<?php
# src/Entity/Ticket.php
namespace App\Entity;
use App\Repository\TicketRepository;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
#[ORM\Entity(repositoryClass: TicketRepository::class)]
class Ticket
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private ?int $id = null;
#[ORM\Column(type: 'string', length: 255)]
#[Assert\NotBlank(message: 'Der Titel darf nicht leer sein.')]
private ?string $title = null;
#[ORM\Column(type: 'text')]
#[Assert\NotBlank(message: 'Die Beschreibung darf nicht leer sein.')]
private ?string $description = null;
#[ORM\Column(type: 'string', length: 20)]
private ?string $status = 'offen'; // Werte: offen, in_bearbeitung, geschlossen
#[ORM\Column(type: 'string', length: 50)]
private ?string $priority = 'niedrig'; // Werte: niedrig, mittel, hoch
#[ORM\Column(type: 'datetime')]
private ?\DateTimeInterface $createdAt = null;
#[ORM\Column(type: 'datetime', nullable: true)]
private ?\DateTimeInterface $updatedAt = null;
#[ORM\ManyToOne(targetEntity: User::class, inversedBy: 'tickets')]
#[ORM\JoinColumn(nullable: true)]
private ?User $user = null;
#[ORM\OneToMany(targetEntity: TicketReply::class, mappedBy: 'ticket', cascade: ['remove'], orphanRemoval: true)]
private Collection $replies;
public function __construct()
{
// Setze das Erstellungsdatum
$this->createdAt = new \DateTime();
$this->replies = new ArrayCollection();
}
// Getter und Setter für alle Felder
public function getId(): ?int
{
return $this->id;
}
public function getTitle(): ?string
{
return $this->title;
}
public function setTitle(string $title): self
{
$this->title = $title;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(string $description): self
{
$this->description = $description;
return $this;
}
public function getStatus(): ?string
{
return $this->status;
}
public function setStatus(string $status): self
{
$this->status = $status;
return $this;
}
public function getPriority(): ?string
{
return $this->priority;
}
public function setPriority(string $priority): self
{
$this->priority = $priority;
return $this;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->createdAt;
}
public function setCreatedAt(\DateTimeInterface $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getUpdatedAt(): ?\DateTimeInterface
{
return $this->updatedAt;
}
public function setUpdatedAt(?\DateTimeInterface $updatedAt): self
{
$this->updatedAt = $updatedAt;
return $this;
}
/**
* Methode, um das Ticket auf "geschlossen" zu setzen.
*/
public function close(): self
{
$this->status = 'geschlossen';
$this->updatedAt = new \DateTime();
return $this;
}
/**
* Methode, um das Ticket auf "in Bearbeitung" zu setzen.
*/
public function setInProgress(): self
{
$this->status = 'in_bearbeitung';
$this->updatedAt = new \DateTime();
return $this;
}
// Getter und Setter für das User-Feld
public function getUser(): ?User
{
return $this->user;
}
public function setUser(?User $user): self
{
$this->user = $user;
return $this;
}
/**
* @return Collection<int, TicketReply>
*/
public function getReplies(): Collection
{
return $this->replies;
}
public function addReply(TicketReply $reply): self
{
if (!$this->replies->contains($reply)) {
$this->replies[] = $reply;
$reply->setTicket($this);
}
return $this;
}
public function removeReply(TicketReply $reply): self
{
if ($this->replies->removeElement($reply)) {
// Set the owning side to null (unless already changed)
if ($reply->getTicket() === $this) {
$reply->setTicket(null);
}
}
return $this;
}
}