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.

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