<?php
namespace App\Entity;
use DateTimeImmutable;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\ORM\Mapping\Table;
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\CategorieimagesRepository")
* @Table (name="categorieimages")
* @UniqueEntity("name")
* @Vich\Uploadable
*/
class Categorieimages
{
/**
* @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;
/**
* 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=1280,
* maxWidth=1920,
* maxHeightMessage="Votre image doit faire 1280 d'hauteur",
* maxWidthMessage="Votre image doit faire 1920 de largeur"
* )
*/
private $imageFile;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $filename;
/**
* @var \DateTime $updatedAt
* @ORM\Column(type="datetime", nullable=true)
*
* @Gedmo\Timestampable(on="update")
*/
private $updatedAt;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Enimages", mappedBy="categories")
*/
private $enimages;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $content;
public function __construct()
{
$this->enimages = 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;
}
/**
* @return File|null
*/
public function getImageFile(): ?File
{
return $this->imageFile;
}
/**
* @param File|null $imageFile
* @return Categorieimages
* @throws \Exception
*/
public function setImageFile(?File $imageFile): Categorieimages
{
$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;
}
public function getUpdatedAt(): ?\DateTimeInterface
{
return $this->updatedAt;
}
/**
* @return Collection|Enimages[]
*/
public function getEnimages(): Collection
{
return $this->enimages;
}
public function addEnimage(Enimages $enimage): self
{
if (!$this->enimages->contains($enimage)) {
$this->enimages[] = $enimage;
$enimage->setCategories($this);
}
return $this;
}
public function removeEnimage(Enimages $enimage): self
{
if ($this->enimages->contains($enimage)) {
$this->enimages->removeElement($enimage);
// set the owning side to null (unless already changed)
if ($enimage->getCategories() === $this) {
$enimage->setCategories(null);
}
}
return $this;
}
public function __toString()
{
return $this->name;
}
public function getContent(): ?string
{
return $this->content;
}
public function setContent(?string $content): self
{
$this->content = $content;
return $this;
}
}