<?php
namespace App\Entity;
use App\Repository\CategoryRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use App\Annotation\DashboardAnnotation as Dashboard;
use App\Annotation\FormBuildAnnotation as FormBuild;
use Symfony\Component\Serializer\Annotation as Serializer;
use Symfony\Component\Serializer\Annotation\SerializedName;
use Doctrine\ORM\Mapping\OrderBy;
/**
* @ORM\Entity(repositoryClass=CategoryRepository::class)
* @Dashboard(generation=true, name="Категория")
*/
class Category
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
* @Serializer\Groups({"collection", "selection/param", "selection/data", "selection/id"})
* @Dashboard(label="Номер", only=true)
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
* @Serializer\Groups({"collection", "selection/param", "selection/data", "selection/id"})
* @Dashboard(label="Название категории")
* @FormBuild(component="input")
*/
private $title;
/**
* @ORM\Column(type="boolean")
* @Serializer\Groups({"collection"})
* @FormBuild(component="switch")
* @Dashboard(label="Скрыть на сайте", only=true, inverse=true)
*/
private $public = true;
/**
* @ORM\OneToMany(targetEntity=Product::class, mappedBy="category", cascade={"persist", "remove"}, orphanRemoval=false)
* @Serializer\Groups({"selection/data"})
* @ORM\OrderBy({"title" = "ASC"})
*/
private $products;
public function __construct()
{
$this->products = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getTitle(): ?string
{
return $this->title;
}
public function setTitle(string $title): self
{
$this->title = $title;
return $this;
}
public function isPublic(): ?bool
{
return $this->public;
}
public function setPublic(bool $public): self
{
$this->public = $public;
return $this;
}
/**
* @return Collection<int, Product>
*/
public function getProducts(): Collection
{
return $this->products;
}
public function addProduct(Product $product): self
{
if (!$this->products->contains($product)) {
$this->products[] = $product;
$product->setCategory($this);
}
return $this;
}
public function removeProduct(Product $product): self
{
if ($this->products->removeElement($product)) {
// set the owning side to null (unless already changed)
if ($product->getCategory() === $this) {
$product->setCategory(null);
}
}
return $this;
}
public function clearProducts(): self
{
$this->products = new ArrayCollection();
return $this;
}
}