src/Entity/Ticket.php line 16

  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\TicketRepository;
  4. use App\Traits\Timestamps;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\DBAL\Types\Types;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use Symfony\Component\Serializer\Annotation\Groups;
  10. #[ORM\Entity(repositoryClassTicketRepository::class)]
  11. #[ORM\Table(name'ticket')]
  12. #[ORM\HasLifecycleCallbacks]
  13. class Ticket
  14. {
  15.     use Timestamps;
  16.     
  17.     const STATUS_UNREAD 'unread';
  18.     const STATUS_IN_PROGRESS 'in_progress';
  19.     const STATUS_DONE 'done';
  20.     #[ORM\Id]
  21.     #[ORM\GeneratedValue]
  22.     #[ORM\Column]
  23.     #[Groups(['ticket:read'])]
  24.     private ?int $id null;
  25.     #[ORM\Column(length255)]
  26.     #[Groups(['ticket:read''ticket:write'])]
  27.     private ?string $subject null;
  28.     #[ORM\Column(typeTypes::TEXT)]
  29.     #[Groups(['ticket:read''ticket:write'])]
  30.     private ?string $content null;
  31.     #[ORM\Column(length50)]
  32.     #[Groups(['ticket:read'])]
  33.     private ?string $status self::STATUS_UNREAD;
  34.     #[ORM\ManyToOne]
  35.     #[ORM\JoinColumn(nullablefalse)]
  36.     private ?Client $client null;
  37.     #[ORM\Column(length255nullabletrue)]
  38.     #[Groups(['ticket:read''ticket:write'])]
  39.     private ?string $clientExternalId null;
  40.     
  41.     #[ORM\ManyToOne]
  42.     #[ORM\JoinColumn(nullabletrue)]
  43.     private ?User $assignedTo null;
  44.     #[ORM\OneToMany(mappedBy'ticket'targetEntityTicketResponse::class, orphanRemovaltrue)]
  45.     #[ORM\OrderBy(['createdAt' => 'ASC'])]
  46.     private Collection $responses;
  47.     #[ORM\Column(length255nullabletrue)]
  48.     #[Groups(['ticket:read''ticket:write'])]
  49.     private ?string $priority 'normal';
  50.     
  51.     #[ORM\Column(length255nullabletrue)]
  52.     #[Groups(['ticket:read''ticket:write'])]
  53.     private ?string $category null;
  54.     public function __construct()
  55.     {
  56.         $this->responses = new ArrayCollection();
  57.     }
  58.     public function getId(): ?int
  59.     {
  60.         return $this->id;
  61.     }
  62.     public function getSubject(): ?string
  63.     {
  64.         return $this->subject;
  65.     }
  66.     public function setSubject(string $subject): self
  67.     {
  68.         $this->subject $subject;
  69.         return $this;
  70.     }
  71.     public function getContent(): ?string
  72.     {
  73.         return $this->content;
  74.     }
  75.     public function setContent(string $content): self
  76.     {
  77.         $this->content $content;
  78.         return $this;
  79.     }
  80.     public function getStatus(): ?string
  81.     {
  82.         return $this->status;
  83.     }
  84.     public function setStatus(string $status): self
  85.     {
  86.         $this->status $status;
  87.         return $this;
  88.     }
  89.     public function getClient(): ?Client
  90.     {
  91.         return $this->client;
  92.     }
  93.     public function setClient(?Client $client): self
  94.     {
  95.         $this->client $client;
  96.         return $this;
  97.     }
  98.     
  99.     public function getClientExternalId(): ?string
  100.     {
  101.         return $this->clientExternalId;
  102.     }
  103.     public function setClientExternalId(?string $clientExternalId): self
  104.     {
  105.         $this->clientExternalId $clientExternalId;
  106.         return $this;
  107.     }
  108.     public function getAssignedTo(): ?User
  109.     {
  110.         return $this->assignedTo;
  111.     }
  112.     public function setAssignedTo(?User $assignedTo): self
  113.     {
  114.         $this->assignedTo $assignedTo;
  115.         return $this;
  116.     }
  117.     /**
  118.      * @return Collection<int, TicketResponse>
  119.      */
  120.     public function getResponses(): Collection
  121.     {
  122.         return $this->responses;
  123.     }
  124.     public function addResponse(TicketResponse $response): self
  125.     {
  126.         if (!$this->responses->contains($response)) {
  127.             $this->responses->add($response);
  128.             $response->setTicket($this);
  129.         }
  130.         return $this;
  131.     }
  132.     public function removeResponse(TicketResponse $response): self
  133.     {
  134.         if ($this->responses->removeElement($response)) {
  135.             // set the owning side to null (unless already changed)
  136.             if ($response->getTicket() === $this) {
  137.                 $response->setTicket(null);
  138.             }
  139.         }
  140.         return $this;
  141.     }
  142.     public function getPriority(): ?string
  143.     {
  144.         return $this->priority;
  145.     }
  146.     public function setPriority(?string $priority): self
  147.     {
  148.         $this->priority $priority;
  149.         return $this;
  150.     }
  151.     public function getCategory(): ?string
  152.     {
  153.         return $this->category;
  154.     }
  155.     public function setCategory(?string $category): self
  156.     {
  157.         $this->category $category;
  158.         return $this;
  159.     }
  160.     
  161.     public function getStatusLabel(): string
  162.     {
  163.         return match($this->status) {
  164.             self::STATUS_UNREAD => 'Unread',
  165.             self::STATUS_IN_PROGRESS => 'In progress',
  166.             self::STATUS_DONE => 'Done',
  167.             default => 'Unknown'
  168.         };
  169.     }
  170.     
  171.     public function getStatusClass(): string
  172.     {
  173.         return match($this->status) {
  174.             self::STATUS_UNREAD => 'danger',
  175.             self::STATUS_IN_PROGRESS => 'warning',
  176.             self::STATUS_DONE => 'success',
  177.             default => 'secondary'
  178.         };
  179.     }
  180. }