<?php
namespace App\Entity;
use App\Entity\Traits\QuoteTrait;
use App\Repository\ActualityRepository;
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 Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\HttpFoundation\File\File;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
use Vich\UploaderBundle\Mapping\Annotation\Uploadable;
use App\Form\ActualityBlocFormType;
/**
* @ORM\Entity(repositoryClass=ActualityRepository::class)
* @Uploadable()
*/
class Actuality implements SEOInterface, SluggableInterface
{
use SEOTrait;
use QuoteTrait;
use SluggableTrait;
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @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 du visuel principal")
*/
private $coverAlt;
/**
* @ORM\Column(type="string", length=255)
* @CrudField(index=true, label="Titre")
*/
private $title;
/**
* @ORM\Column(type="text")
* @CrudField(label="Résumé sur les autres pages")
*/
private $resume;
/**
* @ORM\ManyToOne(targetEntity=ActualityCategory::class, inversedBy="actualities")
* @ORM\JoinColumn(nullable=false)
* @CrudField(label="Catégorie", index=true)
*/
private $category;
/**
* @ORM\OneToMany(targetEntity=ActualityBloc::class, mappedBy="actuality", orphanRemoval=true, cascade={"persist", "remove"})
* @CrudField(label="Paragraphes", formType=ActualityBlocFormType::class, tab="Paragraphes")
*/
private $paragraphs;
/**
* @Vich\UploadableField(mapping="default", fileNameProperty="quoteCoverName", size="quoteCoverSize")
* @CrudField(tab="Citation", label="Visuel de fond")
*/
private $quoteCoverFile;
/**
* @ORM\Column(type="date")
* @CrudField(label="Date")
*/
private $date;
/**
* @ORM\Column(type="boolean")
* @CrudField(index=true, label="Publié")
*/
private $published;
public function __construct()
{
$this->paragraphs = new ArrayCollection();
$this->date = new \DateTime();
}
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 getResume(): ?string
{
return $this->resume;
}
public function setResume(string $resume): self
{
$this->resume = $resume;
return $this;
}
public function getCategory(): ?ActualityCategory
{
return $this->category;
}
public function setCategory(?ActualityCategory $category): self
{
$this->category = $category;
return $this;
}
/**
* @return Collection<int, ActualityBloc>
*/
public function getParagraphs(): Collection
{
return $this->paragraphs;
}
public function addParagraph(ActualityBloc $paragraph): self
{
if (!$this->paragraphs->contains($paragraph)) {
$this->paragraphs[] = $paragraph;
$paragraph->setActuality($this);
}
return $this;
}
public function removeParagraph(ActualityBloc $paragraph): self
{
if ($this->paragraphs->removeElement($paragraph)) {
// set the owning side to null (unless already changed)
if ($paragraph->getActuality() === $this) {
$paragraph->setActuality(null);
}
}
return $this;
}
public function getDate(): ?\DateTimeInterface
{
return $this->date;
}
public function getDateFormated(): ?string
{
// Vérifiez si la date est définie
if ($this->date instanceof \DateTimeInterface) {
// Utilisez la méthode format pour obtenir la date au format souhaité
return $this->date->format('d/m/Y');
}
return null;
}
public function setDate(\DateTimeInterface $date): self
{
$this->date = $date;
return $this;
}
public function isPublished(): ?bool
{
return $this->published;
}
public function setPublished(bool $published): self
{
$this->published = $published;
return $this;
}
}