<?php
namespace App\Entity\Actualites;
use App\Entity\Common\DatesTrait;
use App\Entity\Common\IdTrait;
use App\Entity\Common\OrdreTrait;
use App\Entity\Common\SlugTrait;
use App\Entity\User;
use DateTimeImmutable;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
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\Actualites\ActualitesRepository")
* @UniqueEntity("name")
* @Vich\Uploadable
*/
class Actualites
{
use IdTrait;
use OrdreTrait;
use DatesTrait;
use SlugTrait;
/**
* @ORM\Column(type="string", length=255)
* @Assert\NotBlank(message="Veuillez saisir le nom pour l'actualité")
*/
private $name;
/**
* @ORM\Column(type="string", length=500, nullable=true)
*/
private $description;
/**
* @ORM\Column(type="text")
* @Assert\NotBlank(message="Veuillez saisir le contenu pour l'actualité")
*/
private $content;
/**
* NOTE: This is not a mapped field of entity metadata, just a simple property.
*
* @Vich\UploadableField(mapping="actualites_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\Column(type="boolean", nullable=true)
*/
private $online;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\User", inversedBy="actualites")
*/
private $user;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Actualites\Categories", inversedBy="actualites")
*/
private $categories;
/**
* @ORM\Column(type="boolean", nullable=true, options={"default": 0})
*/
private $featured;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Actualites\Mediasactualites", mappedBy="actualites")
*/
private $mediasactualites;
/**
* @ORM\Column(type="integer", nullable=true, options={"default": 0})
*/
private $views;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\User", inversedBy="actualitesUpatedBy")
*/
private $updatedBy;
/**
* @ORM\Column(type="string", length=255)
*/
private $published;
/**
* NOTE: This is not a mapped field of entity metadata, just a simple property.
*
* @Vich\UploadableField(mapping="bandeau_actualite", fileNameProperty="bandeaufile")
* @var File|null
* @Assert\Image(
* mimeTypes={"image/jpeg", "image/png"},
*
* maxHeight=230,
* maxWidth=1920,
* maxHeightMessage="Votre image doit faire 230 d'hauteur",
* maxWidthMessage="Votre image doit faire 1920 de largeur"
* )
*/
private $imageBandeauFile;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $bandeaufile;
public function __construct()
{
$this->mediasactualites = new ArrayCollection();
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): self
{
$this->description = $description;
return $this;
}
public function getContent(): ?string
{
return $this->content;
}
public function setContent(string $content): self
{
$this->content = $content;
return $this;
}
/**
* @return File|null
*/
public function getImageFile(): ?File
{
return $this->imageFile;
}
/**
* @param File|null $imageFile
* @return Actualites
* @throws \Exception
*/
public function setImageFile(?File $imageFile): Actualites
{
$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 getOnline(): ?bool
{
return $this->online;
}
public function setOnline(?bool $online): self
{
$this->online = $online;
return $this;
}
public function getUser(): ?User
{
return $this->user;
}
public function setUser(?User $user): self
{
$this->user = $user;
return $this;
}
public function getCategories(): ?Categories
{
return $this->categories;
}
public function setCategories(?Categories $categories): self
{
$this->categories = $categories;
return $this;
}
public function __toString()
{
return $this->name;
}
public function getFeatured(): ?bool
{
return $this->featured;
}
public function setFeatured(?bool $featured): self
{
$this->featured = $featured;
return $this;
}
/**
* @return Collection|Mediasactualites[]
*/
public function getMediasactualites(): Collection
{
return $this->mediasactualites;
}
public function addMediasactuality(Mediasactualites $mediasactuality): self
{
if (!$this->mediasactualites->contains($mediasactuality)) {
$this->mediasactualites[] = $mediasactuality;
$mediasactuality->setActualites($this);
}
return $this;
}
public function removeMediasactuality(Mediasactualites $mediasactuality): self
{
if ($this->mediasactualites->contains($mediasactuality)) {
$this->mediasactualites->removeElement($mediasactuality);
// set the owning side to null (unless already changed)
if ($mediasactuality->getActualites() === $this) {
$mediasactuality->setActualites(null);
}
}
return $this;
}
public function getViews(): ?int
{
return $this->views;
}
public function setViews(int $views): self
{
$this->views = $views;
return $this;
}
public function getUpdatedBy(): ?User
{
return $this->updatedBy;
}
public function setUpdatedBy(?User $updatedBy): self
{
$this->updatedBy = $updatedBy;
return $this;
}
public function getPublished(): ?string
{
return $this->published;
}
public function setPublished(string $published): self
{
$this->published = $published;
return $this;
}
/**
* @return File|null
*/
public function getImageBandeauFile(): ?File
{
return $this->imageBandeauFile;
}
/**
* @param File|null $imageBandeauFile
* @return Actualites
*/
public function setImageBandeauFile(?File $imageBandeauFile): Actualites
{
$this->imageBandeauFile = $imageBandeauFile;
if ($this->imageBandeauFile 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 \DateTime('now');
}
return $this;
}
public function getBandeaufile(): ?string
{
return $this->bandeaufile;
}
public function setBandeaufile(?string $bandeaufile): self
{
$this->bandeaufile = $bandeaufile;
return $this;
}
}