<?phpnamespace App\Entity;use App\Entity\Traits\CommonTrait;use App\Repository\ItemSpecCategoryRepository;use Doctrine\Common\Collections\ArrayCollection;use Doctrine\Common\Collections\Collection;use Doctrine\ORM\Mapping as ORM;use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;/** * @ORM\Entity(repositoryClass=ItemSpecCategoryRepository::class) * @ORM\Table(name="itm_spec_category") * @ORM\HasLifecycleCallbacks() * @UniqueEntity({"uuid"}) */class ItemSpecCategory{ use CommonTrait; /** * @ORM\Column(type="string", length=255) */ private $name; /** * @ORM\ManyToMany(targetEntity=ItemSpecTypes::class) */ private $specTypes; /** * @ORM\ManyToMany(targetEntity=ItemCategory::class, inversedBy="itemSpecCategories") */ private $category; /** * @ORM\Column(type="boolean", nullable=true) */ private $hideTitle; /** * @ORM\Column(type="json", nullable=true) */ private $sort; public function __construct() { $this->specTypes = new ArrayCollection(); $this->category = new ArrayCollection(); } public function getName(): ?string { return $this->name; } public function setName(string $name): self { $this->name = $name; return $this; } /** * @return Collection|ItemSpecTypes[] */ public function getSpecTypes() { $v = []; $sort = $this->getSort(); if($sort && is_countable($sort) && count($sort) > 1) { foreach ($sort as $sortId) { foreach ($this->specTypes as $spec) { if($spec->getId() === $sortId) { $v[] = $spec; } } } return $v; } return $this->specTypes->getValues(); } public function addSpecType(ItemSpecTypes $specType): self { if (!$this->specTypes->contains($specType)) { $this->specTypes[] = $specType; } return $this; } public function removeSpecType(ItemSpecTypes $specType): self { $this->specTypes->removeElement($specType); return $this; } /** * @return Collection|ItemCategory[] */ public function getCategory() { return $this->category->getValues(); } public function addCategory(ItemCategory $category): self { if (!$this->category->contains($category)) { $this->category[] = $category; } return $this; } public function removeCategory(ItemCategory $category): self { $this->category->removeElement($category); return $this; } public function __toString() { return $this->getName(); } public function getHideTitle(): ?bool { return $this->hideTitle; } public function setHideTitle(?bool $hideTitle): self { $this->hideTitle = $hideTitle; return $this; } public function setSort($sort) { $this->sort = $sort; return $this; } public function getSort() { if(!is_string($this->sort)) { return $this->sort; } return json_decode($this->sort, true); }}