src/Entity/Categorieimages.php line 23

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use DateTimeImmutable;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Doctrine\ORM\Mapping\Table;
  8. use Gedmo\Mapping\Annotation as Gedmo;
  9. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  10. use Symfony\Component\HttpFoundation\File\File;
  11. use Symfony\Component\HttpFoundation\File\UploadedFile;
  12. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  13. use Symfony\Component\Validator\Constraints as Assert;
  14. /**
  15.  * @ORM\Entity(repositoryClass="App\Repository\CategorieimagesRepository")
  16.  * @Table (name="categorieimages")
  17.  * @UniqueEntity("name")
  18.  * @Vich\Uploadable
  19.  */
  20. class Categorieimages
  21. {
  22.     /**
  23.      * @ORM\Id()
  24.      * @ORM\GeneratedValue()
  25.      * @ORM\Column(type="integer")
  26.      */
  27.     private $id;
  28.     /**
  29.      * @ORM\Column(type="string", length=255)
  30.      * @Assert\NotBlank(message="Veuillez saisir le nom de la catégorie")
  31.      */
  32.     private $name;
  33.     /**
  34.      * @ORM\Column(type="string", length=255)
  35.      * @Gedmo\Slug(fields={"name"})
  36.      */
  37.     private $slug;
  38.     /**
  39.      * NOTE: This is not a mapped field of entity metadata, just a simple property.
  40.      *
  41.      * @Vich\UploadableField(mapping="categories_image", fileNameProperty="filename")
  42.      * @var File|null
  43.      * @Assert\Image(
  44.      *     mimeTypes={"image/jpeg", "image/png"},
  45.      *
  46.      *     maxHeight=1280,
  47.      *     maxWidth=1920,
  48.      *     maxHeightMessage="Votre image doit faire 1280 d'hauteur",
  49.      *     maxWidthMessage="Votre image doit faire 1920 de largeur"
  50.      * )
  51.      */
  52.     private $imageFile;
  53.     /**
  54.      * @ORM\Column(type="string", length=255, nullable=true)
  55.      */
  56.     private $filename;
  57.     /**
  58.      * @var \DateTime $updatedAt
  59.      * @ORM\Column(type="datetime", nullable=true)
  60.      *
  61.      * @Gedmo\Timestampable(on="update")
  62.      */
  63.     private $updatedAt;
  64.     /**
  65.      * @ORM\OneToMany(targetEntity="App\Entity\Enimages", mappedBy="categories")
  66.      */
  67.     private $enimages;
  68.     /**
  69.      * @ORM\Column(type="text", nullable=true)
  70.      */
  71.     private $content;
  72.     public function __construct()
  73.     {
  74.         $this->enimages = new ArrayCollection();
  75.     }
  76.     public function getId(): ?int
  77.     {
  78.         return $this->id;
  79.     }
  80.     public function getName(): ?string
  81.     {
  82.         return $this->name;
  83.     }
  84.     public function setName(string $name): self
  85.     {
  86.         $this->name $name;
  87.         return $this;
  88.     }
  89.     public function getSlug(): ?string
  90.     {
  91.         return $this->slug;
  92.     }
  93.     /**
  94.      * @return File|null
  95.      */
  96.     public function getImageFile(): ?File
  97.     {
  98.         return $this->imageFile;
  99.     }
  100.     /**
  101.      * @param File|null $imageFile
  102.      * @return Categorieimages
  103.      * @throws \Exception
  104.      */
  105.     public function setImageFile(?File $imageFile): Categorieimages
  106.     {
  107.         $this->imageFile $imageFile;
  108.         if ($this->imageFile instanceof UploadedFile) {
  109.             // It is required that at least one field changes if you are using doctrine
  110.             // otherwise the event listeners won't be called and the file is lost
  111.             $this->updatedAt = new DateTimeImmutable('now');
  112.         }
  113.         return $this;
  114.     }
  115.     public function getFilename(): ?string
  116.     {
  117.         return $this->filename;
  118.     }
  119.     public function setFilename(?string $filename): self
  120.     {
  121.         $this->filename $filename;
  122.         return $this;
  123.     }
  124.     public function getUpdatedAt(): ?\DateTimeInterface
  125.     {
  126.         return $this->updatedAt;
  127.     }
  128.     /**
  129.      * @return Collection|Enimages[]
  130.      */
  131.     public function getEnimages(): Collection
  132.     {
  133.         return $this->enimages;
  134.     }
  135.     public function addEnimage(Enimages $enimage): self
  136.     {
  137.         if (!$this->enimages->contains($enimage)) {
  138.             $this->enimages[] = $enimage;
  139.             $enimage->setCategories($this);
  140.         }
  141.         return $this;
  142.     }
  143.     public function removeEnimage(Enimages $enimage): self
  144.     {
  145.         if ($this->enimages->contains($enimage)) {
  146.             $this->enimages->removeElement($enimage);
  147.             // set the owning side to null (unless already changed)
  148.             if ($enimage->getCategories() === $this) {
  149.                 $enimage->setCategories(null);
  150.             }
  151.         }
  152.         return $this;
  153.     }
  154.     public function __toString()
  155.     {
  156.         return $this->name;
  157.     }
  158.     public function getContent(): ?string
  159.     {
  160.         return $this->content;
  161.     }
  162.     public function setContent(?string $content): self
  163.     {
  164.         $this->content $content;
  165.         return $this;
  166.     }
  167. }