src/Entity/ModuleHook.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\ORM\EntityManager;
  4. use Doctrine\ORM\Mapping as ORM;
  5. /**
  6. * ModuleHook
  7. *
  8. * @ORM\Table(name="module_hooks")
  9. * @ORM\Entity(repositoryClass="App\Repository\ModuleHookRepository")
  10. */
  11. class ModuleHook {
  12. /**
  13. * @var integer
  14. *
  15. * @ORM\Column(name="id", type="integer")
  16. * @ORM\Id
  17. * @ORM\GeneratedValue(strategy="AUTO")
  18. */
  19. private $id;
  20. /**
  21. * @var integer
  22. *
  23. * @ORM\ManyToOne(targetEntity="Module", inversedBy="hooks")
  24. * @ORM\JoinColumn(name="module_id", referencedColumnName="id")
  25. */
  26. private $module;
  27. /**
  28. * @var integer
  29. *
  30. * @ORM\ManyToOne(targetEntity="Hook")
  31. * @ORM\JoinColumn(name="hook_id", referencedColumnName="id")
  32. */
  33. private $hook;
  34. /**
  35. * @var boolean
  36. *
  37. * @ORM\Column(name="enabled", type="boolean", options={"default" = 0})
  38. */
  39. private $enabled;
  40. /**
  41. * @var integer
  42. *
  43. * @ORM\Column(name="category_condition", type="string", length=50, nullable=true)
  44. */
  45. private $condition;
  46. /**
  47. * @var integer
  48. *
  49. * @ORM\Column(name="order_num", type="integer")
  50. */
  51. private $orderNum;
  52. /**
  53. * @ORM\Column(name="size_class", type="string", length=50, nullable=true)
  54. */
  55. private $sizeClass;
  56. protected $sizeWidth = 4;
  57. private $data = array();
  58. /**
  59. * @return the $enabled
  60. */
  61. public function getEnabled() {
  62. return $this->enabled;
  63. }
  64. /**
  65. * @param boolean $enabled
  66. */
  67. public function setEnabled($enabled) {
  68. $this->enabled = $enabled;
  69. }
  70. /**
  71. * Get id
  72. *
  73. * @return integer
  74. */
  75. public function getId() {
  76. return $this->id;
  77. }
  78. /**
  79. * Set module
  80. *
  81. * @param integer $module
  82. * @return ModuleHook
  83. */
  84. public function setModule($module) {
  85. $this->module = $module;
  86. return $this;
  87. }
  88. /**
  89. * Get module
  90. *
  91. * @return integer
  92. */
  93. public function getModule() {
  94. return $this->module;
  95. }
  96. /**
  97. * Set hook
  98. *
  99. * @param string $hook
  100. * @return ModuleHook
  101. */
  102. public function setHook($hook) {
  103. $this->hook = $hook;
  104. return $this;
  105. }
  106. /**
  107. * Get hook
  108. *
  109. * @return string
  110. */
  111. public function getHook() {
  112. return $this->hook;
  113. }
  114. /**
  115. * Set orderNum
  116. *
  117. * @param integer $orderNum
  118. * @return ModuleHook
  119. */
  120. public function setOrderNum($orderNum) {
  121. $this->orderNum = $orderNum;
  122. return $this;
  123. }
  124. /**
  125. * Get orderNum
  126. *
  127. * @return integer
  128. */
  129. public function getOrderNum() {
  130. return $this->orderNum;
  131. }
  132. public function getSizeClass() {
  133. return empty($this->sizeClass) ? 'full' : $this->sizeClass;
  134. }
  135. public function setSizeClass($sizeClass) {
  136. $this->sizeClass = $sizeClass;
  137. }
  138. public function getSizeWidth() {
  139. $class = $this->getSizeClass();
  140. switch ($class) {
  141. case 'quater' : return 1;
  142. case 'half' : return 2;
  143. case 'quater-3' : return 3;
  144. default:
  145. }
  146. return 4;
  147. }
  148. /**
  149. * Chargement des données nécessaires au rendu
  150. */
  151. public function loadData(EntityManager $em, $conditions = null) {
  152. $module = $this->getModule();
  153. if ($module->getHasOptions()) {
  154. $obj_name = $module->getEntity();
  155. if (!empty($obj_name)) {
  156. $entity = $em->getRepository($obj_name)->findOneByModuleHook($this);
  157. if (!empty($entity)) {
  158. if ($module->getHasConditions()) {
  159. $this->data = $entity->getData($this, $conditions);
  160. } else {
  161. $this->data = $entity->getData($this);
  162. }
  163. }
  164. }
  165. }
  166. return array();
  167. }
  168. public function getData() {
  169. return $this->data;
  170. }
  171. /**
  172. * @return the $condition
  173. */
  174. public function getCondition() {
  175. return $this->condition;
  176. }
  177. /**
  178. * @param integer $condition
  179. */
  180. public function setCondition($condition) {
  181. $this->condition = $condition;
  182. }
  183. public function checkCondition($id) {
  184. return empty($this->condition) or ( $this->condition == $id);
  185. }
  186. }