src/Entity/PwCity.php line 20

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