<?php
namespace App\Entity;
use App\Entity\Common\DatesTrait;
use App\Entity\Common\IdTrait;
use App\Entity\Common\OrdreTrait;
use App\Entity\Common\SlugTrait;
use DateTimeImmutable;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\Validator\Constraints as Assert;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
/**
* @ORM\Entity(repositoryClass="App\Repository\DirectionsRepository")
* @UniqueEntity("name")
* @Vich\Uploadable
*/
class Directions
{
use IdTrait;
use OrdreTrait;
use DatesTrait;
use SlugTrait;
/**
* @ORM\Column(type="string", length=255)
* @Assert\NotBlank(message="Veuillez saisir un nom")
*/
private $name;
/**
* @ORM\Column(type="string", length=500, nullable=true)
*/
private $extrait;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $content;
/**
* @ORM\Column(type="boolean")
*/
private $online;
/**
* @ORM\Column(type="integer", nullable=true, options={"default": 0})
*/
private $views;
/**
* NOTE: This is not a mapped field of entity metadata, just a simple property.
*
* @Vich\UploadableField(mapping="directions_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;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\User", inversedBy="directions")
*/
private $user;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\User")
*/
private $updatedBy;
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getExtrait(): ?string
{
return $this->extrait;
}
public function setExtrait(?string $extrait): self
{
$this->extrait = $extrait;
return $this;
}
public function getContent(): ?string
{
return $this->content;
}
public function setContent(?string $content): self
{
$this->content = $content;
return $this;
}
public function getOnline(): ?bool
{
return $this->online;
}
public function setOnline(bool $online): self
{
$this->online = $online;
return $this;
}
public function getViews(): ?int
{
return $this->views;
}
public function setViews(int $views): self
{
$this->views = $views;
return $this;
}
/**
* @return File|null
*/
public function getImageFile(): ?File
{
return $this->imageFile;
}
/**
* @param File|null $imageFile
* @return Directions
* @throws \Exception
*/
public function setImageFile(?File $imageFile): Directions
{
$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 getUser(): ?User
{
return $this->user;
}
public function setUser(?User $user): self
{
$this->user = $user;
return $this;
}
public function getUpdatedBy(): ?User
{
return $this->updatedBy;
}
public function setUpdatedBy(?User $updatedBy): self
{
$this->updatedBy = $updatedBy;
return $this;
}
}