src/Entity/Category.php line 19

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\CategoryRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use App\Annotation\DashboardAnnotation as Dashboard;
  8. use App\Annotation\FormBuildAnnotation as FormBuild;
  9. use Symfony\Component\Serializer\Annotation as Serializer;
  10. use Symfony\Component\Serializer\Annotation\SerializedName;
  11. use Doctrine\ORM\Mapping\OrderBy;
  12. /**
  13.  * @ORM\Entity(repositoryClass=CategoryRepository::class)
  14.  * @Dashboard(generation=true, name="Категория")
  15.  */
  16. class Category
  17. {
  18.     /**
  19.      * @ORM\Id
  20.      * @ORM\GeneratedValue
  21.      * @ORM\Column(type="integer")
  22.      * @Serializer\Groups({"collection", "selection/param", "selection/data", "selection/id"}) 
  23.      * @Dashboard(label="Номер", only=true)
  24.      */
  25.     private $id;
  26.     /**
  27.      * @ORM\Column(type="string", length=255)
  28.      * @Serializer\Groups({"collection", "selection/param", "selection/data", "selection/id"})
  29.      * @Dashboard(label="Название категории")
  30.      * @FormBuild(component="input")
  31.      */
  32.     private $title;
  33.     /**
  34.      * @ORM\Column(type="boolean")
  35.      * @Serializer\Groups({"collection"}) 
  36.      * @FormBuild(component="switch")
  37.      * @Dashboard(label="Скрыть на сайте", only=true, inverse=true)
  38.      */
  39.     private $public true;
  40.     /**
  41.      * @ORM\OneToMany(targetEntity=Product::class, mappedBy="category", cascade={"persist", "remove"}, orphanRemoval=false)
  42.      * @Serializer\Groups({"selection/data"})
  43.      * @ORM\OrderBy({"title" = "ASC"})
  44.      */
  45.     private $products;
  46.     public function __construct()
  47.     {
  48.         $this->products = new ArrayCollection();
  49.     }
  50.     public function getId(): ?int
  51.     {
  52.         return $this->id;
  53.     }
  54.     public function getTitle(): ?string
  55.     {
  56.         return $this->title;
  57.     }
  58.     public function setTitle(string $title): self
  59.     {
  60.         $this->title $title;
  61.         return $this;
  62.     }
  63.     public function isPublic(): ?bool
  64.     {
  65.         return $this->public;
  66.     }
  67.     public function setPublic(bool $public): self
  68.     {
  69.         $this->public $public;
  70.         return $this;
  71.     }
  72.     /**
  73.      * @return Collection<int, Product>
  74.      */
  75.     public function getProducts(): Collection
  76.     {
  77.         return $this->products;
  78.     }
  79.     public function addProduct(Product $product): self
  80.     {
  81.         if (!$this->products->contains($product)) {
  82.             $this->products[] = $product;
  83.             $product->setCategory($this);
  84.         }
  85.         return $this;
  86.     }
  87.     public function removeProduct(Product $product): self
  88.     {
  89.         if ($this->products->removeElement($product)) {
  90.             // set the owning side to null (unless already changed)
  91.             if ($product->getCategory() === $this) {
  92.                 $product->setCategory(null);
  93.             }
  94.         }
  95.         return $this;
  96.     }
  97.     public function clearProducts(): self
  98.     {
  99.         $this->products = new ArrayCollection();
  100.         return $this;
  101.     }
  102. }