src/Entity/Model.php line 21

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\ModelRepository;
  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=ModelRepository::class)
  13.  * @Dashboard(generation=true, name="Модель авто")
  14.  * @ORM\Table(indexes={
  15.  *     @ORM\Index(name="model_title_idx", columns={"title"})
  16.  * })
  17.  */
  18. class Model
  19. {
  20.     /**
  21.      * @ORM\Id
  22.      * @ORM\GeneratedValue
  23.      * @ORM\Column(type="integer")
  24.      * @Serializer\Groups({"collection", "selection/param"}) 
  25.      * @Dashboard(label="Номер", only=true)
  26.      */
  27.     private $id;
  28.     /**
  29.      * @ORM\Column(type="string", length=255)
  30.      * @Serializer\Groups({"collection", "selection/param"})
  31.      * @Dashboard(label="Название модели")
  32.      * @FormBuild(component="input")
  33.      */
  34.     private $title;
  35.     /**
  36.      * @ORM\ManyToOne(targetEntity=Mark::class, inversedBy="models")
  37.      * @Serializer\Groups({"collection"}) 
  38.      * @Dashboard(label="Марка авто")
  39.      * @FormBuild(component="autocomplete", bindField="mark", field="title")
  40.      */
  41.     private $mark;
  42.     /**
  43.      * @Serializer\Groups({"selection/param"}) 
  44.      */
  45.     public function getMarkId()
  46.     {
  47.         return $this->mark->getId();
  48.     }
  49.     /**
  50.      * @ORM\Column(type="boolean")
  51.      * @Serializer\Groups({"collection"}) 
  52.      * @FormBuild(component="switch")
  53.      * @Dashboard(label="Скрыть на сайте", only=true, inverse=true)
  54.      */
  55.     private $public true;
  56.     /**
  57.      * @ORM\OneToMany(targetEntity=Modification::class, mappedBy="model", cascade={"persist", "remove"}, orphanRemoval=true)
  58.      */
  59.     private $modifications;
  60.     public function __construct()
  61.     {
  62.         $this->modifications = new ArrayCollection();
  63.     }
  64.     public function getId(): ?int
  65.     {
  66.         return $this->id;
  67.     }
  68.     public function getTitle(): ?string
  69.     {
  70.         return $this->title;
  71.     }
  72.     public function setTitle(string $title): self
  73.     {
  74.         $this->title $title;
  75.         return $this;
  76.     }
  77.     public function isPublic(): ?bool
  78.     {
  79.         return $this->public;
  80.     }
  81.     public function setPublic(bool $public): self
  82.     {
  83.         $this->public $public;
  84.         return $this;
  85.     }
  86.     public function getMark(): ?Mark
  87.     {
  88.         return $this->mark;
  89.     }
  90.     public function setMark(?Mark $mark): self
  91.     {
  92.         $this->mark $mark;
  93.         return $this;
  94.     }
  95.     /**
  96.      * @return Collection<int, Body>
  97.      */
  98.     public function getModifications(): Collection
  99.     {
  100.         return $this->bodies;
  101.     }
  102.     public function addModifications(Modification $modification): self
  103.     {
  104.         if (!$this->modifications->contains($modification)) {
  105.             $this->modifications[] = $modification;
  106.             $modification->setModel($this);
  107.         }
  108.         return $this;
  109.     }
  110.     public function removeModifications(Modification $modification): self
  111.     {
  112.         if ($this->modifications->removeElement($modification)) {
  113.             // set the owning side to null (unless already changed)
  114.             if ($modification->getModel() === $this) {
  115.                 $modification->setModel(null);
  116.             }
  117.         }
  118.         return $this;
  119.     }
  120. }