src/Entity/Post.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\PostRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. /**
  8.  * @ORM\Entity(repositoryClass=PostRepository::class)
  9.  */
  10. class Post
  11. {
  12.     /**
  13.      * @ORM\Id
  14.      * @ORM\GeneratedValue
  15.      * @ORM\Column(type="integer")
  16.      */
  17.     private $id;
  18.     /**
  19.      * @ORM\Column(type="string", length=255, nullable=true)
  20.      */
  21.     private $title;
  22.     /**
  23.      * @ORM\Column(type="text", nullable=true)
  24.      */
  25.     private $content;
  26.     /**
  27.      * @ORM\Column(type="datetime", nullable=true)
  28.      */
  29.     private $createdAt;
  30.     /**
  31.      * @ORM\OneToMany(targetEntity=PostImage::class, mappedBy="post", cascade={"persist", "remove"})
  32.      */
  33.     private $postImages;
  34.     /**
  35.      * @ORM\Column(type="string", length=255, nullable=true)
  36.      */
  37.     private $slug;
  38.     public function __construct()
  39.     {
  40.         $this->postImages = new ArrayCollection();
  41.         $this->createdAt = new \DateTime();
  42.     }
  43.     public function getId(): ?int
  44.     {
  45.         return $this->id;
  46.     }
  47.     public function getTitle(): ?string
  48.     {
  49.         return $this->title;
  50.     }
  51.     public function setTitle(?string $title): self
  52.     {
  53.         $this->title $title;
  54.         return $this;
  55.     }
  56.     public function getContent(): ?string
  57.     {
  58.         return $this->content;
  59.     }
  60.     public function setContent(?string $content): self
  61.     {
  62.         $this->content $content;
  63.         return $this;
  64.     }
  65.     public function getCreatedAt(): ?\DateTimeInterface
  66.     {
  67.         return $this->createdAt;
  68.     }
  69.     public function setCreatedAt(?\DateTimeInterface $createdAt): self
  70.     {
  71.         $this->createdAt $createdAt;
  72.         return $this;
  73.     }
  74.     /**
  75.      * @return Collection<int, PostImage>
  76.      */
  77.     public function getPostImages(): Collection
  78.     {
  79.         return $this->postImages;
  80.     }
  81.     public function addPostImage(PostImage $postImage): self
  82.     {
  83.         if (!$this->postImages->contains($postImage)) {
  84.             $this->postImages[] = $postImage;
  85.             $postImage->setPost($this);
  86.         }
  87.         return $this;
  88.     }
  89.     public function removePostImage(PostImage $postImage): self
  90.     {
  91.         if ($this->postImages->removeElement($postImage)) {
  92.             // set the owning side to null (unless already changed)
  93.             if ($postImage->getPost() === $this) {
  94.                 $postImage->setPost(null);
  95.             }
  96.         }
  97.         return $this;
  98.     }
  99.     public function getSlug(): ?string
  100.     {
  101.         return $this->slug;
  102.     }
  103.     public function setSlug(?string $slug): self
  104.     {
  105.         $this->slug $slug;
  106.         return $this;
  107.     }
  108. }