src/Entity/Blog/Post.php line 20

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Blog;
  3. use App\Entity\Blog\Category;
  4. use App\Entity\User;
  5. use App\Repository\Blog\PostRepository;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use Symfony\Component\HttpFoundation\File\File;
  10. use Symfony\Component\HttpFoundation\File\UploadedFile;
  11. use Vich\UploaderBundle\Entity\File as EmbeddedFile;
  12. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  13. /**
  14.  * @ORM\Entity(repositoryClass=PostRepository::class)
  15.  * @Vich\Uploadable
  16.  */
  17. class Post
  18. {
  19.     /**
  20.      * @ORM\Id
  21.      * @ORM\GeneratedValue
  22.      * @ORM\Column(type="integer")
  23.      */
  24.     private $id;
  25.     /**
  26.      * @ORM\Column(type="string", length=255, nullable=true)
  27.      */
  28.     private $author;
  29.     /**
  30.      * @ORM\Column(type="string", length=255, nullable=true)
  31.      */
  32.     private $title;
  33.     /**
  34.      * @ORM\Column(type="text", nullable=true)
  35.      */
  36.     private $description;
  37.     /**
  38.      * @ORM\Column(type="datetime", nullable=true)
  39.      */
  40.     private $date;
  41.     /**
  42.      * @ORM\Column(type="string", length=255, nullable=true)
  43.      */
  44.     private $link;
  45.     /**
  46.      * @ORM\Embedded(class="Vich\UploaderBundle\Entity\File")
  47.      *
  48.      * @var EmbeddedFile
  49.      */
  50.     private $image;
  51.     /**
  52.      * @Vich\UploadableField(mapping="blogs", fileNameProperty="image.name", size="image.size", mimeType="image.mimeType", originalName="image.originalName", dimensions="image.dimensions")
  53.      * 
  54.      * @var File|null
  55.      */
  56.     private $imageFile;
  57.     /**
  58.      * @ORM\Embedded(class="Vich\UploaderBundle\Entity\File")
  59.      *
  60.      * @var EmbeddedFile
  61.      */
  62.     private $authorImage;
  63.     /**
  64.      * @Vich\UploadableField(mapping="authors", fileNameProperty="authorImage.name", size="authorImage.size", mimeType="authorImage.mimeType", originalName="authorImage.originalName", dimensions="authorImage.dimensions")
  65.      * 
  66.      * @var File|null
  67.      */
  68.     private $authorImageFile;
  69.     /**
  70.      * @ORM\Column(type="datetime")
  71.      */
  72.     private $createdAt;
  73.     /**
  74.      * @ORM\Column(type="datetime")
  75.      */
  76.     private $updatedAt;
  77.     /**
  78.      * @ORM\ManyToOne(targetEntity=User::class, inversedBy="posts")
  79.      */
  80.     private $user;
  81.     /**
  82.      * @ORM\OneToMany(targetEntity=Comment::class, mappedBy="post")
  83.      */
  84.     private $comments;
  85.     /**
  86.      * @ORM\ManyToOne(targetEntity=Category::class, inversedBy="posts")
  87.      */
  88.     private $category;
  89.     /**
  90.      * @ORM\Embedded(class="Vich\UploaderBundle\Entity\File")
  91.      *
  92.      * @var EmbeddedFile
  93.      */
  94.     private $fileDetails;
  95.     /**
  96.      * @Vich\UploadableField(mapping="blogFiles", fileNameProperty="fileDetails.name", size="fileDetails.size", mimeType="fileDetails.mimeType", originalName="fileDetails.originalName", dimensions="fileDetails.dimensions")
  97.      * 
  98.      * @var File|null
  99.      */
  100.     private $file;
  101.     public function __construct()
  102.     {
  103.         $this->image = new EmbeddedFile();
  104.         $this->authorImage = new EmbeddedFile();
  105.         $this->createdAt = new \DateTimeImmutable();
  106.         $this->updatedAt = new \DateTimeImmutable();
  107.         $this->comments = new ArrayCollection();
  108.         $this->fileDetails = new EmbeddedFile();
  109.     }
  110.     public function getId(): ?int
  111.     {
  112.         return $this->id;
  113.     }
  114.     public function getAuthor(): ?string
  115.     {
  116.         return $this->author;
  117.     }
  118.     public function setAuthor(?string $author): self
  119.     {
  120.         $this->author $author;
  121.         return $this;
  122.     }
  123.     public function getTitle(): ?string
  124.     {
  125.         return $this->title;
  126.     }
  127.     public function setTitle(?string $title): self
  128.     {
  129.         $this->title $title;
  130.         return $this;
  131.     }
  132.     public function getDescription(): ?string
  133.     {
  134.         return $this->description;
  135.     }
  136.     public function setDescription(?string $description): self
  137.     {
  138.         $this->description $description;
  139.         return $this;
  140.     }
  141.     public function getDate(): ?\DateTimeInterface
  142.     {
  143.         return $this->date;
  144.     }
  145.     public function setDate(?\DateTimeInterface $date): self
  146.     {
  147.         $this->date $date;
  148.         return $this;
  149.     }
  150.     public function getLink(): ?string
  151.     {
  152.         return $this->link;
  153.     }
  154.     public function setLink(?string $link): self
  155.     {
  156.         $this->link $link;
  157.         return $this;
  158.     }
  159.     public function getImage(): ?EmbeddedFile
  160.     {
  161.         return $this->image;
  162.     }
  163.     public function setImage(?EmbeddedFile $image): void
  164.     {
  165.         $this->image $image;
  166.     }
  167.     public function getImageFile(): ?File
  168.     {
  169.         return $this->imageFile;
  170.     }
  171.     /**
  172.      * @param File|UploadedFile|null $imageFile
  173.      */
  174.     public function setImageFile(?File $imageFile null): void
  175.     {
  176.         $this->imageFile $imageFile;
  177.         if (null !== $imageFile) {
  178.             $this->updatedAt = new \DateTimeImmutable();
  179.         }
  180.     }
  181.     public function getAuthorImage(): ?EmbeddedFile
  182.     {
  183.         return $this->authorImage;
  184.     }
  185.     public function setAuthorImage(?EmbeddedFile $authorImage): void
  186.     {
  187.         $this->authorImage $authorImage;
  188.     }
  189.     public function getAuthorImageFile(): ?File
  190.     {
  191.         return $this->authorImageFile;
  192.     }
  193.     /**
  194.      * @param File|UploadedFile|null $authorImageFile
  195.      */
  196.     public function setAuthorImageFile(?File $authorImageFile null): void
  197.     {
  198.         $this->authorImageFile $authorImageFile;
  199.         if (null !== $authorImageFile) {
  200.             $this->updatedAt = new \DateTimeImmutable();
  201.         }
  202.     }
  203.     public function getCreatedAt(): ?\DateTimeInterface
  204.     {
  205.         return $this->createdAt;
  206.     }
  207.     public function setCreatedAt(\DateTimeInterface $createdAt): self
  208.     {
  209.         $this->createdAt $createdAt;
  210.         return $this;
  211.     }
  212.     public function getUpdatedAt(): ?\DateTimeInterface
  213.     {
  214.         return $this->updatedAt;
  215.     }
  216.     public function setUpdatedAt(\DateTimeInterface $updatedAt): self
  217.     {
  218.         $this->updatedAt $updatedAt;
  219.         return $this;
  220.     }
  221.     public function getUser(): ?User
  222.     {
  223.         return $this->user;
  224.     }
  225.     public function setUser(?User $user): self
  226.     {
  227.         $this->user $user;
  228.         return $this;
  229.     }
  230.     /**
  231.      * @return Collection|Comment[]
  232.      */
  233.     public function getComments(): Collection
  234.     {
  235.         return $this->comments;
  236.     }
  237.     public function addComment(Comment $comment): self
  238.     {
  239.         if (!$this->comments->contains($comment)) {
  240.             $this->comments[] = $comment;
  241.             $comment->setPost($this);
  242.         }
  243.         return $this;
  244.     }
  245.     public function removeComment(Comment $comment): self
  246.     {
  247.         if ($this->comments->removeElement($comment)) {
  248.             // set the owning side to null (unless already changed)
  249.             if ($comment->getPost() === $this) {
  250.                 $comment->setPost(null);
  251.             }
  252.         }
  253.         return $this;
  254.     }
  255.     public function getCategory(): ?Category
  256.     {
  257.         return $this->category;
  258.     }
  259.     public function setCategory(?Category $category): self
  260.     {
  261.         $this->category $category;
  262.         return $this;
  263.     }
  264.     public function getFile(): ?File
  265.     {
  266.         return $this->file;
  267.     }
  268.     /**
  269.      * @param File|UploadedFile|null $file
  270.      */
  271.     public function setFile(?File $file null): void
  272.     {
  273.         $this->file $file;
  274.         if (null !== $file) {
  275.             $this->updatedAt = new \DateTimeImmutable();
  276.         }
  277.     }
  278.     public function getFileDetails(): ?EmbeddedFile
  279.     {
  280.         return $this->fileDetails;
  281.     }
  282.     public function setFileDetails(?EmbeddedFile $fileDetails): void
  283.     {
  284.         $this->fileDetails $fileDetails;
  285.     }
  286. }