<?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']],
)]
#[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'])]
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'])]
private ?string $name = null;
#[ORM\OneToMany(mappedBy: 'street', targetEntity: PwAccident::class)]
private Collection $pwAccidents;
#[ORM\OneToMany(mappedBy: 'street', targetEntity: PwAccount::class)]
private Collection $accounts;
public function __construct()
{
$this->pwAccidents = new ArrayCollection();
$this->accounts = 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;
}
}