src/Entity/PwStreet.php line 26

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