<?php
namespace App\Entity;
use App\Repository\BlogCategoryRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass=BlogCategoryRepository::class)
*/
class BlogCategory
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $name;
/**
* @ORM\OneToMany(targetEntity=BlogPost::class, mappedBy="blogCategory")
*/
private $blogPosts;
public function __construct()
{
$this->blogPosts = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
/**
* @return Collection<int, BlogPost>
*/
public function getBlogPosts(): Collection
{
return $this->blogPosts;
}
public function addBlogPost(BlogPost $blogPost): self
{
if (!$this->blogPosts->contains($blogPost)) {
$this->blogPosts[] = $blogPost;
$blogPost->setBlogCategory($this);
}
return $this;
}
public function removeBlogPost(BlogPost $blogPost): self
{
if ($this->blogPosts->removeElement($blogPost)) {
// set the owning side to null (unless already changed)
if ($blogPost->getBlogCategory() === $this) {
$blogPost->setBlogCategory(null);
}
}
return $this;
}
public function __toString()
{
return strval( $this->getName() );
}
}