Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

SectionModel.php 8.3KB

il y a 3 ans
il y a 3 ans
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. <?php
  2. namespace Lc\CaracoleBundle\Model\Section;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Lc\CaracoleBundle\Doctrine\Extension\FilterMerchantInterface;
  7. use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
  8. use Lc\CaracoleBundle\Model\Order\OrderShopInterface;
  9. use Lc\CaracoleBundle\Model\Product\ProductCategoryInterface;
  10. use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface;
  11. use Lc\CaracoleBundle\Model\Setting\SectionSettingInterface;
  12. use Lc\SovBundle\Model\Setting\EntitySettingTrait;
  13. use Lc\SovBundle\Model\Site\PageInterface;
  14. use Lc\SovBundle\Doctrine\Pattern\AbstractFullEntity;
  15. /**
  16. * @ORM\MappedSuperclass()
  17. */
  18. abstract class SectionModel extends AbstractFullEntity implements FilterMerchantInterface
  19. {
  20. use EntitySettingTrait;
  21. /**
  22. * @ORM\ManyToOne(targetEntity="Lc\CaracoleBundle\Model\Merchant\MerchantInterface")
  23. * @ORM\JoinColumn(nullable=false)
  24. */
  25. protected $merchant;
  26. /**
  27. * @ORM\Column(type="string", length=32)
  28. */
  29. protected $cycle;
  30. const CYCLE_DAY = 'day';
  31. const CYCLE_WEEK = 'week';
  32. const CYCLE_MONTH = 'month';
  33. const CYCLE_YEAR = 'year';
  34. /**
  35. * @ORM\Column(type="boolean", nullable=true)
  36. */
  37. protected $isDefault;
  38. /**
  39. * @ORM\Column(type="string", length=32)
  40. */
  41. protected $color;
  42. /**
  43. * @ORM\ManyToMany(targetEntity="Lc\CaracoleBundle\Model\Product\ProductFamilyInterface", mappedBy="sections")
  44. */
  45. protected $productFamilies;
  46. /**
  47. * @ORM\OneToMany(targetEntity="Lc\CaracoleBundle\Model\Order\OrderShopInterface", mappedBy="section")
  48. */
  49. protected $orderShops;
  50. /**
  51. * @ORM\OneToMany(targetEntity="Lc\CaracoleBundle\Model\Product\ProductCategoryInterface", mappedBy="section")
  52. */
  53. protected $productCategories;
  54. /**
  55. * @ORM\OneToMany(targetEntity="Lc\SovBundle\Model\Site\PageInterface", mappedBy="section")
  56. */
  57. protected $pages;
  58. /**
  59. * @ORM\OneToMany(targetEntity="Lc\CaracoleBundle\Model\Setting\SectionSettingInterface", mappedBy="section", orphanRemoval=true, cascade={"persist"}, fetch="EAGER")
  60. */
  61. protected $settings;
  62. /**
  63. * @ORM\OneToMany(targetEntity="Lc\CaracoleBundle\Model\Section\OpeningInterface", mappedBy="section", orphanRemoval=true)
  64. */
  65. protected $openings;
  66. public function __construct()
  67. {
  68. $this->productFamilies = new ArrayCollection();
  69. $this->orderShops = new ArrayCollection();
  70. $this->openings = new ArrayCollection();
  71. $this->productCategories = new ArrayCollection();
  72. }
  73. public function __toString()
  74. {
  75. return $this->getTitle();
  76. }
  77. public function getMerchant(): ?MerchantInterface
  78. {
  79. return $this->merchant;
  80. }
  81. public function setMerchant(?MerchantInterface $merchant): self
  82. {
  83. $this->merchant = $merchant;
  84. return $this;
  85. }
  86. public function getColor(): ?string
  87. {
  88. return $this->color;
  89. }
  90. public function setColor(string $color): self
  91. {
  92. $this->color = $color;
  93. return $this;
  94. }
  95. public function getCycle(): ?string
  96. {
  97. return $this->cycle;
  98. }
  99. public function setCycle(string $cycle): self
  100. {
  101. $this->cycle = $cycle;
  102. return $this;
  103. }
  104. /**
  105. * @return Collection|ProductFamilyInterface[]
  106. */
  107. public function getProductFamilies(): Collection
  108. {
  109. return $this->productFamilies;
  110. }
  111. public function addProductFamily(ProductFamilyInterface $productFamily): self
  112. {
  113. if (!$this->productFamilies->contains($productFamily)) {
  114. $this->productFamilies[] = $productFamily;
  115. $productFamily->addSection($this);
  116. }
  117. return $this;
  118. }
  119. public function removeProductFamily(ProductFamilyInterface $productFamily): self
  120. {
  121. if ($this->productFamilies->contains($productFamily)) {
  122. $this->productFamilies->removeElement($productFamily);
  123. $productFamily->removeSection($this);
  124. }
  125. return $this;
  126. }
  127. /**
  128. * @return Collection|OrderShopInterface[]
  129. */
  130. public function getOrderShops(): Collection
  131. {
  132. return $this->orderShops;
  133. }
  134. public function addOrderShop(OrderShopInterface $orderShop): self
  135. {
  136. if (!$this->orderShops->contains($orderShop)) {
  137. $this->orderShops[] = $orderShop;
  138. $orderShop->setSection($this);
  139. }
  140. return $this;
  141. }
  142. public function removeOrderShop(OrderShopInterface $orderShop): self
  143. {
  144. if ($this->orderShops->contains($orderShop)) {
  145. $this->orderShops->removeElement($orderShop);
  146. // set the owning side to null (unless already changed)
  147. if ($orderShop->getSection() === $this) {
  148. $orderShop->setSection(null);
  149. }
  150. }
  151. return $this;
  152. }
  153. /**
  154. * @return Collection|ProductCategoryInterface[]
  155. */
  156. public function getProductCategories(): Collection
  157. {
  158. return $this->productCategories;
  159. }
  160. public function addProductCategory(ProductCategoryInterface $productCategory): self
  161. {
  162. if (!$this->productCategories->contains($productCategory)) {
  163. $this->productCategories[] = $productCategory;
  164. $productCategory->setSection($this);
  165. }
  166. return $this;
  167. }
  168. public function removeProductCategory(ProductCategoryInterface $productCategory): self
  169. {
  170. if ($this->productCategories->contains($productCategory)) {
  171. $this->productCategories->removeElement($productCategory);
  172. // set the owning side to null (unless already changed)
  173. if ($productCategory->getSection() === $this) {
  174. $productCategory->setSection(null);
  175. }
  176. }
  177. return $this;
  178. }
  179. /**
  180. * @return Collection|PageInterface[]
  181. */
  182. public function getPages(): Collection
  183. {
  184. return $this->pages;
  185. }
  186. public function addPage(PageInterface $page): self
  187. {
  188. if (!$this->pages->contains($page)) {
  189. $this->pages[] = $page;
  190. $page->setSection($this);
  191. }
  192. return $this;
  193. }
  194. public function removePage(PageInterface $page): self
  195. {
  196. if ($this->pages->removeElement($page)) {
  197. // set the owning side to null (unless already changed)
  198. if ($page->getSection() === $this) {
  199. $page->setSection(null);
  200. }
  201. }
  202. return $this;
  203. }
  204. public function getIsDefault(): ?bool
  205. {
  206. return $this->isDefault;
  207. }
  208. public function setIsDefault(?bool $isDefault): self
  209. {
  210. $this->isDefault = $isDefault;
  211. return $this;
  212. }
  213. /**
  214. * @return Collection|SectionSettingInterface[]
  215. */
  216. public function getSettings(): Collection
  217. {
  218. return $this->settings;
  219. }
  220. public function addSetting(SectionSettingInterface $sectionSetting): self
  221. {
  222. if (!$this->settings->contains($sectionSetting)) {
  223. $this->settings[] = $sectionSetting;
  224. $sectionSetting->setMerchant($this);
  225. }
  226. return $this;
  227. }
  228. public function removeSetting(SectionSettingInterface $sectionSetting): self
  229. {
  230. if ($this->settings->contains($sectionSetting)) {
  231. $this->settings->removeElement($sectionSetting);
  232. // set the owning side to null (unless already changed)
  233. if ($sectionSetting->getMerchant() === $this) {
  234. $sectionSetting->setMerchant(null);
  235. }
  236. }
  237. return $this;
  238. }
  239. /**
  240. * @return Collection|OpeningInterface[]
  241. */
  242. public function getOpenings(): Collection
  243. {
  244. return $this->openings;
  245. }
  246. public function addOpening(OpeningInterface $opening): self
  247. {
  248. if (!$this->openings->contains($opening)) {
  249. $this->openings[] = $opening;
  250. $opening->setSection($this);
  251. }
  252. return $this;
  253. }
  254. public function removeOpening(OpeningInterface $opening): self
  255. {
  256. if ($this->openings->removeElement($opening)) {
  257. // set the owning side to null (unless already changed)
  258. if ($opening->getSection() === $this) {
  259. $opening->setSection(null);
  260. }
  261. }
  262. return $this;
  263. }
  264. }