src/Entity/Label.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\LabelRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Component\HttpFoundation\File\File;
  8. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  9. /**
  10.  * @ORM\Entity(repositoryClass=LabelRepository::class)
  11.  * @ORM\Table(name="`label`")
  12.  * @Vich\Uploadable
  13.  */
  14. class Label
  15. {
  16.     /**
  17.      * @ORM\Id
  18.      * @ORM\GeneratedValue
  19.      * @ORM\Column(type="integer")
  20.      */
  21.     private $id;
  22.     /**
  23.      * @ORM\Column(type="string", length=255)
  24.      */
  25.     private $nom;
  26.     /**
  27.      * @ORM\ManyToMany(targetEntity=Cuvee::class, mappedBy="labels")
  28.      */
  29.     private $cuvees;
  30.     /**
  31.      * @ORM\Column(type="string", length=255, nullable=true)
  32.      * 
  33.      */
  34.     private $image;
  35.     /**
  36.      * @Vich\UploadableField(mapping = "label_images", fileNameProperty = "image")
  37.      */
  38.     private $imageFile;
  39.     /**
  40.      * @ORM\Column(type="datetime", nullable=true)
  41.      */
  42.     private $date_modification;
  43.     public function __construct()
  44.     {
  45.         $this->cuvees = new ArrayCollection();
  46.     }
  47.     public function __toString()
  48.     {
  49.         return $this->nom;
  50.     }
  51.     public function getId(): ?int
  52.     {
  53.         return $this->id;
  54.     }
  55.     public function getNom(): ?string
  56.     {
  57.         return $this->nom;
  58.     }
  59.     public function setNom(string $nom): self
  60.     {
  61.         $this->nom $nom;
  62.         return $this;
  63.     }
  64.     /**
  65.      * @return Collection<int, Cuvee>
  66.      */
  67.     public function getCuvees(): Collection
  68.     {
  69.         return $this->cuvees;
  70.     }
  71.     public function addCuvee(Cuvee $cuvee): self
  72.     {
  73.         if (!$this->cuvees->contains($cuvee)) {
  74.             $this->cuvees[] = $cuvee;
  75.             $cuvee->addLabel($this);
  76.         }
  77.         return $this;
  78.     }
  79.     public function removeCuvee(Cuvee $cuvee): self
  80.     {
  81.         if ($this->cuvees->removeElement($cuvee)) {
  82.             $cuvee->removeLabel($this);
  83.         }
  84.         return $this;
  85.     }
  86.     public function getImage(): ?string
  87.     {
  88.         return $this->image;
  89.     }
  90.     public function setImage(?string $image): self
  91.     {
  92.         $this->image $image;
  93.         return $this;
  94.     }
  95.         /**
  96.      * If manually uploading a file (i.e. not using Symfony Form) ensure an instance
  97.      * of 'UploadedFile' is injected into this setter to trigger the update. If this
  98.      * bundle's configuration parameter 'inject_on_load' is set to 'true' this setter
  99.      * must be able to accept an instance of 'File' as the bundle will inject one here
  100.      * during Doctrine hydration.
  101.      *
  102.      * @param File|\Symfony\Component\HttpFoundation\File\UploadedFile|null $imageFile
  103.      */
  104.     public function setImageFile(?File $imageFile null): void
  105.     {
  106.         $this->imageFile $imageFile;
  107.         if (null !== $imageFile) {
  108.             // It is required that at least one field changes if you are using doctrine
  109.             // otherwise the event listeners won't be called and the file is lost
  110.             $this->date_modification = new \DateTimeImmutable();
  111.         }
  112.     }
  113.     public function getImageFile(): ?File
  114.     {
  115.         return $this->imageFile;
  116.     }
  117.     public function getDateModification(): ?\DateTimeInterface
  118.     {
  119.         return $this->date_modification;
  120.     }
  121.     public function setDateModification(?\DateTimeInterface $date_modification): self
  122.     {
  123.         $this->date_modification $date_modification;
  124.         return $this;
  125.     }
  126. }