<?php
namespace App\Entity;
use App\Repository\PostRepository;
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 Cofondateur\SocleTechniqueBundle\Traits\SortableTrait;
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 Symfony\Component\Validator\Constraints as Assert;
use App\Form\ParagraphFormType;
/**
* @Vich\Uploadable
* @ORM\Entity(repositoryClass=PostRepository::class)
*/
class Post implements SEOInterface, SluggableInterface
{
use SEOTrait;
use SluggableTrait;
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @CrudField(label="Titre", index=true)
*/
private $title;
/**
* @ORM\Column(type="text")
*/
private $resume;
/**
* NOTE: This is not a mapped field of entity metadata, just a simple property.
* @Vich\UploadableField(mapping="default", fileNameProperty="postName", size="postSize")
* @Assert\Expression("this.getPostFile() or this.getPostName()", message = "Veuillez sélectionner un fichier")
* @Assert\File(
* maxSize = "1200k"
* )
* @CrudField(label="Illustration")
* @var File
*/
private $postFile;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*
* @var string
*/
private $postName;
/**
* @ORM\Column(type="integer", nullable=true)
*
* @var integer
*/
private $postSize;
/**
* @ORM\Column(type="datetime", nullable=true)
*
* @var \DateTime
*/
private $postFileUpdatedAt;
/**
* @ORM\Column(type="text", nullable=true)
* @CrudField(label="Introduction", ckeditor=true)
*/
private $intro;
/**
* @ORM\Column(type="boolean", nullable=true)
* @CrudField(label="Mise en avant", index=true)
*/
private $promote;
/**
* @ORM\Column(type="datetime", nullable=true)
* @CrudField(label="Date", index=true)
*/
private $date;
/**
* @ORM\OneToMany(targetEntity=Paragraph::class, mappedBy="post", cascade={"persist", "remove"})
* @CrudField(label="Paragraphes", formType=ParagraphFormType::class, tab="Paragraphes")
*/
private $paragraphs;
public function __construct()
{
$this->paragraphs = new ArrayCollection();
}
public function __toString(): string
{
return $this->getId() ?? "N/A";
}
public function getId(): ?int
{
return $this->id;
}
/**
* If manually uploading a file (i.e. not using Symfony Form) ensure an instance
* of 'UploadedFile' is injected into this setter to trigger the update. If this
* bundle's configuration parameter 'inject_on_load' is set to 'true' this setter
* must be able to accept an instance of 'File' as the bundle will inject one here
* during Doctrine hydration.
*
* @param File|\Symfony\Component\HttpFoundation\File\UploadedFile $image
*/
public function setPostFile(File $image = null)
{
$this->postFile = $image;
if (null !== $image) {
// 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->postFileUpdatedAt = new \DateTimeImmutable();
}
}
public function getPostFile()
{
return $this->postFile;
}
public function getPostName(): ?string
{
return $this->postName;
}
public function setPostName(?string $postName): self
{
$this->postName = $postName;
return $this;
}
public function getPostSize(): ?int
{
return $this->postSize;
}
public function setPostSize(?int $postSize): self
{
$this->postSize = $postSize;
return $this;
}
public function getPostFileUpdatedAt(): ?\DateTimeInterface
{
return $this->postFileUpdatedAt;
}
public function setPostFileUpdatedAt(?\DateTimeInterface $postFileUpdatedAt): self
{
$this->postFileUpdatedAt = $postFileUpdatedAt;
return $this;
}
public function getTitle(): ?string
{
return $this->title;
}
public function setTitle(?string $title): self
{
$this->title = $title;
return $this;
}
public function getIntro(): ?string
{
return $this->intro;
}
public function setIntro(?string $intro): self
{
$this->intro = $intro;
return $this;
}
public function getDate(): ?\DateTimeInterface
{
return $this->date;
}
public function setDate(?\DateTimeInterface $date): self
{
$this->date = $date;
return $this;
}
/**
* @return Collection|Paragraph[]
*/
public function getParagraphs(): Collection
{
return $this->paragraphs;
}
public function addParagraph(Paragraph $paragraph): self
{
if (!$this->paragraphs->contains($paragraph)) {
$this->paragraphs[] = $paragraph;
$paragraph->setPost($this);
}
return $this;
}
public function removeParagraph(Paragraph $paragraph): self
{
if ($this->paragraphs->removeElement($paragraph)) {
// set the owning side to null (unless already changed)
if ($paragraph->getPost() === $this) {
$paragraph->setPost(null);
}
}
return $this;
}
public function isPromote(): ?bool
{
return $this->promote;
}
public function setPromote(?bool $promote): self
{
$this->promote = $promote;
return $this;
}
public function getResume(): ?string
{
return $this->resume;
}
public function setResume(string $resume): self
{
$this->resume = $resume;
return $this;
}
}