<?php
namespace App\Entity;
use App\Entity\Traits\CommonTrait;
use App\Repository\BlogPostRepository;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\HttpFoundation\File\File;
use Vich\UploaderBundle\Entity\File as EmbeddedFile;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
use Symfony\Component\HttpFoundation\File\UploadedFile;
/**
* @ORM\Entity(repositoryClass=BlogPostRepository::class)
* @ORM\HasLifecycleCallbacks()
* @ORM\Table(name="blog_post")
* @UniqueEntity({"uuid"})
*/
#[Vich\Uploadable]
class BlogPost
{
use CommonTrait;
/**
* @ORM\Column(type="string", length=255)
*/
private $title;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $text;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $author;
/**
* NOTE: This is not a mapped field of entity metadata, just a simple property.
*
*
* @var File|null
*/
#[Vich\UploadableField(mapping: 'blog_main', fileNameProperty: 'mainImageFile.name', size: 'mainImageFile.size', mimeType: 'mainImageFile.mimeType', originalName: 'mainImageFile.originalName', dimensions: 'mainImageFile.dimensions')]
private $mainImage;
/**
* @ORM\Embedded(class="Vich\UploaderBundle\Entity\File")
*
* @var EmbeddedFile
*/
private $mainImageFile;
/**
* NOTE: This is not a mapped field of entity metadata, just a simple property.
*
*
* @var File|null
*/
#[Vich\UploadableField(mapping: 'blog_big', fileNameProperty: 'bigImageFile.name', size: 'bigImageFile.size', mimeType: 'bigImageFile.mimeType', originalName: 'bigImageFile.originalName', dimensions: 'bigImageFile.dimensions')]
private $bigImage;
/**
* @ORM\Embedded(class="Vich\UploaderBundle\Entity\File")
*
* @var EmbeddedFile
*/
private $bigImageFile;
public function __construct()
{
$this->bigImageFile = new EmbeddedFile();
$this->mainImageFile = new EmbeddedFile();
}
public function getTitle(): ?string
{
return $this->title;
}
public function setTitle(string $title): self
{
$this->title = $title;
return $this;
}
public function getText(): ?string
{
return $this->text;
}
public function setText(?string $text): self
{
$this->text = $text;
return $this;
}
public function getAuthor(): ?string
{
return $this->author;
}
public function setAuthor(?string $author): self
{
$this->author = $author;
return $this;
}
public function setMainImage(?File $mainImage = null)
{
$this->mainImage = $mainImage;
if (null !== $mainImage) {
// 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 \DateTimeImmutable();
}
}
public function getMainImage(): ?File
{
return $this->mainImage;
}
public function setMainImageFile(EmbeddedFile $image): void
{
$this->mainImageFile = $image;
}
public function getMainImageFile(): ?EmbeddedFile
{
return $this->mainImageFile;
}
public function setBigImage(?File $bigImage = null)
{
$this->bigImage = $bigImage;
if (null !== $bigImage) {
// 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 \DateTimeImmutable();
}
}
public function getBigImage(): ?File
{
return $this->bigImage;
}
public function setBigImageFile(EmbeddedFile $image): void
{
$this->bigImageFile = $image;
}
public function getBigImageFile(): ?EmbeddedFile
{
return $this->bigImageFile;
}
}