Licitator 1.0
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

214 lines
3.8 KiB

5 years ago
  1. <?php
  2. namespace Zitec\RuleEngineBundle\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use Zitec\RuleEngineBundle\DoctrineBehaviors\RuleInterface;
  5. use Zitec\RuleEngineBundle\Form\RuleObject;
  6. use Symfony\Component\Validator\Constraints as Assert;
  7. /**
  8. * Class Rule
  9. *
  10. * @package RuleEngineBundle\Entity
  11. */
  12. class Rule
  13. {
  14. /**
  15. * @ORM\Id
  16. * @ORM\Column(type="integer")
  17. * @ORM\GeneratedValue(strategy="AUTO")
  18. */
  19. protected $id;
  20. /**
  21. * @ORM\Column(type="string", nullable=true)
  22. * @Assert\NotBlank()
  23. * @Assert\Length(max = 100)
  24. */
  25. protected $name = '';
  26. /**
  27. * @ORM\Column(type="boolean", nullable=true, options={"default": 1})
  28. */
  29. protected $active=1;
  30. /**
  31. * @ORM\Column(type="text", nullable=true)
  32. */
  33. protected $expression = '';
  34. /**
  35. * @ORM\Column(type="text", nullable=true)
  36. */
  37. protected $json = '';
  38. /**
  39. * @var RuleObject
  40. */
  41. protected $ruleObject = null;
  42. /**
  43. * @ORM\Column(type="text", nullable=true)
  44. */
  45. protected $action = '';
  46. /**
  47. * @return integer
  48. */
  49. public function getId()
  50. {
  51. return $this->id;
  52. }
  53. /**
  54. * @return string
  55. */
  56. public function getName()
  57. {
  58. return $this->name;
  59. }
  60. /**
  61. * @param null|string $name
  62. */
  63. public function setName(?string $name)
  64. {
  65. $this->name = $name;
  66. }
  67. /**
  68. * Set active
  69. *
  70. * @param boolean $active
  71. *
  72. * @return Rule
  73. */
  74. public function setActive($active)
  75. {
  76. $this->active = ($active)?1:0;
  77. return $this;
  78. }
  79. /**
  80. * Get active
  81. *
  82. * @return boolean
  83. */
  84. public function getActive()
  85. {
  86. return ($this->active)?true:false;
  87. }
  88. /**
  89. * Returns expression in expression language format
  90. * @return string
  91. */
  92. public function getExpression()
  93. {
  94. return $this->expression;
  95. }
  96. /**
  97. * @param null|string $expression
  98. * @return Rule
  99. */
  100. public function setExpression(?string $expression)
  101. {
  102. $this->expression = $expression;
  103. return $this;
  104. }
  105. /**
  106. * @return string
  107. */
  108. public function getJson()
  109. {
  110. return $this->json;
  111. }
  112. /**
  113. * @param null|string $json
  114. * @return Rule
  115. */
  116. public function setJson(?string $json)
  117. {
  118. $this->json = $json;
  119. return $this;
  120. }
  121. /**
  122. * Set the object that contains expression language and json
  123. * @param RuleObject $ruleObject
  124. * @return $this
  125. */
  126. public function setRuleObject(RuleObject $ruleObject)
  127. {
  128. if ($ruleObject) {
  129. $this->ruleObject = $ruleObject;
  130. $this->json = $ruleObject->getJson();
  131. $this->expression = $ruleObject->getExpression();
  132. }
  133. return $this;
  134. }
  135. /**
  136. * Returns the rule object
  137. * @return null|RuleObject
  138. */
  139. public function getRuleObject()
  140. {
  141. if (is_null($this->ruleObject)) {
  142. $this->ruleObject = new RuleObject();
  143. $this->ruleObject->setExpression($this->expression);
  144. $this->ruleObject->setJson($this->json);
  145. }
  146. return $this->ruleObject;
  147. }
  148. /**
  149. * @return string
  150. */
  151. public function getAction()
  152. {
  153. return $this->action;
  154. }
  155. /**
  156. * @param string $action
  157. */
  158. public function setAction( $action): void
  159. {
  160. $this->action = $action;
  161. }
  162. /**
  163. * @return string
  164. */
  165. public function getActions()
  166. {
  167. return $this->action;
  168. }
  169. /**
  170. * @param string $action
  171. */
  172. public function setActions( $action): void
  173. {
  174. $this->action = $action;
  175. }
  176. /**
  177. * @return string
  178. */
  179. public function __toString()
  180. {
  181. if ($this->name) {
  182. return $this->name;
  183. }
  184. return '';
  185. }
  186. }