<?php
namespace App\Entity;
use ApiPlatform\Metadata\ApiResource;
use App\Repository\PwStreetRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
use ApiPlatform\Metadata\ApiFilter;
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
#[ORM\Entity(repositoryClass: PwStreetRepository::class)]
#[ApiResource(
normalizationContext: ['groups' => ['PwStreet:read']],
denormalizationContext: ['groups' => ['PwStreet:write']],
cacheHeaders: [
'max_age' => 60,
'shared_max_age' => 120,
'vary' => ['Authorization', 'Accept-Language']
],
)]
#[ApiFilter(SearchFilter::class, properties: ['name' => 'ipartial', 'city.id' => 'exact'])]
class PwStreet
{
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'IDENTITY')]
#[ORM\Column]
#[Groups(['PwAccident:read', 'PwAccident:write', 'PwStreet:read', 'PwAddressQ:read'])]
private ?int $id = null;
#[ORM\ManyToOne(inversedBy: 'pwStreets')]
#[Groups(['PwAccident:read', 'PwAccident:write', 'PwStreet:read'])]
private ?PwCity $city = null;
#[ORM\Column(length: 255)]
#[Groups(['PwAccident:read', 'PwAccident:write', 'PwStreet:read', 'PwAddressQ:read'])]
private ?string $name = null;
#[ORM\OneToMany(mappedBy: 'street', targetEntity: PwAccident::class)]
private Collection $pwAccidents;
#[ORM\OneToMany(mappedBy: 'street', targetEntity: PwAccount::class)]
private Collection $accounts;
#[ORM\OneToMany(mappedBy: 'street', targetEntity: PwAddressQueue::class)]
private Collection $pwAddressQueues;
public function __construct()
{
$this->pwAccidents = new ArrayCollection();
$this->accounts = new ArrayCollection();
$this->pwAddressQueues = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getCity(): ?PwCity
{
return $this->city;
}
public function setCity(?PwCity $city): static
{
$this->city = $city;
return $this;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): static
{
$this->name = $name;
return $this;
}
/**
* @return Collection<int, PwAccident>
*/
public function getPwAccidents(): Collection
{
return $this->pwAccidents;
}
public function addPwAccident(PwAccident $pwAccident): static
{
if (!$this->pwAccidents->contains($pwAccident)) {
$this->pwAccidents->add($pwAccident);
$pwAccident->setStreet($this);
}
return $this;
}
public function removePwAccident(PwAccident $pwAccident): static
{
if ($this->pwAccidents->removeElement($pwAccident)) {
// set the owning side to null (unless already changed)
if ($pwAccident->getStreet() === $this) {
$pwAccident->setStreet(null);
}
}
return $this;
}
/**
* @return Collection<int, PwAccount>
*/
public function getAccounts(): Collection
{
return $this->accounts;
}
public function addAccount(PwAccount $account): static
{
if (!$this->accounts->contains($account)) {
$this->accounts->add($account);
$account->setStreet($this);
}
return $this;
}
public function removeAccount(PwAccount $account): static
{
if ($this->accounts->removeElement($account)) {
// set the owning side to null (unless already changed)
if ($account->getStreet() === $this) {
$account->setStreet(null);
}
}
return $this;
}
/**
* @return Collection<int, PwAddressQueue>
*/
public function getPwAddressQueues(): Collection
{
return $this->pwAddressQueues;
}
public function addPwAddressQueue(PwAddressQueue $pwAddressQueue): static
{
if (!$this->pwAddressQueues->contains($pwAddressQueue)) {
$this->pwAddressQueues->add($pwAddressQueue);
$pwAddressQueue->setStreet($this);
}
return $this;
}
public function removePwAddressQueue(PwAddressQueue $pwAddressQueue): static
{
if ($this->pwAddressQueues->removeElement($pwAddressQueue)) {
// set the owning side to null (unless already changed)
if ($pwAddressQueue->getStreet() === $this) {
$pwAddressQueue->setStreet(null);
}
}
return $this;
}
}