<?php
namespace App\Entity;
use ApiPlatform\Metadata\ApiResource;
use App\Repository\PwOtgRepository;
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;
use ApiPlatform\Metadata\ApiProperty;
#[ORM\Entity(repositoryClass: PwOtgRepository::class)]
#[ApiResource(
normalizationContext: ['groups' => ['PwOtg:read']],
denormalizationContext: ['groups' => ['PwOtg:write']],
)]
#[ApiFilter(SearchFilter::class, properties: ['name' => 'ipartial', 'code' => 'exact'])]
class PwOtg
{
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'IDENTITY')]
#[ORM\Column]
#[Groups(['PwAccident:read', 'PwAccident:write', 'PwOtg:read'])]
private ?int $id = null;
#[ORM\Column(length: 255, unique: true)]
#[Groups(['PwAccident:read', 'PwAccident:write', 'PwOtg:read'])]
private ?string $code = null;
#[ORM\Column(length: 255)]
#[Groups(['PwAccident:read', 'PwAccident:write', 'PwOtg:read'])]
private ?string $name = null;
#[ORM\OneToMany(mappedBy: 'otg', targetEntity: PwCity::class)]
private Collection $pwCities;
#[ORM\OneToMany(mappedBy: 'otg', targetEntity: PwAccident::class)]
private Collection $pwAccidents;
#[ORM\OneToMany(mappedBy: 'otg', targetEntity: PwAccount::class)]
private Collection $accounts;
public function __construct()
{
$this->pwCities = new ArrayCollection();
$this->pwAccidents = new ArrayCollection();
$this->accounts = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getCode(): ?string
{
return $this->code;
}
public function setCode(?string $code): static
{
$this->code = $code;
return $this;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): static
{
$this->name = $name;
return $this;
}
/**
* @return Collection<int, PwCity>
*/
public function getPwCities(): Collection
{
return $this->pwCities;
}
public function addPwCity(PwCity $pwCity): static
{
if (!$this->pwCities->contains($pwCity)) {
$this->pwCities->add($pwCity);
$pwCity->setOtg($this);
}
return $this;
}
public function removePwCity(PwCity $pwCity): static
{
if ($this->pwCities->removeElement($pwCity)) {
// set the owning side to null (unless already changed)
if ($pwCity->getOtg() === $this) {
$pwCity->setOtg(null);
}
}
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->setOtg($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->getOtg() === $this) {
$pwAccident->setOtg(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->setOtg($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->getOtg() === $this) {
$account->setOtg(null);
}
}
return $this;
}
}