123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314 |
- <?php
- namespace WorkflowBundle\Entity;
- use Doctrine\ORM\Mapping as ORM;
- use Symfony\Component\Validator\Constraints as Assert;
- /**
- * @ORM\Table
- * @ORM\Entity(repositoryClass="WorkflowBundle\Repository\ActionRepository")
- */
- class Action
- {
- /**
- * @var int
- *
- * @ORM\Column(type="integer")
- * @ORM\Id
- * @ORM\GeneratedValue(strategy="AUTO")
- */
- private $id;
- /**
- * @var string
- *
- * @ORM\Column(type="string", length=255, nullable=false)
- *
- * @Assert\NotNull
- * @Assert\NotBlank
- */
- protected $name;
-
- /**
- * @var string
- *
- * @ORM\Column(type="string", length=255, nullable=true)
- *
- * @Assert\Callback({"WorkflowBundle\Validator\EventFieldsValidator", "validate"})
- */
- protected $workflowName;
- /**
- * @var string
- *
- * @ORM\Column(type="string", length=255, nullable=true)
- *
- * @Assert\Callback(
- * callback={"WorkflowBundle\Validator\EventFieldsValidator", "validate"},
- * payload={"doctrine"="true"}
- * )
- */
- protected $objectClass;
- /**
- * @var array
- *
- * @ORM\Column(type="array", nullable=true)
- */
- protected $event;
- /**
- * @var string
- *
- * @ORM\Column(type="string", length=255, nullable=true)
- * @Assert\Callback({"WorkflowBundle\Validator\EventFieldsValidator", "validate"})
- */
- protected $eventReference;
- /**
- * @var string
- *
- * @ORM\Column(type="text", nullable=false)
- *
- * @Assert\NotNull
- * @Assert\NotBlank
- */
- protected $template;
- /**
- * @var int
- *
- * @ORM\Column(type="integer", nullable=false, options={"default":1})
- */
- protected $tenancyId = 1;
- /**
- * Array con variables de contexto a utilizar en el render del template
- *
- * @var array
- */
- protected $twigParams;
-
-
- public function __construct()
- {
- $this->twigParams = array();
- }
-
- /**
- * @return string
- */
- public function __toString()
- {
- return (string) $this->name;
- }
- /**
- * @return int
- */
- public function getId()
- {
- return $this->id;
- }
- /**
- * @param string $name
- *
- * @return Action
- */
- public function setName($name)
- {
- $this->name = $name;
- return $this;
- }
- /**
- * @return string
- */
- public function getName()
- {
- return $this->name;
- }
- /**
- * @param array $event
- *
- * @return Action
- */
- public function setEvent($event = array())
- {
- $this->event = $event;
- return $this;
- }
- /**
- * @return array
- */
- public function getEvent()
- {
- return $this->event;
- }
- /**
- * @param text $template
- *
- * @return Action
- */
- public function setTemplate($template)
- {
- $this->template = $template;
- return $this;
- }
- /**
- * @return text
- */
- public function getTemplate()
- {
- return $this->template;
- }
- /**
- * Set workflowName
- *
- * @param string $workflowName
- *
- * @return Action
- */
- public function setWorkflowName($workflowName = null)
- {
- $this->workflowName = $workflowName;
- return $this;
- }
- /**
- * Get workflowName
- *
- * @return string
- */
- public function getWorkflowName()
- {
- return $this->workflowName;
- }
- /**
- * Set objectClass
- *
- * @param string $objectClass
- *
- * @return Action
- */
- public function setObjectClass($objectClass)
- {
- $this->objectClass = $objectClass;
- return $this;
- }
- /**
- * Get objectClass
- *
- * @return string
- */
- public function getObjectClass()
- {
- return $this->objectClass;
- }
- /**
- * Set eventReference
- *
- * @param string $eventReference
- *
- * @return Action
- */
- public function setEventReference($eventReference)
- {
- $this->eventReference = $eventReference;
- return $this;
- }
- /**
- * Get eventReference
- *
- * @return string
- */
- public function getEventReference()
- {
- return $this->eventReference;
- }
- /**
- * Set tenancyId
- *
- * @param integer $tenancyId
- *
- * @return Action
- */
- public function setTenancyId($tenancyId)
- {
- $this->tenancyId = $tenancyId;
- return $this;
- }
- /**
- * Get tenancyId
- *
- * @return integer
- */
- public function getTenancyId()
- {
- return $this->tenancyId;
- }
- /**
- * @return array
- */
- public function getTwigParams()
- {
- return $this->twigParams;
- }
- /**
- * @param array $twigParams
- *
- * @return $this
- */
- public function setTwigParams($twigParams)
- {
- $this->twigParams = $twigParams;
-
- return $this;
- }
-
- /**
- * @param Entity $entity
- *
- * @return string
- */
- public function render($entity)
- {
- $template = $this->template;
- $loader = new \Twig_Loader_Array(array(
- $this->name => $template
- ));
- $twig = new \Twig_Environment($loader, array(
- 'cache' => false,
- ));
-
- return $twig->render($this->name, array(
- 'entity' => $entity,
- 'object' => $entity,
- 'params' => $this->twigParams,
- ));
- }
- }
|