<?php
namespace App\Entity;
use App\Repository\BlogAuthorRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\Validator\Constraints as Assert;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
/**
* @ORM\Entity(repositoryClass=BlogAuthorRepository::class)
* @Vich\Uploadable
*/
class BlogAuthor
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=40)
*/
private $firstname;
/**
* @ORM\Column(type="string", length=40)
*/
private $lastname;
/**
* @ORM\Column(type="text")
*/
private $description;
/**
* @var File
* @Assert\Image(
* minWidth = 100,
* maxWidth = 200,
* minHeight = 100,
* maxHeight = 200
* )
* @Vich\UploadableField(mapping="blog_author_image", fileNameProperty="filename")
*/
private $imageFile;
/**
* @var string
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $filename;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $website;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $metaTitle;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $metaDescription;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $metaCustom;
/**
* @ORM\OneToMany(targetEntity="BlogPost", mappedBy="blogAuthor")
* @ORM\OrderBy({"createdAt" = "DESC"})
*/
private $blogPosts;
/**
* @ORM\Column(type="datetime")
*/
private $updatedAt;
public function __construct()
{
$this->blogPosts = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getFirstname(): ?string
{
return $this->firstname;
}
public function setFirstname(string $firstname): self
{
$this->firstname = $firstname;
return $this;
}
public function getLastname(): ?string
{
return $this->lastname;
}
public function setLastname(string $lastname): self
{
$this->lastname = $lastname;
return $this;
}
public function getFullName(): string
{
return ucfirst($this->firstname) . ' ' . ucfirst($this->lastname);
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(string $description): self
{
$this->description = $description;
return $this;
}
public function getWebsite(): ?string
{
return $this->website;
}
public function setWebsite(?string $website): self
{
$this->website = $website;
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 getMetaCustom(): ?string
{
return $this->metaCustom;
}
public function setMetaCustom(?string $metaCustom): self
{
$this->metaCustom = $metaCustom;
return $this;
}
public function getFilename(): ?string
{
return $this->filename;
}
public function setFilename(string $filename=null): self
{
$this->filename = $filename;
return $this;
}
public function setImageFile(?File $imageFile = null)
{
$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 \DateTimeImmutable();
}
}
public function getImageFile()
{
return $this->imageFile;
}
/**
* @return Collection|BlogPost[]
*/
public function getBlogPosts(): Collection
{
return $this->blogPosts;
}
public function addBlogPost(BlogPost $blogPost): self
{
if (!$this->blogPosts->contains($blogPost)) {
$this->blogPosts[] = $blogPost;
$blogPost->setBlogAuthor($this);
}
return $this;
}
public function removeBlogPost(BlogPost $blogPost): self
{
if ($this->blogPosts->contains($blogPost)) {
$this->blogPosts->removeElement($blogPost);
// set the owning side to null (unless already changed)
if ($blogPost->getBlogAuthor() === $this) {
$blogPost->setBlogAuthor(null);
}
}
return $this;
}
public function getUpdatedAt(): ?\DateTimeInterface
{
return $this->updatedAt;
}
public function setUpdatedAt(\DateTimeInterface $updatedAt): self
{
$this->updatedAt = $updatedAt;
return $this;
}
}