src/Entity/BlogKind.php line 12

  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\BlogKindRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Component\String\Slugger\AsciiSlugger;
  8. #[ORM\Entity(repositoryClassBlogKindRepository::class)]
  9. class BlogKind
  10. {
  11.     #[ORM\Id]
  12.     #[ORM\GeneratedValue]
  13.     #[ORM\Column]
  14.     private ?int $id null;
  15.     #[ORM\Column(length255)]
  16.     private ?string $name null;
  17.     #[ORM\Column(length255uniquetrue)]
  18.     private ?string $url null;
  19.     #[ORM\ManyToMany(targetEntityBlog::class, mappedBy'kinds')]
  20.     private Collection $blogs;
  21.     public function __construct()
  22.     {
  23.         $this->blogs = new ArrayCollection();
  24.     }
  25.     public function getId(): ?int
  26.     {
  27.         return $this->id;
  28.     }
  29.     public function getName(): ?string
  30.     {
  31.         return $this->name;
  32.     }
  33.     public function setName(string $name): self
  34.     {
  35.         $this->name $name;
  36.         $this->setUrl();
  37.         return $this;
  38.     }
  39.     public function getUrl(): ?string
  40.     {
  41.         return $this->url;
  42.     }
  43.     public function setUrl(): self
  44.     {
  45.         $slugger = new AsciiSlugger('cs');
  46.         $slug =   $slugger->slug($this->getName(), '-')->lower();
  47.         $this->url $slug->toString();
  48.         return $this;
  49.     }
  50.     /**
  51.      * @return Collection<int, Blog>
  52.      */
  53.     public function getBlogs(): Collection
  54.     {
  55.         return $this->blogs;
  56.     }
  57.     public function addBlog(Blog $blog): self
  58.     {
  59.         if (!$this->blogs->contains($blog)) {
  60.             $this->blogs->add($blog);
  61.             $blog->addKind($this);
  62.         }
  63.         return $this;
  64.     }
  65.     public function removeBlog(Blog $blog): self
  66.     {
  67.         if ($this->blogs->removeElement($blog)) {
  68.             $blog->removeKind($this);
  69.         }
  70.         return $this;
  71.     }
  72. }