src/Entity/Food.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Eventable\EventableTrait;
  4. use App\Entity\Sortable\Sortable;
  5. use App\Entity\Sortable\SortableInterface;
  6. use App\Repository\FoodRepository;
  7. use Doctrine\Common\Collections\ArrayCollection;
  8. use Doctrine\Common\Collections\Collection;
  9. use Doctrine\ORM\Mapping as ORM;
  10. use Symfony\Component\Uid\Uuid;
  11. /**
  12.  * @ORM\Entity(repositoryClass=FoodRepository::class)
  13.  */
  14. class Food implements SortableInterface
  15. {
  16.     use Sortable;
  17.     /**
  18.      * @ORM\Id
  19.      * @ORM\Column(type="uuid", unique=true)
  20.      */
  21.     private $id;
  22.     /**
  23.      * @ORM\Column(type="string", length=255)
  24.      */
  25.     private $name;
  26.     /**
  27.      * @ORM\ManyToMany(targetEntity=Image::class, cascade={"persist", "remove"}, orphanRemoval=true)
  28.      */
  29.     private $images;
  30.     /**
  31.      * @ORM\Column(type="text", nullable=true)
  32.      */
  33.     private $description;
  34.     /**
  35.      * @ORM\ManyToMany(targetEntity=Event::class, inversedBy="food")
  36.      */
  37.     private $events;
  38.     public function __construct()
  39.     {
  40.         $this->id Uuid::v4();
  41.         $this->images = new ArrayCollection();
  42.         $this->events = new ArrayCollection();
  43.     }
  44.     public function getId(): string
  45.     {
  46.         return $this->id;
  47.     }
  48.     public function getName(): ?string
  49.     {
  50.         return $this->name;
  51.     }
  52.     public function setName(string $name): self
  53.     {
  54.         $this->name $name;
  55.         return $this;
  56.     }
  57.     /**
  58.      * @return Collection<int, Image>
  59.      */
  60.     public function getImages(): Collection
  61.     {
  62.         return $this->images;
  63.     }
  64.     public function addImage(Image $image): self
  65.     {
  66.         if (!$this->images->contains($image)) {
  67.             $this->images[] = $image;
  68.         }
  69.         return $this;
  70.     }
  71.     public function removeImage(Image $image): self
  72.     {
  73.         $this->images->removeElement($image);
  74.         return $this;
  75.     }
  76.     public function getDescription(): ?string
  77.     {
  78.         return $this->description;
  79.     }
  80.     public function setDescription(?string $description): self
  81.     {
  82.         $this->description $description;
  83.         return $this;
  84.     }
  85.     /**
  86.      * @return Collection<int, Event>
  87.      */
  88.     public function getEvents(): Collection
  89.     {
  90.         return $this->events;
  91.     }
  92.     public function addEvent(Event $event): self
  93.     {
  94.         if (!$this->events->contains($event)) {
  95.             $this->events[] = $event;
  96.         }
  97.         return $this;
  98.     }
  99.     public function removeEvent(Event $event): self
  100.     {
  101.         $this->events->removeElement($event);
  102.         return $this;
  103.     }
  104. }