src/Entity/Position.php line 16

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