<?php
namespace App\Entity\Posts;
use DateTime;
use DateTimeImmutable;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\ORM\Mapping\Table;
use Exception;
use Gedmo\Mapping\Annotation as Gedmo;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity(repositoryClass="App\Repository\Posts\CategoriepostsRepository")
* @Table (name="categorieposts")
* @UniqueEntity("name")
* @Vich\Uploadable
*/
class Categorieposts
{
const MENU = [
0 => "OU DORMIR",
1 => "OU ALLER",
2 => "OU MANGER",
3 => "LOCATION",
];
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
* @Assert\NotBlank(message="Veuillez saisir le nom de la catégorie")
*/
private $name;
/**
* @ORM\Column(type="string", length=255)
* @Gedmo\Slug(fields={"name"})
*/
private $slug;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $description;
/**
* NOTE: This is not a mapped field of entity metadata, just a simple property.
*
* @Vich\UploadableField(mapping="categories_image", fileNameProperty="filename")
* @var File|null
* @Assert\Image(
* mimeTypes={"image/jpeg", "image/png"},
*
* maxHeight=982,
* maxWidth=1920,
* maxHeightMessage="Votre image doit faire 982 d'hauteur",
* maxWidthMessage="Votre image doit faire 1920 de largeur"
* )
*/
private $imageFile;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $filename;
/**
* NOTE: This is not a mapped field of entity metadata, just a simple property.
*
* @Vich\UploadableField(mapping="categories_image", fileNameProperty="filenamecover")
* @var File|null
* @Assert\Image(
* mimeTypes={"image/jpeg", "image/png"},
* maxHeight=1280,
* maxWidth=1920,
* maxHeightMessage="Votre image doit faire 1280 d'hauteur",
* maxWidthMessage="Votre image doit faire 1920 de largeur"
* )
*/
private $imageCover;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $filenamecover;
/**
* NOTE: This is not a mapped field of entity metadata, just a simple property.
*
* @Vich\UploadableField(mapping="documents_files", fileNameProperty="documents")
* @var File|null
* @Assert\File(
* mimeTypes={"application/pdf", "application/x-pdf"}
* )
*/
private $documentsFile;
/**
* @var string|null
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $documents;
/**
* NOTE: This is not a mapped field of entity metadata, just a simple property.
*
* @Vich\UploadableField(mapping="categories_image", fileNameProperty="documentcover")
* @var File|null
* @Assert\Image(
* mimeTypes={"image/jpeg", "image/png"},
* maxHeight=500,
* maxWidth=500,
* maxHeightMessage="Votre image doit faire 500 d'hauteur",
* maxWidthMessage="Votre image doit faire 500 de largeur"
* )
*/
private $fileCover;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $documentcover;
/**
* @ORM\Column(type="integer", nullable=true, options={"default": 0})
*/
private $ordre;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $online;
/**
* @ORM\Column(type="integer")
*/
private $menu;
/**
* @var DateTime $updatedAt
* @ORM\Column(type="datetime", nullable=true)
*
* @Gedmo\Timestampable(on="update")
*/
private $updatedAt;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Posts\Posts", mappedBy="categories")
*/
private $posts;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $role;
public function __construct()
{
$this->posts = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getSlug(): ?string
{
return $this->slug;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): self
{
$this->description = $description;
return $this;
}
/**
* @return File|null
*/
public function getImageFile(): ?File
{
return $this->imageFile;
}
/**
* @param File|null $imageFile
* @return Categorieposts
* @throws Exception
*/
public function setImageFile(?File $imageFile): Categorieposts
{
$this->imageFile = $imageFile;
if ($this->imageFile instanceof UploadedFile) {
// It is required that at least one field changes if you are using doctrine
// otherwise the event listeners won't be called and the file is lost
$this->updatedAt = new DateTimeImmutable('now');
}
return $this;
}
public function getFilename(): ?string
{
return $this->filename;
}
public function setFilename(?string $filename): self
{
$this->filename = $filename;
return $this;
}
/**
* @return File|null
*/
public function getImageCover(): ?File
{
return $this->imageCover;
}
/**
* @param File|null $imageCover
* @return Categorieposts
* @throws Exception
*/
public function setImageCover(?File $imageCover): Categorieposts
{
$this->imageCover = $imageCover;
if ($this->imageCover instanceof UploadedFile) {
// It is required that at least one field changes if you are using doctrine
// otherwise the event listeners won't be called and the file is lost
$this->updatedAt = new DateTimeImmutable('now');
}
return $this;
}
public function getFilenamecover(): ?string
{
return $this->filenamecover;
}
public function setFilenamecover(?string $filenamecover): self
{
$this->filenamecover = $filenamecover;
return $this;
}
public function getOrdre(): ?int
{
return $this->ordre;
}
public function setOrdre(int $ordre): self
{
$this->ordre = $ordre;
return $this;
}
public function getMenu(): ?int
{
return $this->menu;
}
public function setMenu(int $menu): self
{
$this->menu = $menu;
return $this;
}
public function getMenuType(): string {
return self::MENU[$this->menu];
}
public function getUpdatedAt(): ?\DateTimeInterface
{
return $this->updatedAt;
}
public function __toString()
{
return $this->name;
}
/**
* @return Collection|Posts[]
*/
public function getPosts(): Collection
{
return $this->posts;
}
public function addPost(Posts $post): self
{
if (!$this->posts->contains($post)) {
$this->posts[] = $post;
$post->setCategories($this);
}
return $this;
}
public function removePost(Posts $post): self
{
if ($this->posts->contains($post)) {
$this->posts->removeElement($post);
// set the owning side to null (unless already changed)
if ($post->getCategories() === $this) {
$post->setCategories(null);
}
}
return $this;
}
public function getRole(): ?string
{
return $this->role;
}
public function setRole(?string $role): self
{
$this->role = $role;
return $this;
}
/**
* @return mixed
*/
public function getOnline()
{
return $this->online;
}
/**
* @param mixed $online
* @return Categorieposts
*/
public function setOnline($online): Categorieposts
{
$this->online = $online;
return $this;
}
/**
* @return File|null
*/
public function getDocumentsFile(): ?File
{
return $this->documentsFile;
}
/**
* @param File|null $documentsFile
* @return Categorieposts
* @throws Exception
*/
public function setDocumentsFile(?File $documentsFile): Categorieposts
{
$this->documentsFile = $documentsFile;
if ($this->documentsFile instanceof UploadedFile) {
// It is required that at least one field changes if you are using doctrine
// otherwise the event listeners won't be called and the file is lost
$this->updatedAt = new DateTimeImmutable('now');
}
return $this;
}
public function getDocuments(): ?string
{
return $this->documents;
}
public function setDocuments(string $documents): self
{
$this->documents = $documents;
return $this;
}
/**
* @return File|null
*/
public function getFileCover(): ?File
{
return $this->fileCover;
}
/**
* @param File|null $fileCover
* @return Categorieposts
* @throws Exception
*/
public function setFileCover(?File $fileCover): Categorieposts
{
$this->fileCover = $fileCover;
if ($this->fileCover instanceof UploadedFile) {
// It is required that at least one field changes if you are using doctrine
// otherwise the event listeners won't be called and the file is lost
$this->updatedAt = new DateTimeImmutable('now');
}
return $this;
}
public function getDocumentcover(): ?string
{
return $this->documentcover;
}
public function setDocumentcover(string $documentcover): self
{
$this->documentcover = $documentcover;
return $this;
}
}