src/Entity/Posts/Categorieposts.php line 25

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Posts;
  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 Exception;
  10. use Gedmo\Mapping\Annotation as Gedmo;
  11. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  12. use Symfony\Component\HttpFoundation\File\File;
  13. use Symfony\Component\HttpFoundation\File\UploadedFile;
  14. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  15. use Symfony\Component\Validator\Constraints as Assert;
  16. /**
  17.  * @ORM\Entity(repositoryClass="App\Repository\Posts\CategoriepostsRepository")
  18.  * @Table (name="categorieposts")
  19.  * @UniqueEntity("name")
  20.  * @Vich\Uploadable
  21.  */
  22. class Categorieposts
  23. {
  24.     const MENU = [
  25.         => "OU DORMIR",
  26.         => "OU ALLER",
  27.         => "OU MANGER",
  28.         => "LOCATION",
  29.     ];
  30.     /**
  31.      * @ORM\Id()
  32.      * @ORM\GeneratedValue()
  33.      * @ORM\Column(type="integer")
  34.      */
  35.     private $id;
  36.     /**
  37.      * @ORM\Column(type="string", length=255)
  38.      * @Assert\NotBlank(message="Veuillez saisir le nom de la catégorie")
  39.      */
  40.     private $name;
  41.     /**
  42.      * @ORM\Column(type="string", length=255)
  43.      * @Gedmo\Slug(fields={"name"})
  44.      */
  45.     private $slug;
  46.     /**
  47.      * @ORM\Column(type="text", nullable=true)
  48.      */
  49.     private $description;
  50.     /**
  51.      * NOTE: This is not a mapped field of entity metadata, just a simple property.
  52.      *
  53.      * @Vich\UploadableField(mapping="categories_image", fileNameProperty="filename")
  54.      * @var File|null
  55.      * @Assert\Image(
  56.      *     mimeTypes={"image/jpeg", "image/png"},
  57.      *
  58.      *     maxHeight=982,
  59.      *     maxWidth=1920,
  60.      *     maxHeightMessage="Votre image doit faire 982 d'hauteur",
  61.      *     maxWidthMessage="Votre image doit faire 1920 de largeur"
  62.      * )
  63.      */
  64.     private $imageFile;
  65.     /**
  66.      * @ORM\Column(type="string", length=255, nullable=true)
  67.      */
  68.     private $filename;
  69.     /**
  70.      * NOTE: This is not a mapped field of entity metadata, just a simple property.
  71.      *
  72.      * @Vich\UploadableField(mapping="categories_image", fileNameProperty="filenamecover")
  73.      * @var File|null
  74.      * @Assert\Image(
  75.      *     mimeTypes={"image/jpeg", "image/png"},
  76.      *     maxHeight=1280,
  77.      *     maxWidth=1920,
  78.      *     maxHeightMessage="Votre image doit faire 1280 d'hauteur",
  79.      *     maxWidthMessage="Votre image doit faire 1920 de largeur"
  80.      * )
  81.      */
  82.     private $imageCover;
  83.     /**
  84.      * @ORM\Column(type="string", length=255, nullable=true)
  85.      */
  86.     private $filenamecover;
  87.     /**
  88.      * NOTE: This is not a mapped field of entity metadata, just a simple property.
  89.      *
  90.      * @Vich\UploadableField(mapping="documents_files", fileNameProperty="documents")
  91.      * @var File|null
  92.      * @Assert\File(
  93.      *     mimeTypes={"application/pdf", "application/x-pdf"}
  94.      * )
  95.      */
  96.     private $documentsFile;
  97.     /**
  98.      * @var string|null
  99.      * @ORM\Column(type="string", length=255, nullable=true)
  100.      */
  101.     private $documents;
  102.     /**
  103.      * NOTE: This is not a mapped field of entity metadata, just a simple property.
  104.      *
  105.      * @Vich\UploadableField(mapping="categories_image", fileNameProperty="documentcover")
  106.      * @var File|null
  107.      * @Assert\Image(
  108.      *     mimeTypes={"image/jpeg", "image/png"},
  109.      *     maxHeight=500,
  110.      *     maxWidth=500,
  111.      *     maxHeightMessage="Votre image doit faire 500 d'hauteur",
  112.      *     maxWidthMessage="Votre image doit faire 500 de largeur"
  113.      * )
  114.      */
  115.     private $fileCover;
  116.     /**
  117.      * @ORM\Column(type="string", length=255, nullable=true)
  118.      */
  119.     private $documentcover;
  120.     /**
  121.      * @ORM\Column(type="integer", nullable=true, options={"default": 0})
  122.      */
  123.     private $ordre;
  124.     /**
  125.      * @ORM\Column(type="boolean", nullable=true)
  126.      */
  127.     private $online;
  128.     /**
  129.      * @ORM\Column(type="integer")
  130.      */
  131.     private $menu;
  132.     /**
  133.      * @var DateTime $updatedAt
  134.      * @ORM\Column(type="datetime", nullable=true)
  135.      *
  136.      * @Gedmo\Timestampable(on="update")
  137.      */
  138.     private $updatedAt;
  139.     /**
  140.      * @ORM\OneToMany(targetEntity="App\Entity\Posts\Posts", mappedBy="categories")
  141.      */
  142.     private $posts;
  143.     /**
  144.      * @ORM\Column(type="string", length=255, nullable=true)
  145.      */
  146.     private $role;
  147.     public function __construct()
  148.     {
  149.         $this->posts = new ArrayCollection();
  150.     }
  151.     public function getId(): ?int
  152.     {
  153.         return $this->id;
  154.     }
  155.     public function getName(): ?string
  156.     {
  157.         return $this->name;
  158.     }
  159.     public function setName(string $name): self
  160.     {
  161.         $this->name $name;
  162.         return $this;
  163.     }
  164.     public function getSlug(): ?string
  165.     {
  166.         return $this->slug;
  167.     }
  168.     public function getDescription(): ?string
  169.     {
  170.         return $this->description;
  171.     }
  172.     public function setDescription(?string $description): self
  173.     {
  174.         $this->description $description;
  175.         return $this;
  176.     }
  177.     /**
  178.      * @return File|null
  179.      */
  180.     public function getImageFile(): ?File
  181.     {
  182.         return $this->imageFile;
  183.     }
  184.     /**
  185.      * @param File|null $imageFile
  186.      * @return Categorieposts
  187.      * @throws Exception
  188.      */
  189.     public function setImageFile(?File $imageFile): Categorieposts
  190.     {
  191.         $this->imageFile $imageFile;
  192.         if ($this->imageFile instanceof UploadedFile) {
  193.             // It is required that at least one field changes if you are using doctrine
  194.             // otherwise the event listeners won't be called and the file is lost
  195.             $this->updatedAt = new DateTimeImmutable('now');
  196.         }
  197.         return $this;
  198.     }
  199.     public function getFilename(): ?string
  200.     {
  201.         return $this->filename;
  202.     }
  203.     public function setFilename(?string $filename): self
  204.     {
  205.         $this->filename $filename;
  206.         return $this;
  207.     }
  208.     /**
  209.      * @return File|null
  210.      */
  211.     public function getImageCover(): ?File
  212.     {
  213.         return $this->imageCover;
  214.     }
  215.     /**
  216.      * @param File|null $imageCover
  217.      * @return Categorieposts
  218.      * @throws Exception
  219.      */
  220.     public function setImageCover(?File $imageCover): Categorieposts
  221.     {
  222.         $this->imageCover $imageCover;
  223.         if ($this->imageCover instanceof UploadedFile) {
  224.             // It is required that at least one field changes if you are using doctrine
  225.             // otherwise the event listeners won't be called and the file is lost
  226.             $this->updatedAt = new DateTimeImmutable('now');
  227.         }
  228.         return $this;
  229.     }
  230.     public function getFilenamecover(): ?string
  231.     {
  232.         return $this->filenamecover;
  233.     }
  234.     public function setFilenamecover(?string $filenamecover): self
  235.     {
  236.         $this->filenamecover $filenamecover;
  237.         return $this;
  238.     }
  239.     public function getOrdre(): ?int
  240.     {
  241.         return $this->ordre;
  242.     }
  243.     public function setOrdre(int $ordre): self
  244.     {
  245.         $this->ordre $ordre;
  246.         return $this;
  247.     }
  248.     public function getMenu(): ?int
  249.     {
  250.         return $this->menu;
  251.     }
  252.     public function setMenu(int $menu): self
  253.     {
  254.         $this->menu $menu;
  255.         return $this;
  256.     }
  257.     public function getMenuType(): string {
  258.         return self::MENU[$this->menu];
  259.     }
  260.     public function getUpdatedAt(): ?\DateTimeInterface
  261.     {
  262.         return $this->updatedAt;
  263.     }
  264.     public function __toString()
  265.     {
  266.         return $this->name;
  267.     }
  268.     /**
  269.      * @return Collection|Posts[]
  270.      */
  271.     public function getPosts(): Collection
  272.     {
  273.         return $this->posts;
  274.     }
  275.     public function addPost(Posts $post): self
  276.     {
  277.         if (!$this->posts->contains($post)) {
  278.             $this->posts[] = $post;
  279.             $post->setCategories($this);
  280.         }
  281.         return $this;
  282.     }
  283.     public function removePost(Posts $post): self
  284.     {
  285.         if ($this->posts->contains($post)) {
  286.             $this->posts->removeElement($post);
  287.             // set the owning side to null (unless already changed)
  288.             if ($post->getCategories() === $this) {
  289.                 $post->setCategories(null);
  290.             }
  291.         }
  292.         return $this;
  293.     }
  294.     public function getRole(): ?string
  295.     {
  296.         return $this->role;
  297.     }
  298.     public function setRole(?string $role): self
  299.     {
  300.         $this->role $role;
  301.         return $this;
  302.     }
  303.     /**
  304.      * @return mixed
  305.      */
  306.     public function getOnline()
  307.     {
  308.         return $this->online;
  309.     }
  310.     /**
  311.      * @param mixed $online
  312.      * @return Categorieposts
  313.      */
  314.     public function setOnline($online): Categorieposts
  315.     {
  316.         $this->online $online;
  317.         return $this;
  318.     }
  319.     /**
  320.      * @return File|null
  321.      */
  322.     public function getDocumentsFile(): ?File
  323.     {
  324.         return $this->documentsFile;
  325.     }
  326.     /**
  327.      * @param File|null $documentsFile
  328.      * @return Categorieposts
  329.      * @throws Exception
  330.      */
  331.     public function setDocumentsFile(?File $documentsFile): Categorieposts
  332.     {
  333.         $this->documentsFile $documentsFile;
  334.         if ($this->documentsFile instanceof UploadedFile) {
  335.             // It is required that at least one field changes if you are using doctrine
  336.             // otherwise the event listeners won't be called and the file is lost
  337.             $this->updatedAt = new DateTimeImmutable('now');
  338.         }
  339.         return $this;
  340.     }
  341.     public function getDocuments(): ?string
  342.     {
  343.         return $this->documents;
  344.     }
  345.     public function setDocuments(string $documents): self
  346.     {
  347.         $this->documents $documents;
  348.         return $this;
  349.     }
  350.     /**
  351.      * @return File|null
  352.      */
  353.     public function getFileCover(): ?File
  354.     {
  355.         return $this->fileCover;
  356.     }
  357.     /**
  358.      * @param File|null $fileCover
  359.      * @return Categorieposts
  360.      * @throws Exception
  361.      */
  362.     public function setFileCover(?File $fileCover): Categorieposts
  363.     {
  364.         $this->fileCover $fileCover;
  365.         if ($this->fileCover instanceof UploadedFile) {
  366.             // It is required that at least one field changes if you are using doctrine
  367.             // otherwise the event listeners won't be called and the file is lost
  368.             $this->updatedAt = new DateTimeImmutable('now');
  369.         }
  370.         return $this;
  371.     }
  372.     public function getDocumentcover(): ?string
  373.     {
  374.         return $this->documentcover;
  375.     }
  376.     public function setDocumentcover(string $documentcover): self
  377.     {
  378.         $this->documentcover $documentcover;
  379.         return $this;
  380.     }
  381. }