Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

173 lines
5.0KB

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