src/Entity/ItemSpecCategory.php line 18

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Traits\CommonTrait;
  4. use App\Repository\ItemSpecCategoryRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  9. /**
  10.  * @ORM\Entity(repositoryClass=ItemSpecCategoryRepository::class)
  11.  * @ORM\Table(name="itm_spec_category")
  12.  * @ORM\HasLifecycleCallbacks()
  13.  * @UniqueEntity({"uuid"})
  14.  */
  15. class ItemSpecCategory
  16. {
  17.     use CommonTrait;
  18.     /**
  19.      * @ORM\Column(type="string", length=255)
  20.      */
  21.     private $name;
  22.     /**
  23.      * @ORM\ManyToMany(targetEntity=ItemSpecTypes::class)
  24.      */
  25.     private $specTypes;
  26.     /**
  27.      * @ORM\ManyToMany(targetEntity=ItemCategory::class, inversedBy="itemSpecCategories")
  28.      */
  29.     private $category;
  30.     /**
  31.      * @ORM\Column(type="boolean", nullable=true)
  32.      */
  33.     private $hideTitle;
  34.     /**
  35.      * @ORM\Column(type="json", nullable=true)
  36.      */
  37.     private $sort;
  38.     public function __construct()
  39.     {
  40.         $this->specTypes = new ArrayCollection();
  41.         $this->category = new ArrayCollection();
  42.     }
  43.     public function getName(): ?string
  44.     {
  45.         return $this->name;
  46.     }
  47.     public function setName(string $name): self
  48.     {
  49.         $this->name $name;
  50.         return $this;
  51.     }
  52.     /**
  53.      * @return Collection|ItemSpecTypes[]
  54.      */
  55.     public function getSpecTypes()
  56.     {
  57.         $v = [];
  58.         $sort $this->getSort();
  59.         if($sort && is_countable($sort) && count($sort) > 1) {
  60.             foreach ($sort as $sortId) {
  61.                 foreach ($this->specTypes as $spec) {
  62.                     if($spec->getId() === $sortId) {
  63.                         $v[] = $spec;
  64.                     }
  65.                 }
  66.             }
  67.             return $v;
  68.         }
  69.         return $this->specTypes->getValues();
  70.     }
  71.     public function addSpecType(ItemSpecTypes $specType): self
  72.     {
  73.         if (!$this->specTypes->contains($specType)) {
  74.             $this->specTypes[] = $specType;
  75.         }
  76.         return $this;
  77.     }
  78.     public function removeSpecType(ItemSpecTypes $specType): self
  79.     {
  80.         $this->specTypes->removeElement($specType);
  81.         return $this;
  82.     }
  83.     /**
  84.      * @return Collection|ItemCategory[]
  85.      */
  86.     public function getCategory()
  87.     {
  88.         return $this->category->getValues();
  89.     }
  90.     public function addCategory(ItemCategory $category): self
  91.     {
  92.         if (!$this->category->contains($category)) {
  93.             $this->category[] = $category;
  94.         }
  95.         return $this;
  96.     }
  97.     public function removeCategory(ItemCategory $category): self
  98.     {
  99.         $this->category->removeElement($category);
  100.         return $this;
  101.     }
  102.     public function __toString()
  103.     {
  104.         return $this->getName();
  105.     }
  106.     public function getHideTitle(): ?bool
  107.     {
  108.         return $this->hideTitle;
  109.     }
  110.     public function setHideTitle(?bool $hideTitle): self
  111.     {
  112.         $this->hideTitle $hideTitle;
  113.         return $this;
  114.     }
  115.     public function setSort($sort)
  116.     {
  117.         $this->sort $sort;
  118.         return $this;
  119.     }
  120.     public function getSort()
  121.     {
  122.         if(!is_string($this->sort)) {
  123.             return $this->sort;
  124.         }
  125.         return json_decode($this->sorttrue);
  126.     }
  127. }