src/Entity/Blog/Category.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Blog;
  3. use App\Entity\Blog\Post;
  4. use App\Repository\Blog\CategoryRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. /**
  9.  * @ORM\Entity(repositoryClass=CategoryRepository::class)
  10.  */
  11. class Category
  12. {
  13.     /**
  14.      * @ORM\Id
  15.      * @ORM\GeneratedValue
  16.      * @ORM\Column(type="integer")
  17.      */
  18.     private $id;
  19.     /**
  20.      * @ORM\Column(type="string", length=255)
  21.      */
  22.     private $name;
  23.     /**
  24.      * @ORM\Column(type="string", length=255)
  25.      */
  26.     private $slug;
  27.     /**
  28.      * @ORM\OneToMany(targetEntity=Post::class, mappedBy="category")
  29.      */
  30.     private $posts;
  31.     /**
  32.      * @ORM\Column(type="datetime")
  33.      */
  34.     private $createdAt;
  35.     /**
  36.      * @ORM\Column(type="datetime")
  37.      */
  38.     private $updatedAt;
  39.     /**
  40.      * @ORM\Column(type="string", length=255, nullable=true)
  41.      */
  42.     private $nameEng;
  43.     public function __construct()
  44.     {
  45.         $this->posts = new ArrayCollection();
  46.         $this->createdAt = new \DateTimeImmutable();
  47.         $this->updatedAt = new \DateTimeImmutable();
  48.     }
  49.     public function __toString(): string
  50.     {
  51.         return $this->name;
  52.     }
  53.     public function getId(): ?int
  54.     {
  55.         return $this->id;
  56.     }
  57.     public function getName(): ?string
  58.     {
  59.         return $this->name;
  60.     }
  61.     public function setName(string $name): self
  62.     {
  63.         $this->name $name;
  64.         return $this;
  65.     }
  66.     public function getSlug(): ?string
  67.     {
  68.         return $this->slug;
  69.     }
  70.     public function setSlug(string $slug): self
  71.     {
  72.         $this->slug $slug;
  73.         return $this;
  74.     }
  75.     /**
  76.      * @return Collection|Post[]
  77.      */
  78.     public function getPosts(): Collection
  79.     {
  80.         return $this->posts;
  81.     }
  82.     public function addPost(Post $post): self
  83.     {
  84.         if (!$this->posts->contains($post)) {
  85.             $this->posts[] = $post;
  86.             $post->setCategory($this);
  87.         }
  88.         return $this;
  89.     }
  90.     public function removePost(Post $post): self
  91.     {
  92.         if ($this->posts->removeElement($post)) {
  93.             // set the owning side to null (unless already changed)
  94.             if ($post->getCategory() === $this) {
  95.                 $post->setCategory(null);
  96.             }
  97.         }
  98.         return $this;
  99.     }
  100.     public function getCreatedAt(): ?\DateTimeInterface
  101.     {
  102.         return $this->createdAt;
  103.     }
  104.     public function setCreatedAt(\DateTimeInterface $createdAt): self
  105.     {
  106.         $this->createdAt $createdAt;
  107.         return $this;
  108.     }
  109.     public function getUpdatedAt(): ?\DateTimeInterface
  110.     {
  111.         return $this->updatedAt;
  112.     }
  113.     public function setUpdatedAt(\DateTimeInterface $updatedAt): self
  114.     {
  115.         $this->updatedAt $updatedAt;
  116.         return $this;
  117.     }
  118.     public function getNameEng(): ?string
  119.     {
  120.         return $this->nameEng;
  121.     }
  122.     public function setNameEng(?string $nameEng): self
  123.     {
  124.         $this->nameEng $nameEng;
  125.         return $this;
  126.     }
  127. }