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.

325 lines
8.3KB

  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. }