src/Entity/VehiclePartKind.php line 28

  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Doctrine\Orm\Filter\BooleanFilter;
  4. use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
  5. use ApiPlatform\Metadata\ApiFilter;
  6. use ApiPlatform\Metadata\ApiResource;
  7. use ApiPlatform\Metadata\Get;
  8. use ApiPlatform\Metadata\GetCollection;
  9. use App\Repository\VehiclePartKindRepository;
  10. use Doctrine\Common\Collections\ArrayCollection;
  11. use Doctrine\Common\Collections\Collection;
  12. use Doctrine\ORM\Mapping as ORM;
  13. use Symfony\Component\Serializer\Annotation\Groups;
  14. #[ApiResource(
  15.     operations: [
  16.         new Get(),
  17.         new GetCollection()
  18.     ],
  19.     normalizationContext: ['groups' => ['part-kind:read']],
  20.     security"is_granted('PUBLIC_ACCESS')"
  21. )]
  22. #[ApiFilter(SearchFilter::class, properties:  [ 'vehicles.category.url' => 'exact' ])]
  23. #[ApiFilter(BooleanFilter::class, properties: ['vehicles.visible' ])]
  24. #[ORM\Entity(repositoryClassVehiclePartKindRepository::class)]
  25. class VehiclePartKind
  26. {
  27.     #[Groups(['vehicle:read''part-kind:read'])]
  28.     #[ORM\Id]
  29.     #[ORM\GeneratedValue]
  30.     #[ORM\Column]
  31.     private ?int $id null;
  32.     #[Groups(['vehicle:read''part-kind:read'])]
  33.     #[ORM\Column(length255)]
  34.     private ?string $name null;
  35.     #[ORM\OneToMany(mappedBy'partKind'targetEntityVehicle::class)]
  36.     private Collection $vehicles;
  37.     public function __construct()
  38.     {
  39.         $this->vehicles = new ArrayCollection();
  40.     }
  41.     public function getId(): ?int
  42.     {
  43.         return $this->id;
  44.     }
  45.     public function getName(): ?string
  46.     {
  47.         return $this->name;
  48.     }
  49.     public function setName(string $name): self
  50.     {
  51.         $this->name $name;
  52.         return $this;
  53.     }
  54.     /**
  55.      * @return Collection<int, Vehicle>
  56.      */
  57.     public function getVehicles(): Collection
  58.     {
  59.         return $this->vehicles;
  60.     }
  61.     public function addVehicle(Vehicle $vehicle): self
  62.     {
  63.         if (!$this->vehicles->contains($vehicle)) {
  64.             $this->vehicles->add($vehicle);
  65.             $vehicle->setPartKind($this);
  66.         }
  67.         return $this;
  68.     }
  69.     public function removeVehicle(Vehicle $vehicle): self
  70.     {
  71.         if ($this->vehicles->removeElement($vehicle)) {
  72.             // set the owning side to null (unless already changed)
  73.             if ($vehicle->getPartKind() === $this) {
  74.                 $vehicle->setPartKind(null);
  75.             }
  76.         }
  77.         return $this;
  78.     }
  79. }