<?php
namespace App\Entity;
use App\Repository\BlogRepository;
use App\Traits\DateTrait;
use DateTime;
use Doctrine\ORM\Mapping as ORM;
use JMS\Serializer\Annotation as Serializer;
use JMS\Serializer\Annotation\Expose;
use JMS\Serializer\Annotation\Groups;
use Symfony\Component\HttpFoundation\File\File;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
/**
* @ORM\Entity(repositoryClass=BlogRepository::class)
*
* @Vich\Uploadable
*
* @ORM\HasLifecycleCallbacks()
* @Serializer\ExclusionPolicy("ALL")
*/
class Blog
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*
* @Expose
* @Groups({"blog_post_list", "blog"})
*
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*
* @Expose
* @Groups({"blog_post_list", "blog"})
*/
private $title;
/**
* @ORM\Column(type="string", length=255)
*/
private $slug;
/**
* @ORM\Column(type="text")
*/
private $body;
/**
* @ORM\Column(type="boolean", options={"default":false})
*
* @Expose
* @Groups({"blog_post_list", "blog"})
*/
private $published = TRUE;
/**
* @ORM\Column(type="string", length=255)
*
* @Expose
* @Groups({"blog_post_list", "blog"})
*/
private $article;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $image;
// Vich Uploader
/**
* @Vich\UploadableField(mapping="blog_post_image", fileNameProperty="image")
*/
private ?File $imageFile = NULL;
/**
* @ORM\Column(type="string", length=255)
*/
private $imgSize;
use DateTrait;
/*
* ============================================================================================
* =============================== FONCTIONS CUSTOM ===========================================
* ============================================================================================
*/
/**
* @ORM\PrePersist()
* @ORM\PreUpdate()
*/
public function prePersist()
{
// $slugifier = new Slugify();
// $this->slug = $slugifier->slugify($this->title);
$this->slug = md5(uniqid());
}
public function getId(): ?int
{
return $this->id;
}
/*
* ============================================================================================
* ============================== FIN FONCTIONS CUSTOM ========================================
* ============================================================================================
*/
public function getTitle(): ?string
{
return $this->title;
}
public function setTitle(string $title): self
{
$this->title = $title;
return $this;
}
public function getSlug(): ?string
{
return $this->slug;
}
public function setSlug(string $slug): self
{
$this->slug = $slug;
return $this;
}
public function setArticle(string $article): self
{
$this->article = $article;
return $this;
}
public function getArticle(): ?string
{
return $this->article;
}
public function getBody(): ?string
{
return $this->body;
}
public function setBody(string $body): self
{
$this->body = $body;
return $this;
}
public function getPublished(): ?bool
{
return $this->published;
}
public function setPublished(bool $published): self
{
$this->published = $published;
return $this;
}
public function getImage(): ?string
{
return $this->image ?? NULL;
}
public function setImage(?string $image): self
{
$this->image = $image;
return $this;
}
public function getImageFile(): ?File
{
return $this->imageFile;
}
/**
* @param File $imageFile
*
* @return void
*/
public function setImageFile(File $imageFile): void
{
$this->imageFile = $imageFile;
if (NULL !== $imageFile) {
// 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();
}
}
public function setImgSize(string $imgSize): self
{
$this->imgSize = $imgSize;
return $this;
}
public function getImgSize(): ?string
{
return $this->imgSize;
}
}