src/Entity/BlogPost.php line 16

  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\BlogPostRepository;
  4. use Doctrine\DBAL\Types\Types;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Symfony\Component\HttpFoundation\File\File;
  8. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  9. use Doctrine\ORM\Mapping as ORM;
  10. #[ORM\Entity(repositoryClassBlogPostRepository::class)]
  11. #[Vich\Uploadable]
  12. class BlogPost
  13. {
  14.     #[ORM\Id]
  15.     #[ORM\GeneratedValue]
  16.     #[ORM\Column]
  17.     private ?int $id null;
  18.     #[ORM\Column(length255)]
  19.     private ?string $titleblog null;
  20.     #[Vich\UploadableField(mapping'recipe_images'fileNameProperty'imageName')]
  21.     private ?File $imageFile null;
  22.     #[ORM\Column(nullabletrue)]
  23.     private ?string $imageName null;
  24.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  25.     private ?string $content null;
  26.     #[ORM\Column]
  27.     private ?\DateTimeImmutable $createdAt null;
  28.     #[ORM\Column(nullabletrue)]
  29.     private ?\DateTimeImmutable $publishedAt null;
  30.     #[ORM\Column(nullabletrue)]
  31.     private ?\DateTimeImmutable $updatedAt null;
  32.     #[ORM\Column]
  33.     private ?bool $isValid null;
  34.     #[ORM\Column]
  35.     private ?bool $deleted null;
  36.     #[ORM\Column(length50)]
  37.     private ?string $status null;
  38.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  39.     private $comment;
  40.     #[ORM\Column(length255)]
  41.     private ?string $slug null;
  42.     #[ORM\ManyToMany(targetEntityCategory::class, inversedBy'blogPosts')]
  43.     private Collection $categories;
  44.     public function __construct()
  45.     {
  46.         $this->categories = new ArrayCollection();
  47.         $this->createdAt = new \DateTimeImmutable();
  48.     }
  49.     public function getComment(): ?string
  50.     {
  51.         return $this->comment;
  52.     }
  53.     public function setComment(?string $comment): self
  54.     {
  55.         $this->comment $comment;
  56.         return $this;
  57.     }
  58.     public function getSlug(): ?string
  59.     {
  60.         return $this->slug;
  61.     }
  62.     public function setSlug(string $slug): self
  63.     {
  64.         $this->slug $slug;
  65.         return $this;
  66.     }
  67.     public function getId(): ?int
  68.     {
  69.         return $this->id;
  70.     }
  71.     public function getTitleBlog(): ?string
  72.     {
  73.         return $this->titleblog;
  74.     }
  75.     public function setTitleBlog(string $titleblog): self
  76.     {
  77.         $this->titleblog $titleblog;
  78.         return $this;
  79.     }
  80.     public function getContent(): ?string
  81.     {
  82.         return $this->content;
  83.     }
  84.     public function setContent(?string $content): self
  85.     {
  86.         $this->content $content;
  87.         $this->updatedAt = new \DateTimeImmutable();
  88.         return $this;
  89.     }
  90.     public function getCreatedAt(): ?\DateTimeImmutable
  91.     {
  92.         return $this->createdAt;
  93.     }
  94.     public function setCreatedAt(\DateTimeImmutable $createdAt): self
  95.     {
  96.         $this->createdAt $createdAt;
  97.         return $this;
  98.     }
  99.     public function getPublishedAt(): ?\DateTimeImmutable
  100.     {
  101.         return $this->publishedAt;
  102.     }
  103.     public function setPublishedAt(?\DateTimeImmutable $publishedAt): self
  104.     {
  105.         $this->publishedAt $publishedAt;
  106.         $this->updatedAt = new \DateTimeImmutable();
  107.         return $this;
  108.     }
  109.     public function getUpdatedAt(): ?\DateTimeImmutable
  110.     {
  111.         return $this->updatedAt;
  112.     }
  113.     public function setUpdatedAt(?\DateTimeImmutable $updatedAt): self
  114.     {
  115.         $this->updatedAt $updatedAt;
  116.         return $this;
  117.     }
  118.     public function isValid(): ?bool
  119.     {
  120.         return $this->isValid;
  121.     }
  122.     public function setIsValid(bool $isValid): self
  123.     {
  124.         $this->isValid $isValid;
  125.         $this->updatedAt = new \DateTimeImmutable();
  126.         return $this;
  127.     }
  128.     public function isDeleted(): ?bool
  129.     {
  130.         return $this->deleted;
  131.     }
  132.     public function setDeleted(bool $deleted): self
  133.     {
  134.         $this->deleted $deleted;
  135.         $this->updatedAt = new \DateTimeImmutable();
  136.         return $this;
  137.     }
  138.     public function getStatus(): ?string
  139.     {
  140.         return $this->status;
  141.     }
  142.     public function setStatus(string $status): self
  143.     {
  144.         $this->status $status;
  145.         $this->updatedAt = new \DateTimeImmutable();
  146.         return $this;
  147.     }
  148.     /**
  149.      * @return Collection<int, Category>
  150.      */
  151.     public function getCategories(): Collection
  152.     {
  153.         return $this->categories;
  154.     }
  155.     public function addCategory(Category $category): self
  156.     {
  157.         if (!$this->categories->contains($category)) {
  158.             $this->categories->add($category);
  159.             $this->updatedAt = new \DateTimeImmutable();
  160.         }
  161.         return $this;
  162.     }
  163.     public function removeCategory(Category $category): self
  164.     {
  165.         $this->categories->removeElement($category);
  166.         $this->updatedAt = new \DateTimeImmutable();
  167.         return $this;
  168.     }
  169.       /**
  170.      * If manually uploading a file (i.e. not using Symfony Form) ensure an instance
  171.      * of 'UploadedFile' is injected into this setter to trigger the update. If this
  172.      * bundle's configuration parameter 'inject_on_load' is set to 'true' this setter
  173.      * must be able to accept an instance of 'File' as the bundle will inject one here
  174.      * during Doctrine hydration.
  175.      *
  176.      * @param File|\Symfony\Component\HttpFoundation\File\UploadedFile|null $imageFile
  177.      */
  178.     public function setImageFile(?File $imageFile null): void
  179.     {
  180.         $this->imageFile $imageFile;
  181.         if (null !== $imageFile) {
  182.             // It is required that at least one field changes if you are using doctrine
  183.             // otherwise the event listeners won't be called and the file is lost
  184.             $this->updatedAt = new \DateTimeImmutable();
  185.         }
  186.     }
  187.     public function getImageFile(): ?File
  188.     {
  189.         return $this->imageFile;
  190.     }
  191.     public function setImageName(?string $imageName): void
  192.     {
  193.         $this->imageName $imageName;
  194.     }
  195.     public function getImageName(): ?string
  196.     {
  197.         return $this->imageName;
  198.     }
  199.     
  200. }