<?php
namespace App\Entity;
use App\Repository\ActualiteRepository;
use Cofondateur\SocleTechniqueBundle\Annotation\CrudField;
use Cofondateur\SocleTechniqueBundle\Traits\SEOInterface;
use Cofondateur\SocleTechniqueBundle\Traits\SEOTrait;
use Cofondateur\SocleTechniqueBundle\Traits\SluggableInterface;
use Cofondateur\SocleTechniqueBundle\Traits\SluggableTrait;
use DateTime;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\Validator\Constraints\Date;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
use Vich\UploaderBundle\Mapping\Annotation\Uploadable;
use App\Form\ActualiteParagraphFormType;
use App\Form\ActualiteHashtagFormType;
use App\Form\ActualiteGalleriePhotoFormType;
use App\Form\ActualiteGallerieVideoFormType;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity(repositoryClass=ActualiteRepository::class)
* @UniqueEntity(
* fields={"slug"},
* errorPath="slug",
* message="Ce slug est déjà utilisé pour une autre actualité"
* )
* @Uploadable()
*/
class Actualite implements SEOInterface, SluggableInterface
{
use SEOTrait;
use SluggableTrait;
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
* @CrudField(index=true, label="Titre")
*/
private $title;
/**
* @ORM\ManyToOne(targetEntity=CategoryActualite::class, inversedBy="actualites")
* @ORM\JoinColumn(nullable=false)
* @CrudField(label="Catégorie de l'actualité")
*/
private $category;
/**
* @ORM\ManyToMany(targetEntity=ActualiteHashtag::class, mappedBy="actualite", cascade={"persist", "remove"})
* @CrudField(label="Hashtags")
*/
private $hashtags;
/**
* @ORM\Column(type="date")
* @CrudField(label="Date")
*/
private $createdAt;
/**
* @ORM\Column(type="string")
*/
private $coverName;
/**
* @ORM\Column(type="integer")
*/
private $coverSize;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $coverUpdatedAt;
/**
* @Vich\UploadableField(mapping="default", fileNameProperty="coverName", size="coverSize")
* @CrudField(label="Visuel principal (bandeau top)")
*/
private $coverFile;
/**
* @ORM\Column(type="string", nullable=true)
* @CrudField(label="Alt")
*/
private $coverAlt;
/**
* @ORM\Column(type="text")
* @CrudField(label="Résumé sur les autres pages")
*/
private $resumeOtherPage;
/**
* @ORM\Column(type="text", nullable=true)
* @CrudField(label="Résumé sur la page")
*/
private $resumeOnPage;
/**
* @ORM\OneToMany(targetEntity=ActualiteParagraph::class, mappedBy="actualite", cascade={"persist", "remove"})
* @CrudField(label="Paragraphes", formType=ActualiteParagraphFormType::class, tab="Paragraphes")
*/
private $paragraphs;
/**
* @ORM\OneToMany(targetEntity=ActualiteGalleriePhoto::class, mappedBy="actualite", cascade={"persist", "remove"})
* @ORM\OrderBy({"position" = "ASC"})
* @CrudField(label="Photos de la galerie", formType=ActualiteGalleriePhotoFormType::class, tab="Galerie")
*/
private $galeriePhotos;
/**
* @ORM\OneToMany(targetEntity=ActualiteGallerieVideo::class, mappedBy="actualite", cascade={"persist", "remove"})
* @ORM\OrderBy({"position" = "ASC"})
* @CrudField(label="Videos de la galerie", formType=ActualiteGallerieVideoFormType::class, tab="Galerie")
*/
private $galerieVideos;
/**
* @ORM\ManyToMany(targetEntity=ReferencePublic::class, inversedBy="actualites")
* @CrudField(label="Références publiques", tab="Références")
*/
private $referencesPublic;
/**
* @ORM\ManyToMany(targetEntity=ReferencePrive::class, inversedBy="actualites")
* @CrudField(label="Références privées", tab="Références")
*/
private $referencesPrive;
/**
* @ORM\Column(type="boolean", nullable=true)
* @CrudField(label="Affiché sur le site", index=true)
*/
private $published;
public function __construct() {
$this->createdAt = new DateTime();
$this->paragraphs = new ArrayCollection();
$this->hashtags = new ArrayCollection();
$this->galeriePhotos = new ArrayCollection();
$this->galerieVideos = new ArrayCollection();
$this->referencesPublic = new ArrayCollection();
$this->referencesPrive = new ArrayCollection();
}
public function __toString(): string
{
return $this->getId() ?? "N/A";
}
public function getId(): ?int
{
return $this->id;
}
public function getCoverName(): ?string
{
return $this->coverName;
}
public function setCoverName(?string $coverName): self
{
$this->coverName = $coverName;
return $this;
}
public function getCoverSize(): ?int
{
return $this->coverSize;
}
public function setCoverSize(?int $coverSize): self
{
$this->coverSize = $coverSize;
return $this;
}
public function getCoverUpdatedAt(): ?\DateTimeInterface
{
return $this->coverUpdatedAt;
}
public function setCoverUpdatedAt(?\DateTimeInterface $coverUpdatedAt): self
{
$this->coverUpdatedAt = $coverUpdatedAt;
return $this;
}
public function getCoverFile(): ?File
{
return $this->coverFile;
}
public function setCoverFile(?File $coverFile): self
{
$this->coverFile = $coverFile;
if (null !== $this->coverFile) {
$this->coverUpdatedAt = new \DateTimeImmutable();
}
return $this;
}
public function getCoverAlt(): ?string
{
return $this->coverAlt;
}
public function setCoverAlt(?string $coverAlt): self
{
$this->coverAlt = $coverAlt;
return $this;
}
public function getTitle(): ?string
{
return $this->title;
}
public function setTitle(string $title): self
{
$this->title = $title;
return $this;
}
public function getCategory(): ?CategoryActualite
{
return $this->category;
}
public function setCategory(?CategoryActualite $category): self
{
$this->category = $category;
return $this;
}
public function getResumeOnPage(): ?string
{
return $this->resumeOnPage;
}
public function setResumeOnPage(?string $resumeOnPage): self
{
$this->resumeOnPage = $resumeOnPage;
return $this;
}
public function getResumeOtherPage(): ?string
{
return $this->resumeOtherPage;
}
public function setResumeOtherPage(string $resumeOtherPage): self
{
$this->resumeOtherPage = $resumeOtherPage;
return $this;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->createdAt;
}
public function setCreatedAt(\DateTimeInterface $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
/**
* @return Collection<int, ActualiteParagraph>
*/
public function getParagraphs(): Collection
{
return $this->paragraphs;
}
public function addParagraph(ActualiteParagraph $paragraph): self
{
if (!$this->paragraphs->contains($paragraph)) {
$this->paragraphs[] = $paragraph;
$paragraph->setActualite($this);
}
return $this;
}
public function removeParagraph(ActualiteParagraph $paragraph): self
{
if ($this->paragraphs->removeElement($paragraph)) {
// set the owning side to null (unless already changed)
if ($paragraph->getActualite() === $this) {
$paragraph->setActualite(null);
}
}
return $this;
}
/**
* @return Collection<int, ActualiteHashtag>
*/
public function getHashtags(): Collection
{
return $this->hashtags;
}
public function addHashtag(ActualiteHashtag $hashtag): self
{
if (!$this->hashtags->contains($hashtag)) {
$this->hashtags[] = $hashtag;
$hashtag->addActualite($this);
}
return $this;
}
public function removeHashtag(ActualiteHashtag $hashtag): self
{
if ($this->hashtags->removeElement($hashtag)) {
$hashtag->removeActualite($this);
}
return $this;
}
/**
* @return Collection<int, ActualiteGalleriePhoto>
*/
public function getGaleriePhotos(): Collection
{
return $this->galeriePhotos;
}
public function addGaleriePhoto(ActualiteGalleriePhoto $galeriePhoto): self
{
if (!$this->galeriePhotos->contains($galeriePhoto)) {
$this->galeriePhotos[] = $galeriePhoto;
$galeriePhoto->setActualite($this);
}
return $this;
}
public function removeGaleriePhoto(ActualiteGalleriePhoto $galeriePhoto): self
{
if ($this->galeriePhotos->removeElement($galeriePhoto)) {
// set the owning side to null (unless already changed)
if ($galeriePhoto->getActualite() === $this) {
$galeriePhoto->setActualite(null);
}
}
return $this;
}
/**
* @return Collection<int, ActualiteGallerieVideo>
*/
public function getGalerieVideos(): Collection
{
return $this->galerieVideos;
}
public function addGalerieVideo(ActualiteGallerieVideo $galerieVideo): self
{
if (!$this->galerieVideos->contains($galerieVideo)) {
$this->galerieVideos[] = $galerieVideo;
$galerieVideo->setActualite($this);
}
return $this;
}
public function removeGalerieVideo(ActualiteGallerieVideo $galerieVideo): self
{
if ($this->galerieVideos->removeElement($galerieVideo)) {
// set the owning side to null (unless already changed)
if ($galerieVideo->getActualite() === $this) {
$galerieVideo->setActualite(null);
}
}
return $this;
}
/**
* @return Collection<int, ReferencePublic>
*/
public function getReferencesPublic(): Collection
{
return $this->referencesPublic;
}
public function addReferencesPublic(ReferencePublic $referencesPublic): self
{
if (!$this->referencesPublic->contains($referencesPublic)) {
$this->referencesPublic[] = $referencesPublic;
}
return $this;
}
public function removeReferencesPublic(ReferencePublic $referencesPublic): self
{
$this->referencesPublic->removeElement($referencesPublic);
return $this;
}
/**
* @return Collection<int, ReferencePrive>
*/
public function getReferencesPrive(): Collection
{
return $this->referencesPrive;
}
public function addReferencesPrive(ReferencePrive $referencesPrive): self
{
if (!$this->referencesPrive->contains($referencesPrive)) {
$this->referencesPrive[] = $referencesPrive;
}
return $this;
}
public function removeReferencesPrive(ReferencePrive $referencesPrive): self
{
$this->referencesPrive->removeElement($referencesPrive);
return $this;
}
public function isPublished(): ?bool
{
return $this->published;
}
public function setPublished(?bool $published): self
{
$this->published = $published;
return $this;
}
}