src/Entity/Keyword.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Metadata\ApiResource;
  4. use App\Repository\KeywordRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Symfony\Component\Serializer\Annotation\Groups;
  9. #[ORM\Entity(repositoryClassKeywordRepository::class)]
  10. #[ApiResource]
  11. class Keyword
  12. {
  13.     #[ORM\Id]
  14.     #[ORM\GeneratedValue]
  15.     #[ORM\Column]
  16.     private ?int $id null;
  17.     #[ORM\Column(length255)]
  18.     #[Groups([
  19.         'read:club:collection:getCompanies',
  20.         'read:company:collection:get',
  21.         'write:company:item'
  22.     ])]
  23.     private ?string $name null;
  24.     #[ORM\ManyToMany(targetEntityCompany::class, mappedBy'keywords')]
  25.     private Collection $companies;
  26.     public function __construct()
  27.     {
  28.         $this->companies = new ArrayCollection();
  29.     }
  30.     public function __toString(): string
  31.     {
  32.         return $this->name;
  33.     }
  34.     public function getId(): ?int
  35.     {
  36.         return $this->id;
  37.     }
  38.     public function getName(): ?string
  39.     {
  40.         return $this->name;
  41.     }
  42.     public function setName(string $name): self
  43.     {
  44.         $this->name $name;
  45.         return $this;
  46.     }
  47.     /**
  48.      * @return Collection<int, Company>
  49.      */
  50.     public function getCompanies(): Collection
  51.     {
  52.         return $this->companies;
  53.     }
  54.     public function addCompany(Company $company): self
  55.     {
  56.         if (!$this->companies->contains($company)) {
  57.             $this->companies->add($company);
  58.             $company->addKeyword($this);
  59.         }
  60.         return $this;
  61.     }
  62.     public function removeCompany(Company $company): self
  63.     {
  64.         if ($this->companies->removeElement($company)) {
  65.             $company->removeKeyword($this);
  66.         }
  67.         return $this;
  68.     }
  69. }