src/Entity/VehicleCondition.php line 22

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