src/Entity/PwCity.php line 25

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Metadata\ApiResource;
  4. use App\Repository\PwCityRepository;
  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(repositoryClassPwCityRepository::class)]
  12. #[ApiResource(
  13.     normalizationContext: ['groups' => ['PwCity:read']],
  14.     denormalizationContext: ['groups' => ['PwCity:write']],
  15.     cacheHeaders: [
  16.         'max_age' => 3600
  17.         'shared_max_age' => 7200
  18.         'vary' => ['Authorization''Accept-Language']
  19.     ],
  20. )]
  21. #[ApiFilter(SearchFilter::class, properties: ['name' => 'ipartial''otg.id' => 'exact''codeOtg' => 'exact'])]
  22. class PwCity
  23. {
  24.     #[ORM\Id]
  25.     #[ORM\GeneratedValue(strategy'IDENTITY')]
  26.     #[ORM\Column]
  27.     #[Groups(['PwAccident:read''PwAccident:write''PwCity:read'])]
  28.     private ?int $id null;
  29.     #[Groups(['PwAccident:read''PwAccident:write''PwCity:read'])]
  30.     #[ORM\Column(length255nullabletrue)]
  31.     private ?string $name null;
  32.     #[Groups(['PwAccident:read''PwAccident:write''PwCity:read'])]
  33.     #[ORM\Column(length255nullabletrue)]
  34.     private ?string $codeOtg null;
  35.     #[ORM\OneToMany(mappedBy'city'targetEntityPwStreet::class)]
  36.     private Collection $pwStreets;
  37.     #[ORM\OneToMany(mappedBy'city'targetEntityPwAccident::class)]
  38.     private Collection $pwAccidents;
  39.     #[Groups(['PwCity:read'])]
  40.     #[ORM\ManyToOne(inversedBy'pwCities')]
  41.     private ?PwOtg $otg null;
  42.     #[ORM\OneToMany(mappedBy'city'targetEntityPwAccount::class)]
  43.     private Collection $accounts;
  44.     public function __construct()
  45.     {
  46.         $this->pwStreets = new ArrayCollection();
  47.         $this->pwAccidents = new ArrayCollection();
  48.         $this->accounts = new ArrayCollection();
  49.     }
  50.     public function getId(): ?int
  51.     {
  52.         return $this->id;
  53.     }
  54.     public function getName(): ?string
  55.     {
  56.         return $this->name;
  57.     }
  58.     public function setName(?string $name): static
  59.     {
  60.         $this->name $name;
  61.         return $this;
  62.     }
  63.     public function getCodeOtg(): ?string
  64.     {
  65.         return $this->codeOtg;
  66.     }
  67.     public function setCodeOtg(?string $codeOtg): static
  68.     {
  69.         $this->codeOtg $codeOtg;
  70.         return $this;
  71.     }
  72.     /**
  73.      * @return Collection<int, PwStreet>
  74.      */
  75.     public function getPwStreets(): Collection
  76.     {
  77.         return $this->pwStreets;
  78.     }
  79.     public function addPwStreet(PwStreet $pwStreet): static
  80.     {
  81.         if (!$this->pwStreets->contains($pwStreet)) {
  82.             $this->pwStreets->add($pwStreet);
  83.             $pwStreet->setCity($this);
  84.         }
  85.         return $this;
  86.     }
  87.     public function removePwStreet(PwStreet $pwStreet): static
  88.     {
  89.         if ($this->pwStreets->removeElement($pwStreet)) {
  90.             // set the owning side to null (unless already changed)
  91.             if ($pwStreet->getCity() === $this) {
  92.                 $pwStreet->setCity(null);
  93.             }
  94.         }
  95.         return $this;
  96.     }
  97.     /**
  98.      * @return Collection<int, PwAccident>
  99.      */
  100.     public function getPwAccidents(): Collection
  101.     {
  102.         return $this->pwAccidents;
  103.     }
  104.     public function addPwAccident(PwAccident $pwAccident): static
  105.     {
  106.         if (!$this->pwAccidents->contains($pwAccident)) {
  107.             $this->pwAccidents->add($pwAccident);
  108.             $pwAccident->setCity($this);
  109.         }
  110.         return $this;
  111.     }
  112.     public function removePwAccident(PwAccident $pwAccident): static
  113.     {
  114.         if ($this->pwAccidents->removeElement($pwAccident)) {
  115.             // set the owning side to null (unless already changed)
  116.             if ($pwAccident->getCity() === $this) {
  117.                 $pwAccident->setCity(null);
  118.             }
  119.         }
  120.         return $this;
  121.     }
  122.     public function getOtg(): ?PwOtg
  123.     {
  124.         return $this->otg;
  125.     }
  126.     public function setOtg(?PwOtg $otg): static
  127.     {
  128.         $this->otg $otg;
  129.         return $this;
  130.     }
  131.     /**
  132.      * @return Collection<int, PwAccount>
  133.      */
  134.     public function getAccounts(): Collection
  135.     {
  136.         return $this->accounts;
  137.     }
  138.     public function addAccount(PwAccount $account): static
  139.     {
  140.         if (!$this->accounts->contains($account)) {
  141.             $this->accounts->add($account);
  142.             $account->setCity($this);
  143.         }
  144.         return $this;
  145.     }
  146.     public function removeAccount(PwAccount $account): static
  147.     {
  148.         if ($this->accounts->removeElement($account)) {
  149.             // set the owning side to null (unless already changed)
  150.             if ($account->getCity() === $this) {
  151.                 $account->setCity(null);
  152.             }
  153.         }
  154.         return $this;
  155.     }
  156. }