src/Entity/Directions.php line 22

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Common\DatesTrait;
  4. use App\Entity\Common\IdTrait;
  5. use App\Entity\Common\OrdreTrait;
  6. use App\Entity\Common\SlugTrait;
  7. use DateTimeImmutable;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  10. use Symfony\Component\HttpFoundation\File\File;
  11. use Symfony\Component\HttpFoundation\File\UploadedFile;
  12. use Symfony\Component\Validator\Constraints as Assert;
  13. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  14. /**
  15.  * @ORM\Entity(repositoryClass="App\Repository\DirectionsRepository")
  16.  * @UniqueEntity("name")
  17.  * @Vich\Uploadable
  18.  */
  19. class Directions
  20. {
  21.     use IdTrait;
  22.     use OrdreTrait;
  23.     use DatesTrait;
  24.     use SlugTrait;
  25.     /**
  26.      * @ORM\Column(type="string", length=255)
  27.      * @Assert\NotBlank(message="Veuillez saisir un nom")
  28.      */
  29.     private $name;
  30.     /**
  31.      * @ORM\Column(type="string", length=500, nullable=true)
  32.      */
  33.     private $extrait;
  34.     /**
  35.      * @ORM\Column(type="text", nullable=true)
  36.      */
  37.     private $content;
  38.     /**
  39.      * @ORM\Column(type="boolean")
  40.      */
  41.     private $online;
  42.     /**
  43.      * @ORM\Column(type="integer", nullable=true, options={"default": 0})
  44.      */
  45.     private $views;
  46.     /**
  47.      * NOTE: This is not a mapped field of entity metadata, just a simple property.
  48.      *
  49.      * @Vich\UploadableField(mapping="directions_image", fileNameProperty="filename")
  50.      * @var File|null
  51.      * @Assert\Image(
  52.      *     mimeTypes={"image/jpeg", "image/png"},
  53.      *
  54.      *     maxHeight=1280,
  55.      *     maxWidth=1920,
  56.      *     maxHeightMessage="Votre image doit faire 1280 d'hauteur",
  57.      *     maxWidthMessage="Votre image doit faire 1920 de largeur"
  58.      * )
  59.      */
  60.     private $imageFile;
  61.     /**
  62.      * @ORM\Column(type="string", length=255, nullable=true)
  63.      */
  64.     private $filename;
  65.     /**
  66.      * @ORM\ManyToOne(targetEntity="App\Entity\User", inversedBy="directions")
  67.      */
  68.     private $user;
  69.     /**
  70.      * @ORM\ManyToOne(targetEntity="App\Entity\User")
  71.      */
  72.     private $updatedBy;
  73.     public function getName(): ?string
  74.     {
  75.         return $this->name;
  76.     }
  77.     public function setName(string $name): self
  78.     {
  79.         $this->name $name;
  80.         return $this;
  81.     }
  82.     public function getExtrait(): ?string
  83.     {
  84.         return $this->extrait;
  85.     }
  86.     public function setExtrait(?string $extrait): self
  87.     {
  88.         $this->extrait $extrait;
  89.         return $this;
  90.     }
  91.     public function getContent(): ?string
  92.     {
  93.         return $this->content;
  94.     }
  95.     public function setContent(?string $content): self
  96.     {
  97.         $this->content $content;
  98.         return $this;
  99.     }
  100.     public function getOnline(): ?bool
  101.     {
  102.         return $this->online;
  103.     }
  104.     public function setOnline(bool $online): self
  105.     {
  106.         $this->online $online;
  107.         return $this;
  108.     }
  109.     public function getViews(): ?int
  110.     {
  111.         return $this->views;
  112.     }
  113.     public function setViews(int $views): self
  114.     {
  115.         $this->views $views;
  116.         return $this;
  117.     }
  118.     /**
  119.      * @return File|null
  120.      */
  121.     public function getImageFile(): ?File
  122.     {
  123.         return $this->imageFile;
  124.     }
  125.     /**
  126.      * @param File|null $imageFile
  127.      * @return Directions
  128.      * @throws \Exception
  129.      */
  130.     public function setImageFile(?File $imageFile): Directions
  131.     {
  132.         $this->imageFile $imageFile;
  133.         if ($this->imageFile instanceof UploadedFile) {
  134.             // It is required that at least one field changes if you are using doctrine
  135.             // otherwise the event listeners won't be called and the file is lost
  136.             $this->updatedAt = new DateTimeImmutable('now');
  137.         }
  138.         return $this;
  139.     }
  140.     public function getFilename(): ?string
  141.     {
  142.         return $this->filename;
  143.     }
  144.     public function setFilename(?string $filename): self
  145.     {
  146.         $this->filename $filename;
  147.         return $this;
  148.     }
  149.     public function getUser(): ?User
  150.     {
  151.         return $this->user;
  152.     }
  153.     public function setUser(?User $user): self
  154.     {
  155.         $this->user $user;
  156.         return $this;
  157.     }
  158.     public function getUpdatedBy(): ?User
  159.     {
  160.         return $this->updatedBy;
  161.     }
  162.     public function setUpdatedBy(?User $updatedBy): self
  163.     {
  164.         $this->updatedBy $updatedBy;
  165.         return $this;
  166.     }
  167. }