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.

233 line
5.8KB

  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\Site\PageInterface;
  12. use Lc\SovBundle\Doctrine\Pattern\AbstractFullEntity;
  13. /**
  14. * @ORM\MappedSuperclass()
  15. */
  16. abstract class SectionModel extends AbstractFullEntity implements FilterMerchantInterface
  17. {
  18. /**
  19. * @ORM\ManyToOne(targetEntity="Lc\CaracoleBundle\Model\Merchant\MerchantInterface")
  20. * @ORM\JoinColumn(nullable=false)
  21. */
  22. protected $merchant;
  23. /**
  24. * @ORM\Column(type="string", length=32)
  25. */
  26. protected $cycle;
  27. const CYCLE_DAY = 'day';
  28. const CYCLE_WEEK = 'week';
  29. const CYCLE_MONTH = 'month';
  30. const CYCLE_YEAR = 'year';
  31. /**
  32. * @ORM\Column(type="string", length=32)
  33. */
  34. protected $color;
  35. /**
  36. * @ORM\ManyToMany(targetEntity="Lc\CaracoleBundle\Model\Product\ProductFamilyInterface", mappedBy="sections")
  37. */
  38. protected $productFamilies;
  39. /**
  40. * @ORM\OneToMany(targetEntity="Lc\CaracoleBundle\Model\Order\OrderShopInterface", mappedBy="section")
  41. */
  42. protected $orderShops;
  43. /**
  44. * @ORM\OneToMany(targetEntity="Lc\CaracoleBundle\Model\Product\ProductCategoryInterface", mappedBy="section")
  45. */
  46. protected $productCategories;
  47. /**
  48. * @ORM\OneToMany(targetEntity="Lc\CaracoleBundle\Model\Site\PageInterface", mappedBy="section")
  49. */
  50. protected $pages;
  51. public function __construct()
  52. {
  53. $this->productFamilies = new ArrayCollection();
  54. $this->orderShops = new ArrayCollection();
  55. }
  56. public function __toString()
  57. {
  58. return $this->getTitle();
  59. }
  60. public function getMerchant(): ?MerchantInterface
  61. {
  62. return $this->merchant;
  63. }
  64. public function setMerchant(?MerchantInterface $merchant): self
  65. {
  66. $this->merchant = $merchant;
  67. return $this;
  68. }
  69. public function getColor(): ?string
  70. {
  71. return $this->color;
  72. }
  73. public function setColor(string $color): self
  74. {
  75. $this->color = $color;
  76. return $this;
  77. }
  78. public function getCycle(): ?string
  79. {
  80. return $this->cycle;
  81. }
  82. public function setCycle(string $cycle): self
  83. {
  84. $this->cycle = $cycle;
  85. return $this;
  86. }
  87. /**
  88. * @return Collection|ProductFamilyInterface[]
  89. */
  90. public function getProductFamilies(): Collection
  91. {
  92. return $this->productFamilies;
  93. }
  94. public function addProductFamily(ProductFamilyInterface $productFamily): self
  95. {
  96. if (!$this->productFamilies->contains($productFamily)) {
  97. $this->productFamilies[] = $productFamily;
  98. $productFamily->addSection($this);
  99. }
  100. return $this;
  101. }
  102. public function removeProductFamily(ProductFamilyInterface $productFamily): self
  103. {
  104. if ($this->productFamilies->contains($productFamily)) {
  105. $this->productFamilies->removeElement($productFamily);
  106. $productFamily->removeSection($this);
  107. }
  108. return $this;
  109. }
  110. /**
  111. * @return Collection|OrderShopInterface[]
  112. */
  113. public function getOrderShops(): Collection
  114. {
  115. return $this->orderShops;
  116. }
  117. public function addOrderShop(OrderShopInterface $orderShop): self
  118. {
  119. if (!$this->orderShops->contains($orderShop)) {
  120. $this->orderShops[] = $orderShop;
  121. $orderShop->setSection($this);
  122. }
  123. return $this;
  124. }
  125. public function removeOrderShop(OrderShopInterface $orderShop): self
  126. {
  127. if ($this->orderShops->contains($orderShop)) {
  128. $this->orderShops->removeElement($orderShop);
  129. // set the owning side to null (unless already changed)
  130. if ($orderShop->getSection() === $this) {
  131. $orderShop->setSection(null);
  132. }
  133. }
  134. return $this;
  135. }
  136. /**
  137. * @return Collection|ProductCategoryInterface[]
  138. */
  139. public function getProductCategories(): Collection
  140. {
  141. return $this->productCategories;
  142. }
  143. public function addProductCategory(ProductCategoryInterface $productCategory): self
  144. {
  145. if (!$this->productCategories->contains($productCategory)) {
  146. $this->productCategories[] = $productCategory;
  147. $productCategory->setSection($this);
  148. }
  149. return $this;
  150. }
  151. public function removeProductCategory(ProductCategoryInterface $productCategory): self
  152. {
  153. if ($this->productCategories->contains($productCategory)) {
  154. $this->productCategories->removeElement($productCategory);
  155. // set the owning side to null (unless already changed)
  156. if ($productCategory->getSection() === $this) {
  157. $productCategory->setSection(null);
  158. }
  159. }
  160. return $this;
  161. }
  162. /**
  163. * @return Collection|PageInterface[]
  164. */
  165. public function getPages(): Collection
  166. {
  167. return $this->pages;
  168. }
  169. public function addPage(PageInterface $page): self
  170. {
  171. if (!$this->pages->contains($page)) {
  172. $this->pages[] = $page;
  173. $page->setSection($this);
  174. }
  175. return $this;
  176. }
  177. public function removePage(PageInterface $page): self
  178. {
  179. if ($this->pages->removeElement($page)) {
  180. // set the owning side to null (unless already changed)
  181. if ($page->getSection() === $this) {
  182. $page->setSection(null);
  183. }
  184. }
  185. return $this;
  186. }
  187. }