Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

175 lines
4.9KB

  1. <?php
  2. namespace Lc\ShopBundle\Model;
  3. use App\Entity\Hub;
  4. use App\Entity\ProductFamily;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Lc\ShopBundle\Context\FilterMerchantInterface;
  9. use Lc\ShopBundle\Context\TreeInterface;
  10. /**
  11. * @ORM\MappedSuperclass()
  12. */
  13. abstract class ProductCategory extends AbstractDocumentEntity implements TreeInterface, FilterMerchantInterface
  14. {
  15. /**
  16. * @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\MerchantInterface", inversedBy="productCategories")
  17. * @ORM\JoinColumn(nullable=false)
  18. */
  19. protected $merchant;
  20. /**
  21. * @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\ProductCategoryInterface", inversedBy="childrens")
  22. */
  23. protected $parent;
  24. /**
  25. * @ORM\OneToMany(targetEntity="Lc\ShopBundle\Context\ProductCategoryInterface", mappedBy="parent" , fetch="EAGER"))
  26. * @ORM\OrderBy({"position" = "ASC"})
  27. */
  28. protected $childrens;
  29. /**
  30. * @ORM\ManyToMany(targetEntity="App\Entity\ProductFamily", mappedBy="productCategories")
  31. */
  32. protected $productFamilies;
  33. /**
  34. * @ORM\Column(type="boolean")
  35. */
  36. protected $saleStatus;
  37. public function __construct()
  38. {
  39. $this->childrens = new ArrayCollection();
  40. $this->productFamilies = new ArrayCollection();
  41. }
  42. public function __toString()
  43. {
  44. // TODO: Implement __toString() method.
  45. return $this->getTitle();
  46. }
  47. public function getParent(): ?self
  48. {
  49. return $this->parent;
  50. }
  51. public function setParent(?self $productCategory): self
  52. {
  53. $this->parent = $productCategory;
  54. return $this;
  55. }
  56. public function getParentCategory()
  57. {
  58. if($this->getParent()) {
  59. return $this->getParent() ;
  60. }
  61. return $this ;
  62. }
  63. /**
  64. * @return Collection|self[]
  65. */
  66. public function getChildrens(): Collection
  67. {
  68. return $this->childrens;
  69. }
  70. public function addChildren(self $productCategory): self
  71. {
  72. if (!$this->childrens->contains($productCategory)) {
  73. $this->childrens[] = $productCategory;
  74. $productCategory->setParent($this);
  75. }
  76. return $this;
  77. }
  78. public function removeChildren(self $productCategory): self
  79. {
  80. if ($this->childrens->contains($productCategory)) {
  81. $this->childrens->removeElement($productCategory);
  82. // set the owning side to null (unless already changed)
  83. if ($productCategory->getParent() === $this) {
  84. $productCategory->setParent(null);
  85. }
  86. }
  87. return $this;
  88. }
  89. /**
  90. * @return Collection|ProductFamily[]
  91. */
  92. public function getProductFamilies(): Collection
  93. {
  94. return $this->productFamilies;
  95. }
  96. public function addProductFamily(ProductFamily $productFamily): self
  97. {
  98. if (!$this->productFamilies->contains($productFamily)) {
  99. $this->productFamilies[] = $productFamily;
  100. $productFamily->addProductCategory($this);
  101. }
  102. return $this;
  103. }
  104. public function removeProductFamily(ProductFamily $productFamily): self
  105. {
  106. if ($this->productFamilies->contains($productFamily)) {
  107. $this->productFamilies->removeElement($productFamily);
  108. $productFamily->removeProductCategory($this);
  109. }
  110. return $this;
  111. }
  112. public function countProductFamilies($status = null)
  113. {
  114. $count = 0 ;
  115. foreach($this->getProductFamilies() as $productFamily) {
  116. if($status === null || ($status !== null && $productFamily->getStatus() == $status)) {
  117. $count ++ ;
  118. }
  119. }
  120. return $count ;
  121. }
  122. public function getMerchant(): ?Merchant
  123. {
  124. return $this->merchant;
  125. }
  126. public function setMerchant(?Merchant $merchant): self
  127. {
  128. $this->merchant = $merchant;
  129. return $this;
  130. }
  131. public function getSaleStatus(): ?bool
  132. {
  133. return $this->saleStatus;
  134. }
  135. public function setSaleStatus(bool $saleStatus): self
  136. {
  137. $this->saleStatus = $saleStatus;
  138. return $this;
  139. }
  140. }