src/Entity/Articles/Categoriearticles.php line 24

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Articles;
  3. use DateTime;
  4. use DateTimeImmutable;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Doctrine\ORM\Mapping\Table;
  9. use Gedmo\Mapping\Annotation as Gedmo;
  10. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  11. use Symfony\Component\HttpFoundation\File\File;
  12. use Symfony\Component\HttpFoundation\File\UploadedFile;
  13. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  14. use Symfony\Component\Validator\Constraints as Assert;
  15. /**
  16.  * @ORM\Entity(repositoryClass="App\Repository\Articles\CategoriearticlesRepository")
  17.  * @Table (name="categoriearticles")
  18.  * @UniqueEntity("name")
  19.  * @Vich\Uploadable
  20.  */
  21. class Categoriearticles
  22. {
  23.     const MENU = [
  24.         => "ATOUTS TOURISTIQUES",
  25.         => "TYPES DE TOURISME"
  26.     ];
  27.     /**
  28.      * @ORM\Id()
  29.      * @ORM\GeneratedValue()
  30.      * @ORM\Column(type="integer")
  31.      */
  32.     private $id;
  33.     /**
  34.      * @ORM\Column(type="string", length=255)
  35.      * @Assert\NotBlank(message="Veuillez saisir le nom de la catégorie")
  36.      */
  37.     private $name;
  38.     /**
  39.      * @ORM\Column(type="string", length=255)
  40.      * @Gedmo\Slug(fields={"name"})
  41.      */
  42.     private $slug;
  43.     /**
  44.      * @ORM\OneToMany(targetEntity="App\Entity\Articles\Articles", mappedBy="categories")
  45.      */
  46.     private $articles;
  47.     /**
  48.      * @ORM\Column(type="text", nullable=true)
  49.      */
  50.     private $description;
  51.     /**
  52.      * @ORM\Column(type="integer")
  53.      */
  54.     private $ordre;
  55.     /**
  56.      * @ORM\Column(type="integer")
  57.      */
  58.     private $menu;
  59.     /**
  60.      * NOTE: This is not a mapped field of entity metadata, just a simple property.
  61.      *
  62.      * @Vich\UploadableField(mapping="categories_image", fileNameProperty="filename")
  63.      * @var File|null
  64.      * @Assert\Image(
  65.      *     mimeTypes={"image/jpeg", "image/png"},
  66.      *
  67.      *     maxHeight=982,
  68.      *     maxWidth=1920,
  69.      *     maxHeightMessage="Votre image doit faire 982 d'hauteur",
  70.      *     maxWidthMessage="Votre image doit faire 1920 de largeur"
  71.      * )
  72.      */
  73.     private $imageFile;
  74.     /**
  75.      * @ORM\Column(type="string", length=255, nullable=true)
  76.      */
  77.     private $filename;
  78.     /**
  79.      * @var DateTime $updatedAt
  80.      * @ORM\Column(type="datetime", nullable=true)
  81.      *
  82.      * @Gedmo\Timestampable(on="update")
  83.      */
  84.     private $updatedAt;
  85.     /**
  86.      * @ORM\Column(type="string", length=255, nullable=true)
  87.      */
  88.     private $laus;
  89.     public function __construct()
  90.     {
  91.         $this->articles = new ArrayCollection();
  92.     }
  93.     public function getId(): ?int
  94.     {
  95.         return $this->id;
  96.     }
  97.     public function getName(): ?string
  98.     {
  99.         return $this->name;
  100.     }
  101.     public function setName(string $name): self
  102.     {
  103.         $this->name $name;
  104.         return $this;
  105.     }
  106.     public function getSlug(): ?string
  107.     {
  108.         return $this->slug;
  109.     }
  110.     public function setSlug(string $slug): self
  111.     {
  112.         $this->slug $slug;
  113.         return $this;
  114.     }
  115.     /**
  116.      * @return Collection|Articles[]
  117.      */
  118.     public function getArticles(): Collection
  119.     {
  120.         return $this->articles;
  121.     }
  122.     public function addArticle(Articles $article): self
  123.     {
  124.         if (!$this->articles->contains($article)) {
  125.             $this->articles[] = $article;
  126.             $article->setCategories($this);
  127.         }
  128.         return $this;
  129.     }
  130.     public function removeArticle(Articles $article): self
  131.     {
  132.         if ($this->articles->contains($article)) {
  133.             $this->articles->removeElement($article);
  134.             // set the owning side to null (unless already changed)
  135.             if ($article->getCategories() === $this) {
  136.                 $article->setCategories(null);
  137.             }
  138.         }
  139.         return $this;
  140.     }
  141.     public function getDescription(): ?string
  142.     {
  143.         return $this->description;
  144.     }
  145.     public function setDescription(?string $description): self
  146.     {
  147.         $this->description $description;
  148.         return $this;
  149.     }
  150.     public function getOrdre(): ?int
  151.     {
  152.         return $this->ordre;
  153.     }
  154.     public function setOrdre(int $ordre): self
  155.     {
  156.         $this->ordre $ordre;
  157.         return $this;
  158.     }
  159.     public function getMenu(): ?int
  160.     {
  161.         return $this->menu;
  162.     }
  163.     public function setMenu(int $menu): self
  164.     {
  165.         $this->menu $menu;
  166.         return $this;
  167.     }
  168.     public function getMenuType(): string {
  169.         return self::MENU[$this->menu];
  170.     }
  171.     /**
  172.      * @return File|null
  173.      */
  174.     public function getImageFile(): ?File
  175.     {
  176.         return $this->imageFile;
  177.     }
  178.     /**
  179.      * @param File|null $imageFile
  180.      * @return Categoriearticles
  181.      * @throws \Exception
  182.      */
  183.     public function setImageFile(?File $imageFile): Categoriearticles
  184.     {
  185.         $this->imageFile $imageFile;
  186.         if ($this->imageFile instanceof UploadedFile) {
  187.             // It is required that at least one field changes if you are using doctrine
  188.             // otherwise the event listeners won't be called and the file is lost
  189.             $this->updatedAt = new DateTimeImmutable('now');
  190.         }
  191.         return $this;
  192.     }
  193.     public function getFilename(): ?string
  194.     {
  195.         return $this->filename;
  196.     }
  197.     public function setFilename(?string $filename): self
  198.     {
  199.         $this->filename $filename;
  200.         return $this;
  201.     }
  202.     public function getUpdatedAt(): ?\DateTimeInterface
  203.     {
  204.         return $this->updatedAt;
  205.     }
  206.     public function __toString()
  207.     {
  208.         return $this->name;
  209.     }
  210.     public function getLaus(): ?string
  211.     {
  212.         return $this->laus;
  213.     }
  214.     public function setLaus(?string $laus): self
  215.     {
  216.         $this->laus $laus;
  217.         return $this;
  218.     }
  219. }