Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

177 lines
4.7KB

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