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