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.

123 lines
3.5KB

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