<?php
namespace App\Entity\Server\Ticket;
use App\Entity\BaseEntity;
use App\Entity\Generic\User;
use App\Repository\Server\Ticket\TicketRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\IdGenerator\UuidGenerator;
#[ORM\Entity(repositoryClass: TicketRepository::class)]
class Ticket extends BaseEntity
{
#[ORM\Id]
#[ORM\Column(type: 'guid', unique: true)]
#[ORM\GeneratedValue(strategy: 'CUSTOM')]
#[ORM\CustomIdGenerator(class: UuidGenerator::class)]
private $id;
#[ORM\ManyToOne(inversedBy: 'tickets')]
#[ORM\JoinColumn(nullable: false)]
private ?User $creator = null;
#[ORM\Column]
private ?bool $isAnswered = null;
#[ORM\OneToMany(mappedBy: 'ticket', targetEntity: TicketMessage::class)]
private Collection $ticketMessages;
#[ORM\Column(length: 255)]
private ?string $title = null;
public function __construct()
{
parent::__construct();
$this->setIsAnswered(false);
$this->ticketMessages = new ArrayCollection();
}
public function getId(): ?string
{
return $this->id;
}
public function getCreator(): ?User
{
return $this->creator;
}
public function setCreator(?User $creator): static
{
$this->creator = $creator;
return $this;
}
public function isIsAnswered(): ?bool
{
return $this->isAnswered;
}
public function setIsAnswered(bool $isAnswered): static
{
$this->isAnswered = $isAnswered;
return $this;
}
/**
* @return Collection<int, TicketMessage>
*/
public function getTicketMessages(): Collection
{
return $this->ticketMessages;
}
public function addTicketMessage(TicketMessage $ticketMessage): static
{
if (!$this->ticketMessages->contains($ticketMessage)) {
$this->ticketMessages->add($ticketMessage);
$ticketMessage->setTicket($this);
}
return $this;
}
public function removeTicketMessage(TicketMessage $ticketMessage): static
{
if ($this->ticketMessages->removeElement($ticketMessage)) {
// set the owning side to null (unless already changed)
if ($ticketMessage->getTicket() === $this) {
$ticketMessage->setTicket(null);
}
}
return $this;
}
public function getTitle(): ?string
{
return $this->title;
}
public function setTitle(string $title): static
{
$this->title = $title;
return $this;
}
}