<?php
namespace App\Entity;
use App\Repository\PostRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Symfony\Component\HttpFoundation\File\File;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @Vich\Uploadable
* @ORM\Entity(repositoryClass=PostRepository::class)
*/
class Post
{
public function __toString()
{
return "#" . $this->id . " " . $this->getTitle();
}
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $title;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $intro;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $date;
/**
* @ORM\OneToMany(targetEntity=Paragraph::class, mappedBy="post")
*/
private $paragraphs;
/**
* NOTE: This is not a mapped field of entity metadata, just a simple property.
* @Vich\UploadableField(mapping="post", fileNameProperty="postFileName", size="postFileSize")
* @Assert\Expression("this.getPostFile() or this.getPostFileName()", message = "Veuillez sélectionner un fichier")
* @Assert\File(
* maxSize = "1200k"
* )
*
* @var File
*/
private $postFile;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*
* @var string
*/
private $postFileName;
/**
* @ORM\Column(type="integer", nullable=true)
*
* @var integer
*/
private $postFileSize;
/**
* @ORM\Column(type="datetime", nullable=true)
*
* @var \DateTime
*/
private $postFileUpdatedAt;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $metaTitle;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $metaDescription;
/**
* @Gedmo\Slug(fields={"title"})
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $slug;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $isPublished;
/**
* 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 getPostFileName(): ?string
{
return $this->postFileName;
}
public function setPostFileName(?string $postFileName): self
{
$this->postFileName = $postFileName;
return $this;
}
public function getPostFileSize(): ?int
{
return $this->postFileSize;
}
public function setPostFileSize(?int $postFileSize): self
{
$this->postFileSize = $postFileSize;
return $this;
}
public function getPostFileUpdatedAt(): ?\DateTimeInterface
{
return $this->postFileUpdatedAt;
}
public function setPostFileUpdatedAt(?\DateTimeInterface $postFileUpdatedAt): self
{
$this->postFileUpdatedAt = $postFileUpdatedAt;
return $this;
}
public function __construct()
{
$this->paragraphs = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
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 getMetaTitle(): ?string
{
return $this->metaTitle;
}
public function setMetaTitle(?string $metaTitle): self
{
$this->metaTitle = $metaTitle;
return $this;
}
public function getMetaDescription(): ?string
{
return $this->metaDescription;
}
public function setMetaDescription(?string $metaDescription): self
{
$this->metaDescription = $metaDescription;
return $this;
}
public function getSlug(): ?string
{
return $this->slug;
}
public function setSlug(?string $slug): self
{
$this->slug = $slug;
return $this;
}
public function getIsPublished(): ?bool
{
return $this->isPublished;
}
public function setIsPublished(?bool $isPublished): self
{
$this->isPublished = $isPublished;
return $this;
}
}