childrens = new ArrayCollection(); $this->productFamilies = new ArrayCollection(); } public function __toString() { $parent = $this->getParent(); $title = $parent ? $parent->getTitle() . ' - ' : ''; $title .= $this->getTitle(); return $title; } public function getSection(): SectionInterface { return $this->section; } public function setSection(SectionInterface $section): self { $this->section = $section; return $this; } public function getParent(): ?self { return $this->parent; } public function setParent(?self $productCategory): self { $this->parent = $productCategory; return $this; } public function getParentCategory() { if ($this->getParent()) { return $this->getParent(); } return $this; } /** * @return Collection|self[] */ public function getChildrens(): Collection { // @TODO : les lignes ci-dessous ne devraient pas exister, sert à résoudre le problème d'ordre dans le menu $iterator = $this->childrens->getIterator(); $iterator->uasort( function ($a, $b) { return ($a->getPosition() < $b->getPosition()) ? -1 : 1; } ); return new ArrayCollection(iterator_to_array($iterator)); } public function addChildren(self $productCategory): self { if (!$this->childrens->contains($productCategory)) { $this->childrens[] = $productCategory; $productCategory->setParent($this); } return $this; } public function removeChildren(self $productCategory): self { if ($this->childrens->contains($productCategory)) { $this->childrens->removeElement($productCategory); // set the owning side to null (unless already changed) if ($productCategory->getParent() === $this) { $productCategory->setParent(null); } } return $this; } /** * @return Collection|ProductFamilyInterface[] */ public function getProductFamilies(): Collection { return $this->productFamilies; } public function addProductFamily(ProductFamilyInterface $productFamily): self { if (!$this->productFamilies->contains($productFamily)) { $this->productFamilies[] = $productFamily; $productFamily->addProductCategory($this); } return $this; } public function removeProductFamily(ProductFamilyInterface $productFamily): self { if ($this->productFamilies->contains($productFamily)) { $this->productFamilies->removeElement($productFamily); $productFamily->removeProductCategory($this); } return $this; } public function countProductFamilies($status = null) { $count = 0; foreach ($this->getProductFamilies() as $productFamily) { if ($status === null || ($status !== null && $productFamily->getStatus() == $status)) { $count++; } } return $count; } public function getSaleStatus(): ?bool { return $this->saleStatus; } public function setSaleStatus(bool $saleStatus): self { $this->saleStatus = $saleStatus; return $this; } public function getImage(): ?FileInterface { return $this->image; } public function setImage(?FileInterface $image): self { $this->image = $image; return $this; } }