src/Entity/PwStreet.php line 21

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Metadata\ApiResource;
  4. use App\Repository\PwStreetRepository;
  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. use ApiPlatform\Metadata\ApiFilter;
  10. use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
  11. #[ORM\Entity(repositoryClassPwStreetRepository::class)]
  12. #[ApiResource(
  13.     normalizationContext: ['groups' => ['PwStreet:read']],
  14.     denormalizationContext: ['groups' => ['PwStreet:write']],
  15. )]
  16. #[ApiFilter(SearchFilter::class, properties: ['name' => 'ipartial''city.id' => 'exact'])]
  17. class PwStreet
  18. {
  19.     #[ORM\Id]
  20.     #[ORM\GeneratedValue(strategy'IDENTITY')]
  21.     #[ORM\Column]
  22.     #[Groups(['PwAccident:read''PwAccident:write''PwStreet:read'])]
  23.     private ?int $id null;
  24.     #[ORM\ManyToOne(inversedBy'pwStreets')]
  25.     #[Groups(['PwAccident:read''PwAccident:write''PwStreet:read'])]
  26.     private ?PwCity $city null;
  27.     #[ORM\Column(length255)]
  28.     #[Groups(['PwAccident:read''PwAccident:write''PwStreet:read'])]
  29.     private ?string $name null;
  30.     #[ORM\OneToMany(mappedBy'street'targetEntityPwAccident::class)]
  31.     private Collection $pwAccidents;
  32.     #[ORM\OneToMany(mappedBy'street'targetEntityPwAccount::class)]
  33.     private Collection $accounts;
  34.     public function __construct()
  35.     {
  36.         $this->pwAccidents = new ArrayCollection();
  37.         $this->accounts = new ArrayCollection();
  38.     }
  39.     public function getId(): ?int
  40.     {
  41.         return $this->id;
  42.     }
  43.     public function getCity(): ?PwCity
  44.     {
  45.         return $this->city;
  46.     }
  47.     public function setCity(?PwCity $city): static
  48.     {
  49.         $this->city $city;
  50.         return $this;
  51.     }
  52.     public function getName(): ?string
  53.     {
  54.         return $this->name;
  55.     }
  56.     public function setName(string $name): static
  57.     {
  58.         $this->name $name;
  59.         return $this;
  60.     }
  61.     /**
  62.      * @return Collection<int, PwAccident>
  63.      */
  64.     public function getPwAccidents(): Collection
  65.     {
  66.         return $this->pwAccidents;
  67.     }
  68.     public function addPwAccident(PwAccident $pwAccident): static
  69.     {
  70.         if (!$this->pwAccidents->contains($pwAccident)) {
  71.             $this->pwAccidents->add($pwAccident);
  72.             $pwAccident->setStreet($this);
  73.         }
  74.         return $this;
  75.     }
  76.     public function removePwAccident(PwAccident $pwAccident): static
  77.     {
  78.         if ($this->pwAccidents->removeElement($pwAccident)) {
  79.             // set the owning side to null (unless already changed)
  80.             if ($pwAccident->getStreet() === $this) {
  81.                 $pwAccident->setStreet(null);
  82.             }
  83.         }
  84.         return $this;
  85.     }
  86.     /**
  87.      * @return Collection<int, PwAccount>
  88.      */
  89.     public function getAccounts(): Collection
  90.     {
  91.         return $this->accounts;
  92.     }
  93.     public function addAccount(PwAccount $account): static
  94.     {
  95.         if (!$this->accounts->contains($account)) {
  96.             $this->accounts->add($account);
  97.             $account->setStreet($this);
  98.         }
  99.         return $this;
  100.     }
  101.     public function removeAccount(PwAccount $account): static
  102.     {
  103.         if ($this->accounts->removeElement($account)) {
  104.             // set the owning side to null (unless already changed)
  105.             if ($account->getStreet() === $this) {
  106.                 $account->setStreet(null);
  107.             }
  108.         }
  109.         return $this;
  110.     }
  111. }