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.

SectionModel.php 11KB

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