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.

398 lines
10KB

  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\Newsletter\NewsletterInterface;
  13. use Lc\SovBundle\Model\Site\NewsInterface;
  14. use Lc\SovBundle\Model\Site\PageInterface;
  15. use Lc\SovBundle\Doctrine\Pattern\AbstractFullEntity;
  16. /**
  17. * @ORM\MappedSuperclass()
  18. */
  19. abstract class SectionModel extends AbstractFullEntity implements FilterMerchantInterface
  20. {
  21. /**
  22. * @ORM\ManyToOne(targetEntity="Lc\CaracoleBundle\Model\Merchant\MerchantInterface", inversedBy="sections")
  23. * @ORM\JoinColumn(nullable=false)
  24. */
  25. protected $merchant;
  26. /**
  27. * @ORM\Column(type="string", length=32)
  28. */
  29. protected $cycleType;
  30. const CYCLE_TYPE_DAY = 'day';
  31. const CYCLE_TYPE_WEEK = 'week';
  32. const CYCLE_TYPE_MONTH = 'month';
  33. const CYCLE_TYPE_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\NewsInterface", mappedBy="section", orphanRemoval=true)
  56. */
  57. protected $news;
  58. /**
  59. * @ORM\OneToMany(targetEntity="Lc\SovBundle\Model\Newsletter\NewsletterInterface", mappedBy="section")
  60. */
  61. protected $newsletters;
  62. /**
  63. * @ORM\OneToMany(targetEntity="Lc\SovBundle\Model\Site\PageInterface", mappedBy="section")
  64. */
  65. protected $pages;
  66. /**
  67. * @ORM\OneToMany(targetEntity="Lc\CaracoleBundle\Model\Setting\SectionSettingInterface", mappedBy="section", orphanRemoval=true, cascade={"persist"}, fetch="EAGER")
  68. */
  69. protected $settings;
  70. /**
  71. * @ORM\OneToMany(targetEntity="Lc\CaracoleBundle\Model\Section\OpeningInterface", mappedBy="section", orphanRemoval=true)
  72. */
  73. protected $openings;
  74. public function __construct()
  75. {
  76. $this->productFamilies = new ArrayCollection();
  77. $this->orderShops = new ArrayCollection();
  78. $this->productCategories = new ArrayCollection();
  79. $this->news = new ArrayCollection();
  80. $this->newsletters = new ArrayCollection();
  81. $this->pages = new ArrayCollection();
  82. $this->settings = new ArrayCollection();
  83. $this->openings = new ArrayCollection();
  84. }
  85. public function __toString()
  86. {
  87. return $this->getTitle();
  88. }
  89. public function getMerchant(): ?MerchantInterface
  90. {
  91. return $this->merchant;
  92. }
  93. public function setMerchant(?MerchantInterface $merchant): self
  94. {
  95. $this->merchant = $merchant;
  96. return $this;
  97. }
  98. public function getColor(): ?string
  99. {
  100. return $this->color;
  101. }
  102. public function setColor(string $color): self
  103. {
  104. $this->color = $color;
  105. return $this;
  106. }
  107. public function getCycleType(): ?string
  108. {
  109. return $this->cycleType;
  110. }
  111. public function setCycleType(string $cycleType): self
  112. {
  113. $this->cycleType = $cycleType;
  114. return $this;
  115. }
  116. /**
  117. * @return Collection|ProductFamilyInterface[]
  118. */
  119. public function getProductFamilies(): Collection
  120. {
  121. return $this->productFamilies;
  122. }
  123. public function addProductFamily(ProductFamilyInterface $productFamily): self
  124. {
  125. if (!$this->productFamilies->contains($productFamily)) {
  126. $this->productFamilies[] = $productFamily;
  127. $productFamily->addSection($this);
  128. }
  129. return $this;
  130. }
  131. public function removeProductFamily(ProductFamilyInterface $productFamily): self
  132. {
  133. if ($this->productFamilies->contains($productFamily)) {
  134. $this->productFamilies->removeElement($productFamily);
  135. $productFamily->removeSection($this);
  136. }
  137. return $this;
  138. }
  139. /**
  140. * @return Collection|OrderShopInterface[]
  141. */
  142. public function getOrderShops(): Collection
  143. {
  144. return $this->orderShops;
  145. }
  146. public function addOrderShop(OrderShopInterface $orderShop): self
  147. {
  148. if (!$this->orderShops->contains($orderShop)) {
  149. $this->orderShops[] = $orderShop;
  150. $orderShop->setSection($this);
  151. }
  152. return $this;
  153. }
  154. public function removeOrderShop(OrderShopInterface $orderShop): self
  155. {
  156. if ($this->orderShops->contains($orderShop)) {
  157. $this->orderShops->removeElement($orderShop);
  158. // set the owning side to null (unless already changed)
  159. if ($orderShop->getSection() === $this) {
  160. $orderShop->setSection(null);
  161. }
  162. }
  163. return $this;
  164. }
  165. /**
  166. * @return Collection|ProductCategoryInterface[]
  167. */
  168. public function getProductCategories(): Collection
  169. {
  170. return $this->productCategories;
  171. }
  172. public function addProductCategory(ProductCategoryInterface $productCategory): self
  173. {
  174. if (!$this->productCategories->contains($productCategory)) {
  175. $this->productCategories[] = $productCategory;
  176. $productCategory->setSection($this);
  177. }
  178. return $this;
  179. }
  180. public function removeProductCategory(ProductCategoryInterface $productCategory): self
  181. {
  182. if ($this->productCategories->contains($productCategory)) {
  183. $this->productCategories->removeElement($productCategory);
  184. // set the owning side to null (unless already changed)
  185. if ($productCategory->getSection() === $this) {
  186. $productCategory->setSection(null);
  187. }
  188. }
  189. return $this;
  190. }
  191. /**
  192. * @return Collection|PageInterface[]
  193. */
  194. public function getPages(): Collection
  195. {
  196. return $this->pages;
  197. }
  198. public function addPage(PageInterface $page): self
  199. {
  200. if (!$this->pages->contains($page)) {
  201. $this->pages[] = $page;
  202. $page->setSection($this);
  203. }
  204. return $this;
  205. }
  206. public function removePage(PageInterface $page): self
  207. {
  208. if ($this->pages->removeElement($page)) {
  209. // set the owning side to null (unless already changed)
  210. if ($page->getSection() === $this) {
  211. $page->setSection(null);
  212. }
  213. }
  214. return $this;
  215. }
  216. /**
  217. * @return Collection|NewsInterface[]
  218. */
  219. public function getNews(): Collection
  220. {
  221. return $this->news;
  222. }
  223. public function addNews(NewsInterface $news): self
  224. {
  225. if (!$this->news->contains($news)) {
  226. $this->news[] = $news;
  227. $news->setSection($this);
  228. }
  229. return $this;
  230. }
  231. public function removeNews(NewsInterface $news): self
  232. {
  233. if ($this->news->contains($news)) {
  234. $this->news->removeElement($news);
  235. // set the owning side to null (unless already changed)
  236. if ($news->getSection() === $this) {
  237. $news->setSection(null);
  238. }
  239. }
  240. return $this;
  241. }
  242. /**
  243. * @return Collection|NewsletterInterface[]
  244. */
  245. public function getNewsletters(): Collection
  246. {
  247. return $this->newsletters;
  248. }
  249. public function addNewsletter(NewsletterInterface $newsletter): self
  250. {
  251. if (!$this->newsletters->contains($newsletter)) {
  252. $this->newsletters[] = $newsletter;
  253. $newsletter->setSection($this);
  254. }
  255. return $this;
  256. }
  257. public function removeNewsletter(NewsletterInterface $newsletter): self
  258. {
  259. if ($this->newsletters->contains($newsletter)) {
  260. $this->newsletters->removeElement($newsletter);
  261. // set the owning side to null (unless already changed)
  262. if ($newsletter->getSection() === $this) {
  263. $newsletter->setSection(null);
  264. }
  265. }
  266. return $this;
  267. }
  268. public function getIsDefault(): ?bool
  269. {
  270. return $this->isDefault;
  271. }
  272. public function setIsDefault(?bool $isDefault): self
  273. {
  274. $this->isDefault = $isDefault;
  275. return $this;
  276. }
  277. /**
  278. * @return Collection|SectionSettingInterface[]
  279. */
  280. public function getSettings(): Collection
  281. {
  282. return $this->settings;
  283. }
  284. public function addSetting(SectionSettingInterface $sectionSetting): self
  285. {
  286. if (!$this->settings->contains($sectionSetting)) {
  287. $this->settings[] = $sectionSetting;
  288. $sectionSetting->setSection($this);
  289. }
  290. return $this;
  291. }
  292. public function removeSetting(SectionSettingInterface $sectionSetting): self
  293. {
  294. if ($this->settings->contains($sectionSetting)) {
  295. $this->settings->removeElement($sectionSetting);
  296. // set the owning side to null (unless already changed)
  297. if ($sectionSetting->getSection() === $this) {
  298. $sectionSetting->setSection(null);
  299. }
  300. }
  301. return $this;
  302. }
  303. /**
  304. * @return Collection|OpeningInterface[]
  305. */
  306. public function getOpenings(): Collection
  307. {
  308. return $this->openings;
  309. }
  310. public function addOpening(OpeningInterface $opening): self
  311. {
  312. if (!$this->openings->contains($opening)) {
  313. $this->openings[] = $opening;
  314. $opening->setSection($this);
  315. }
  316. return $this;
  317. }
  318. public function removeOpening(OpeningInterface $opening): self
  319. {
  320. if ($this->openings->removeElement($opening)) {
  321. // set the owning side to null (unless already changed)
  322. if ($opening->getSection() === $this) {
  323. $opening->setSection(null);
  324. }
  325. }
  326. return $this;
  327. }
  328. }