<?php
namespace App\Entity\Blog;
use App\Entity\Blog\Category;
use App\Entity\User;
use App\Repository\Blog\PostRepository;
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 Vich\UploaderBundle\Entity\File as EmbeddedFile;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
/**
* @ORM\Entity(repositoryClass=PostRepository::class)
* @Vich\Uploadable
*/
class Post
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $author;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $title;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $description;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $date;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $link;
/**
* @ORM\Embedded(class="Vich\UploaderBundle\Entity\File")
*
* @var EmbeddedFile
*/
private $image;
/**
* @Vich\UploadableField(mapping="blogs", fileNameProperty="image.name", size="image.size", mimeType="image.mimeType", originalName="image.originalName", dimensions="image.dimensions")
*
* @var File|null
*/
private $imageFile;
/**
* @ORM\Embedded(class="Vich\UploaderBundle\Entity\File")
*
* @var EmbeddedFile
*/
private $authorImage;
/**
* @Vich\UploadableField(mapping="authors", fileNameProperty="authorImage.name", size="authorImage.size", mimeType="authorImage.mimeType", originalName="authorImage.originalName", dimensions="authorImage.dimensions")
*
* @var File|null
*/
private $authorImageFile;
/**
* @ORM\Column(type="datetime")
*/
private $createdAt;
/**
* @ORM\Column(type="datetime")
*/
private $updatedAt;
/**
* @ORM\ManyToOne(targetEntity=User::class, inversedBy="posts")
*/
private $user;
/**
* @ORM\OneToMany(targetEntity=Comment::class, mappedBy="post")
*/
private $comments;
/**
* @ORM\ManyToOne(targetEntity=Category::class, inversedBy="posts")
*/
private $category;
/**
* @ORM\Embedded(class="Vich\UploaderBundle\Entity\File")
*
* @var EmbeddedFile
*/
private $fileDetails;
/**
* @Vich\UploadableField(mapping="blogFiles", fileNameProperty="fileDetails.name", size="fileDetails.size", mimeType="fileDetails.mimeType", originalName="fileDetails.originalName", dimensions="fileDetails.dimensions")
*
* @var File|null
*/
private $file;
public function __construct()
{
$this->image = new EmbeddedFile();
$this->authorImage = new EmbeddedFile();
$this->createdAt = new \DateTimeImmutable();
$this->updatedAt = new \DateTimeImmutable();
$this->comments = new ArrayCollection();
$this->fileDetails = new EmbeddedFile();
}
public function getId(): ?int
{
return $this->id;
}
public function getAuthor(): ?string
{
return $this->author;
}
public function setAuthor(?string $author): self
{
$this->author = $author;
return $this;
}
public function getTitle(): ?string
{
return $this->title;
}
public function setTitle(?string $title): self
{
$this->title = $title;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): self
{
$this->description = $description;
return $this;
}
public function getDate(): ?\DateTimeInterface
{
return $this->date;
}
public function setDate(?\DateTimeInterface $date): self
{
$this->date = $date;
return $this;
}
public function getLink(): ?string
{
return $this->link;
}
public function setLink(?string $link): self
{
$this->link = $link;
return $this;
}
public function getImage(): ?EmbeddedFile
{
return $this->image;
}
public function setImage(?EmbeddedFile $image): void
{
$this->image = $image;
}
public function getImageFile(): ?File
{
return $this->imageFile;
}
/**
* @param File|UploadedFile|null $imageFile
*/
public function setImageFile(?File $imageFile = null): void
{
$this->imageFile = $imageFile;
if (null !== $imageFile) {
$this->updatedAt = new \DateTimeImmutable();
}
}
public function getAuthorImage(): ?EmbeddedFile
{
return $this->authorImage;
}
public function setAuthorImage(?EmbeddedFile $authorImage): void
{
$this->authorImage = $authorImage;
}
public function getAuthorImageFile(): ?File
{
return $this->authorImageFile;
}
/**
* @param File|UploadedFile|null $authorImageFile
*/
public function setAuthorImageFile(?File $authorImageFile = null): void
{
$this->authorImageFile = $authorImageFile;
if (null !== $authorImageFile) {
$this->updatedAt = new \DateTimeImmutable();
}
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->createdAt;
}
public function setCreatedAt(\DateTimeInterface $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getUpdatedAt(): ?\DateTimeInterface
{
return $this->updatedAt;
}
public function setUpdatedAt(\DateTimeInterface $updatedAt): self
{
$this->updatedAt = $updatedAt;
return $this;
}
public function getUser(): ?User
{
return $this->user;
}
public function setUser(?User $user): self
{
$this->user = $user;
return $this;
}
/**
* @return Collection|Comment[]
*/
public function getComments(): Collection
{
return $this->comments;
}
public function addComment(Comment $comment): self
{
if (!$this->comments->contains($comment)) {
$this->comments[] = $comment;
$comment->setPost($this);
}
return $this;
}
public function removeComment(Comment $comment): self
{
if ($this->comments->removeElement($comment)) {
// set the owning side to null (unless already changed)
if ($comment->getPost() === $this) {
$comment->setPost(null);
}
}
return $this;
}
public function getCategory(): ?Category
{
return $this->category;
}
public function setCategory(?Category $category): self
{
$this->category = $category;
return $this;
}
public function getFile(): ?File
{
return $this->file;
}
/**
* @param File|UploadedFile|null $file
*/
public function setFile(?File $file = null): void
{
$this->file = $file;
if (null !== $file) {
$this->updatedAt = new \DateTimeImmutable();
}
}
public function getFileDetails(): ?EmbeddedFile
{
return $this->fileDetails;
}
public function setFileDetails(?EmbeddedFile $fileDetails): void
{
$this->fileDetails = $fileDetails;
}
}