Action.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. <?php
  2. namespace WorkflowBundle\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. /**
  5. * @ORM\Table
  6. * @ORM\Entity
  7. */
  8. class Action
  9. {
  10. /**
  11. * @var int
  12. *
  13. * @ORM\Column(type="integer")
  14. * @ORM\Id
  15. * @ORM\GeneratedValue(strategy="AUTO")
  16. */
  17. private $id;
  18. /**
  19. * @var string
  20. *
  21. * @ORM\Column(type="string", length=255, nullable=false)
  22. */
  23. protected $name;
  24. /**
  25. * @var string
  26. *
  27. * @ORM\Column(type="string", length=255, nullable=false)
  28. */
  29. protected $workflowType;
  30. /**
  31. * @var string
  32. *
  33. * @ORM\Column(type="string", length=255, nullable=false)
  34. */
  35. protected $workflowName;
  36. /**
  37. * @var string
  38. *
  39. * @ORM\Column(type="string", length=255, nullable=false)
  40. */
  41. protected $objectClass;
  42. /**
  43. * @var string
  44. *
  45. * @ORM\Column(type="string", length=255, nullable=false)
  46. */
  47. protected $event;
  48. /**
  49. * @var string
  50. *
  51. * @ORM\Column(type="string", length=255, nullable=false)
  52. */
  53. protected $eventReference;
  54. /**
  55. * @var text
  56. *
  57. * @ORM\Column(type="text", nullable=false)
  58. */
  59. protected $template;
  60. /**
  61. * @var Doctrine2WorkFlowAction
  62. *
  63. * @ORM\ManyToMany(targetEntity="Doctrine2WorkFlowAction", inversedBy="actions", fetch="EXTRA_LAZY")
  64. */
  65. private $doctrine2WorkFlowActions;
  66. /**
  67. * @var int
  68. *
  69. * @ORM\Column(type="integer", nullable=false, options={"default":1})
  70. */
  71. protected $tenancyId = 1;
  72. /**
  73. * Array con variables de contexto a utilizar en el render del template
  74. *
  75. * @var array
  76. */
  77. protected $twigParams;
  78. public function __construct()
  79. {
  80. $this->twigParams = array();
  81. }
  82. /**
  83. * @return string
  84. */
  85. public function __toString()
  86. {
  87. return (string) $this->name;
  88. }
  89. /**
  90. * @return int
  91. */
  92. public function getId()
  93. {
  94. return $this->id;
  95. }
  96. /**
  97. * @param string $name
  98. *
  99. * @return Action
  100. */
  101. public function setName($name)
  102. {
  103. $this->name = $name;
  104. return $this;
  105. }
  106. /**
  107. * @return string
  108. */
  109. public function getName()
  110. {
  111. return $this->name;
  112. }
  113. /**
  114. * @param string $event
  115. *
  116. * @return Action
  117. */
  118. public function setEvent($event)
  119. {
  120. $this->event = $event;
  121. return $this;
  122. }
  123. /**
  124. * @return string
  125. */
  126. public function getEvent()
  127. {
  128. return $this->event;
  129. }
  130. /**
  131. * @param text $template
  132. *
  133. * @return Action
  134. */
  135. public function setTemplate($template)
  136. {
  137. $this->template = $template;
  138. return $this;
  139. }
  140. /**
  141. * @return text
  142. */
  143. public function getTemplate()
  144. {
  145. return $this->template;
  146. }
  147. /**
  148. * Set workflowType
  149. *
  150. * @param string $workflowType
  151. *
  152. * @return Action
  153. */
  154. public function setWorkflowType($workflowType)
  155. {
  156. $this->workflowType = $workflowType;
  157. return $this;
  158. }
  159. /**
  160. * Get workflowType
  161. *
  162. * @return string
  163. */
  164. public function getWorkflowType()
  165. {
  166. return $this->workflowType;
  167. }
  168. /**
  169. * Set workflowName
  170. *
  171. * @param string $workflowName
  172. *
  173. * @return Action
  174. */
  175. public function setWorkflowName($workflowName)
  176. {
  177. $this->workflowName = $workflowName;
  178. return $this;
  179. }
  180. /**
  181. * Get workflowName
  182. *
  183. * @return string
  184. */
  185. public function getWorkflowName()
  186. {
  187. return $this->workflowName;
  188. }
  189. /**
  190. * Set objectClass
  191. *
  192. * @param string $objectClass
  193. *
  194. * @return Action
  195. */
  196. public function setObjectClass($objectClass)
  197. {
  198. $this->objectClass = $objectClass;
  199. return $this;
  200. }
  201. /**
  202. * Get objectClass
  203. *
  204. * @return string
  205. */
  206. public function getObjectClass()
  207. {
  208. return $this->objectClass;
  209. }
  210. /**
  211. * Set eventReference
  212. *
  213. * @param string $eventReference
  214. *
  215. * @return Action
  216. */
  217. public function setEventReference($eventReference)
  218. {
  219. $this->eventReference = $eventReference;
  220. return $this;
  221. }
  222. /**
  223. * Get eventReference
  224. *
  225. * @return string
  226. */
  227. public function getEventReference()
  228. {
  229. return $this->eventReference;
  230. }
  231. /**
  232. * @return Doctrine2WorkFlowAction
  233. */
  234. public function getDoctrine2WorkFlowActions()
  235. {
  236. return $this->doctrine2WorkFlowActions;
  237. }
  238. /**
  239. * @param Doctrine2WorkFlowAction $doctrine2WorkFlowAction
  240. *
  241. * @return Workflow
  242. */
  243. public function addDoctrine2WorkFlowAction($doctrine2WorkFlowAction)
  244. {
  245. $this->doctrine2WorkFlowActions[] = $doctrine2WorkFlowAction;
  246. return $this;
  247. }
  248. /**
  249. * @param Doctrine2WorkFlowAction $doctrine2WorkFlowAction
  250. *
  251. * @return Workflow
  252. */
  253. public function removeDoctrine2WorkFlowAction($doctrine2WorkFlowAction)
  254. {
  255. $this->doctrine2WorkFlowActions->removeElement($doctrine2WorkFlowAction);
  256. return $this;
  257. }
  258. /**
  259. * Set tenancyId
  260. *
  261. * @param integer $tenancyId
  262. *
  263. * @return Action
  264. */
  265. public function setTenancyId($tenancyId)
  266. {
  267. $this->tenancyId = $tenancyId;
  268. return $this;
  269. }
  270. /**
  271. * Get tenancyId
  272. *
  273. * @return integer
  274. */
  275. public function getTenancyId()
  276. {
  277. return $this->tenancyId;
  278. }
  279. /**
  280. * @return array
  281. */
  282. public function getTwigParams()
  283. {
  284. return $this->twigParams;
  285. }
  286. /**
  287. * @param array $twigParams
  288. *
  289. * @return $this
  290. */
  291. public function setTwigParams($twigParams)
  292. {
  293. $this->twigParams = $twigParams;
  294. return $this;
  295. }
  296. /**
  297. * @param Entity $entity
  298. *
  299. * @return string
  300. */
  301. public function render($entity)
  302. {
  303. $template = $this->template;
  304. $loader = new \Twig_Loader_Array(array(
  305. $this->name => $template
  306. ));
  307. $twig = new \Twig_Environment($loader, array(
  308. 'cache' => false,
  309. ));
  310. return $twig->render($this->name, array(
  311. 'entity' => $entity,
  312. 'params' => $this->twigParams,
  313. ));
  314. }
  315. }