<?php
namespace App\Entity\Shop\Ticket;
use App\Entity\BaseEntity;
use App\Entity\Generic\Customer\Customer;
use App\Entity\Shop\Shop\Shop;
use App\Repository\Shop\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)]
#[ORM\Table(name: '`website_ticket`')]
class Ticket extends BaseEntity
{
#[ORM\Id]
#[ORM\Column(type: 'guid', unique: true)]
#[ORM\GeneratedValue(strategy: 'CUSTOM')]
#[ORM\CustomIdGenerator(class: UuidGenerator::class)]
private ?string $id;
#[ORM\Column(length: 255)]
private ?string $title = null;
#[ORM\ManyToOne(inversedBy: 'tickets')]
#[ORM\JoinColumn(nullable: false)]
private ?Shop $shop = null;
#[ORM\Column]
private ?int $priority = null;
#[ORM\ManyToOne(inversedBy: 'tickets')]
#[ORM\JoinColumn(nullable: false)]
private ?Customer $creator = null;
#[ORM\OneToMany(mappedBy: 'ticket', targetEntity: TicketMessage::class)]
private Collection $ticketMessages;
public function getStatus()
{
switch ($this->getPriority()){
case 0:
return'کم اهمیت';
break;
case 1:
return'معمولی';
break;
case 2:
return'اهمیت بالا';
break;
default:
return $this->getPriority();
break;
}
}
public function __construct()
{
parent::__construct();
$this->ticketMessages = new ArrayCollection();
}
public function getId(): ?string
{
return $this->id;
}
public function getTitle(): ?string
{
return $this->title;
}
public function setTitle(string $title): static
{
$this->title = $title;
return $this;
}
public function getShop(): ?Shop
{
return $this->shop;
}
public function setShop(?Shop $shop): static
{
$this->shop = $shop;
return $this;
}
public function getPriority(): ?int
{
return $this->priority;
}
public function setPriority(int $priority): static
{
$this->priority = $priority;
return $this;
}
public function getCreator(): ?Customer
{
return $this->creator;
}
public function setCreator(?Customer $creator): static
{
$this->creator = $creator;
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;
}
}