src/Entity/Blog.php line 19

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\BlogRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\DBAL\Types\Types;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use App\Entity\Traits\Timestampable;
  9. use Symfony\Component\HttpFoundation\File\File;
  10. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  11. #[ORM\HasLifecycleCallbacks]
  12. #[Vich\Uploadable]
  13. #[ORM\Table(name"blog")]
  14. #[ORM\Index(columns: ["title","content"], name"blog",flags: ['fulltext'])]
  15. #[ORM\Entity(repositoryClassBlogRepository::class)]
  16. class Blog
  17. {
  18.     use Timestampable;
  19.     #[ORM\Id]
  20.     #[ORM\GeneratedValue]
  21.     #[ORM\Column]
  22.     private ?int $id null;
  23.     #[ORM\Column(length255)]
  24.     private ?string $title null;
  25.     #[ORM\Column(typeTypes::TEXT)]
  26.     private ?string $content null;
  27.     /**
  28.      * NOTE: This is not a mapped field of entity metadata, just a simple property.
  29.      *
  30.     */
  31.     #[Vich\UploadableField(mapping'blog_image'fileNameProperty'imageName')]
  32.     private ?File $imageFile null;
  33.     #[ORM\Column(length255nullabletrue)]
  34.     private ?string $imageName null;
  35.     #[ORM\OneToMany(mappedBy'blog'targetEntityComment::class)]
  36.     private Collection $comments;
  37.     #[ORM\Column(length255)]
  38.     private ?string $slug null;
  39.     #[ORM\ManyToOne(inversedBy'blogs'cascade: ["persist"])]
  40.     #[ORM\JoinColumn(nullablefalse)]
  41.     private ?BlogCategory $category null;
  42.     public function __construct()
  43.     {
  44.         $this->comments = new ArrayCollection();
  45.     }
  46.     public function getId(): ?int
  47.     {
  48.         return $this->id;
  49.     }
  50.     public function getTitle(): ?string
  51.     {
  52.         return $this->title;
  53.     }
  54.     public function setTitle(string $title): static
  55.     {
  56.         $this->title $title;
  57.         return $this;
  58.     }
  59.     public function getContent(): ?string
  60.     {
  61.         return $this->content;
  62.     }
  63.     public function setContent(string $content): static
  64.     {
  65.         $this->content $content;
  66.         return $this;
  67.     }
  68.     /**
  69.      * If manually uploading a file (i.e. not using Symfony Form) ensure an instance
  70.      * of 'UploadedFile' is injected into this setter to trigger the update. If this
  71.      * bundle's configuration parameter 'inject_on_load' is set to 'true' this setter
  72.      * must be able to accept an instance of 'File' as the bundle will inject one here
  73.      * during Doctrine hydration.
  74.      *
  75.      * @param File|\Symfony\Component\HttpFoundation\File\UploadedFile|null $imageFile
  76.      */
  77.     public function setImageFile(?File $imageFile null): void
  78.     {
  79.         $this->imageFile $imageFile;
  80.         if (null !== $imageFile) {
  81.             // It is required that at least one field changes if you are using doctrine
  82.             // otherwise the event listeners won't be called and the file is lost
  83.             $this->setUpdatedAt(new \DateTime());
  84.         }
  85.     }
  86.     public function getImageFile(): ?File
  87.     {
  88.         return $this->imageFile;
  89.     }
  90.     public function getImageName(): ?string
  91.     {
  92.         return $this->imageName;
  93.     }
  94.     public function setImageName(?string $imageName): static
  95.     {
  96.         $this->imageName $imageName;
  97.         return $this;
  98.     }
  99.     /**
  100.      * @return Collection<int, Comment>
  101.      */
  102.     public function getComments(): Collection
  103.     {
  104.         return $this->comments;
  105.     }
  106.     public function addComment(Comment $comment): static
  107.     {
  108.         if (!$this->comments->contains($comment)) {
  109.             $this->comments->add($comment);
  110.             $comment->setBlog($this);
  111.         }
  112.         return $this;
  113.     }
  114.     public function removeComment(Comment $comment): static
  115.     {
  116.         if ($this->comments->removeElement($comment)) {
  117.             // set the owning side to null (unless already changed)
  118.             if ($comment->getBlog() === $this) {
  119.                 $comment->setBlog(null);
  120.             }
  121.         }
  122.         return $this;
  123.     }
  124.     public function getSlug(): ?string
  125.     {
  126.         return $this->slug;
  127.     }
  128.     public function setSlug(string $slug): static
  129.     {
  130.         $this->slug $slug;
  131.         return $this;
  132.     }
  133.     public function getCategory(): ?BlogCategory
  134.     {
  135.         return $this->category;
  136.     }
  137.     public function setCategory(?BlogCategory $category): static
  138.     {
  139.         $this->category $category;
  140.         return $this;
  141.     }
  142. }