<?php
namespace App\Entity\GroupTicket;
use App\Entity\Abstract\Entity;
use App\Entity\User;
use App\Repository\GroupTicket\PublicConnectionRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: PublicConnectionRepository::class)]
#[ORM\Table(name: 'group_tickets_public_connection')]
class PublicConnection extends Entity
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(length: 255)]
private ?string $name = null;
#[ORM\OneToMany(mappedBy: 'publicConnection', targetEntity: PriceList::class, cascade: ["all"])]
private Collection $priceLists;
#[ORM\ManyToMany(targetEntity: TransportCompany::class, mappedBy: 'publicConnections')]
private Collection $transportCompanies;
#[ORM\Column(nullable: true)]
private ?int $restriktion = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $template = null;
#[ORM\ManyToMany(targetEntity: User::class, mappedBy: 'groupTicketPublicConnection')]
private Collection $users;
#[ORM\Column(length: 20, nullable: true)]
private ?string $groupTicketMode = null;
public function __construct()
{
$this->priceLists = new ArrayCollection();
$this->transportCompanies = new ArrayCollection();
$this->users = new ArrayCollection();
}
public function getGroupTicketMode(): ?string
{
return $this->groupTicketMode;
}
public function setGroupTicketMode(?string $groupTicketMode): static
{
$this->groupTicketMode = $groupTicketMode;
return $this;
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): static
{
$this->name = $name;
return $this;
}
/**
* @return Collection<int, PriceList>
*/
public function getPriceLists(): Collection
{
return $this->priceLists;
}
public function addPriceList(PriceList $priceList): static
{
if (!$this->priceLists->contains($priceList)) {
$this->priceLists->add($priceList);
$priceList->setPublicConnection($this);
}
return $this;
}
public function removePriceList(PriceList $priceList): static
{
if ($this->priceLists->removeElement($priceList)) {
// set the owning side to null (unless already changed)
if ($priceList->getPublicConnection() === $this) {
$priceList->setPublicConnection(null);
}
}
return $this;
}
/**
* @return Collection<int, TransportCompany>
*/
public function getTransportCompanies(): Collection
{
return $this->transportCompanies;
}
public function addTransportCompany(TransportCompany $transportCompany): static
{
if (!$this->transportCompanies->contains($transportCompany)) {
$this->transportCompanies->add($transportCompany);
$transportCompany->addPublicConnection($this);
}
return $this;
}
public function removeTransportCompany(TransportCompany $transportCompany): static
{
if ($this->transportCompanies->removeElement($transportCompany)) {
$transportCompany->removePublicConnection($this);
}
return $this;
}
public function getRestriktion(): ?int
{
return $this->restriktion;
}
public function getRestriktionLabelKey(): string
{
return match ($this->getRestriktion()) {
2 => 'rvbw',
3 => 'tvzg',
default => '',
};
}
public function setRestriktion(?int $restriktion): static
{
$this->restriktion = $restriktion;
return $this;
}
public function getTemplate(): ?string
{
return $this->template;
}
public function setTemplate(?string $template): static
{
$this->template = $template;
return $this;
}
/**
* @return Collection<int, User>
*/
public function getUsers(): Collection
{
return $this->users;
}
public function addUser(User $user): static
{
if (!$this->users->contains($user)) {
$this->users->add($user);
$user->addGroupTicketPublicConnection($this);
}
return $this;
}
public function removeUser(User $user): static
{
if ($this->users->removeElement($user)) {
$user->removeGroupTicketPublicConnection($this);
}
return $this;
}
}