src/Entity/FielpetPol/Ticket.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Entity\FielpetPol;
  3. use App\Entity\Traits\LoggableTrait;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. /**
  8. * Ticket
  9. *
  10. * @ORM\Table(name="ticket")
  11. * @ORM\Entity(repositoryClass="App\Repository\FielpetPol\TicketRepository")
  12. * @ORM\HasLifecycleCallbacks()
  13. */
  14. class Ticket
  15. {
  16. use LoggableTrait;
  17. const ESTADO_ABIERTO = 'Abierto';
  18. const ESTADO_CERRADO = 'Cerrado';
  19. const ESTADO_PENDIENTE = 'Pendiente';
  20. const ESTADO_DEVUELTO = 'Devuelto';
  21. const ESTADO_REABIERTO = 'Re-Abierto';
  22. public static function getEstados(): array
  23. {
  24. return [
  25. self::ESTADO_ABIERTO => self::ESTADO_ABIERTO,
  26. self::ESTADO_CERRADO => self::ESTADO_CERRADO,
  27. self::ESTADO_PENDIENTE => self::ESTADO_PENDIENTE,
  28. self::ESTADO_DEVUELTO => self::ESTADO_DEVUELTO,
  29. self::ESTADO_REABIERTO => self::ESTADO_REABIERTO,
  30. ];
  31. }
  32. /**
  33. * @var integer
  34. *
  35. * @ORM\Column(name="id", type="integer", nullable=false)
  36. * @ORM\Id
  37. * @ORM\GeneratedValue(strategy="IDENTITY")
  38. */
  39. private $id;
  40. /**
  41. * @var string
  42. *
  43. * @ORM\Column(name="titulo", type="string", length=255, nullable=false)
  44. */
  45. private $titulo;
  46. /**
  47. * @var string
  48. *
  49. * @ORM\Column(name="descripcion", type="text", nullable=false)
  50. */
  51. private $descripcion;
  52. /**
  53. * @var string
  54. *
  55. * @ORM\Column(name="estado", type="string", length=50, nullable=false, options={"default"="Abierto"})
  56. */
  57. private $estado = self::ESTADO_ABIERTO;
  58. /**
  59. * @var string
  60. *
  61. * @ORM\Column(name="prioridad", type="string", length=50, nullable=false, options={"default"="Normal"})
  62. */
  63. private $prioridad = 'Normal';
  64. /**
  65. * @var string|null
  66. *
  67. * @ORM\Column(name="categoria", type="string", length=100, nullable=true)
  68. */
  69. private $categoria;
  70. /**
  71. * @var \DateTime
  72. *
  73. * @ORM\Column(name="fecha_creacion", type="datetime", nullable=false)
  74. */
  75. private $fechaCreacion;
  76. /**
  77. * @var \DateTime|null
  78. *
  79. * @ORM\Column(name="fecha_cierre", type="datetime", nullable=true)
  80. */
  81. private $fechaCierre;
  82. /**
  83. * @var \DateTime|null
  84. *
  85. * @ORM\Column(name="deleted_at", type="datetime", nullable=true)
  86. */
  87. private $deletedAt;
  88. /**
  89. * @var Usuario
  90. *
  91. * @ORM\ManyToOne(targetEntity="App\Entity\FielpetPol\Usuario")
  92. * @ORM\JoinColumn(name="usuario_id", referencedColumnName="id", nullable=false)
  93. */
  94. private $usuario;
  95. /**
  96. * @var Collection|TicketRespuesta[]
  97. *
  98. * @ORM\OneToMany(targetEntity="App\Entity\FielpetPol\TicketRespuesta", mappedBy="ticket", cascade={"persist", "remove"}, orphanRemoval=true)
  99. * @ORM\OrderBy({"fechaCreacion" = "ASC"})
  100. */
  101. private $respuestas;
  102. /**
  103. * @var Collection|TicketAdjunto[]
  104. *
  105. * @ORM\OneToMany(targetEntity="App\Entity\FielpetPol\TicketAdjunto", mappedBy="ticket", cascade={"remove"})
  106. * @ORM\OrderBy({"fechaCreacion" = "ASC"})
  107. */
  108. private $adjuntos;
  109. public function __construct()
  110. {
  111. $this->respuestas = new ArrayCollection();
  112. $this->adjuntos = new ArrayCollection();
  113. $this->fechaCreacion = new \DateTime();
  114. }
  115. // --- Getters & Setters ---
  116. public function getId(): ?int
  117. {
  118. return $this->id;
  119. }
  120. public function getTitulo(): ?string
  121. {
  122. return $this->titulo;
  123. }
  124. public function setTitulo(string $titulo): static
  125. {
  126. $this->titulo = $titulo;
  127. return $this;
  128. }
  129. public function getDescripcion(): ?string
  130. {
  131. return $this->descripcion;
  132. }
  133. public function setDescripcion(string $descripcion): static
  134. {
  135. $this->descripcion = $descripcion;
  136. return $this;
  137. }
  138. public function getEstado(): ?string
  139. {
  140. return $this->estado;
  141. }
  142. public function setEstado(string $estado): static
  143. {
  144. $this->estado = $estado;
  145. if ($estado === self::ESTADO_CERRADO && $this->fechaCierre === null) {
  146. $this->fechaCierre = new \DateTime();
  147. }
  148. if ($estado !== self::ESTADO_CERRADO) {
  149. $this->fechaCierre = null;
  150. }
  151. return $this;
  152. }
  153. public function getPrioridad(): ?string
  154. {
  155. return $this->prioridad;
  156. }
  157. public function setPrioridad(string $prioridad): static
  158. {
  159. $this->prioridad = $prioridad;
  160. return $this;
  161. }
  162. public function getCategoria(): ?string
  163. {
  164. return $this->categoria;
  165. }
  166. public function setCategoria(?string $categoria): static
  167. {
  168. $this->categoria = $categoria;
  169. return $this;
  170. }
  171. public function getFechaCreacion(): ?\DateTimeInterface
  172. {
  173. return $this->fechaCreacion;
  174. }
  175. public function setFechaCreacion(\DateTimeInterface $fechaCreacion): static
  176. {
  177. $this->fechaCreacion = $fechaCreacion;
  178. return $this;
  179. }
  180. public function getFechaCierre(): ?\DateTimeInterface
  181. {
  182. return $this->fechaCierre;
  183. }
  184. public function setFechaCierre(?\DateTimeInterface $fechaCierre): static
  185. {
  186. $this->fechaCierre = $fechaCierre;
  187. return $this;
  188. }
  189. public function getUsuario(): ?Usuario
  190. {
  191. return $this->usuario;
  192. }
  193. public function setUsuario(?Usuario $usuario): static
  194. {
  195. $this->usuario = $usuario;
  196. return $this;
  197. }
  198. public function getRespuestas(): Collection
  199. {
  200. return $this->respuestas;
  201. }
  202. public function addRespuesta(TicketRespuesta $respuesta): static
  203. {
  204. if (!$this->respuestas->contains($respuesta)) {
  205. $this->respuestas[] = $respuesta;
  206. $respuesta->setTicket($this);
  207. }
  208. return $this;
  209. }
  210. public function removeRespuesta(TicketRespuesta $respuesta): static
  211. {
  212. if ($this->respuestas->removeElement($respuesta)) {
  213. if ($respuesta->getTicket() === $this) {
  214. $respuesta->setTicket(null);
  215. }
  216. }
  217. return $this;
  218. }
  219. public function getTotalRespuestas(): int
  220. {
  221. return $this->respuestas->count();
  222. }
  223. public function getDeletedAt(): ?\DateTimeInterface
  224. {
  225. return $this->deletedAt;
  226. }
  227. public function setDeletedAt(?\DateTimeInterface $deletedAt): static
  228. {
  229. $this->deletedAt = $deletedAt;
  230. return $this;
  231. }
  232. public function isDeleted(): bool
  233. {
  234. return $this->deletedAt !== null;
  235. }
  236. public function getAdjuntos(): Collection
  237. {
  238. return $this->adjuntos;
  239. }
  240. /**
  241. * Solo los adjuntos cargados en la creación/edición del ticket (no los de comentarios)
  242. */
  243. public function getAdjuntosDirectos(): Collection
  244. {
  245. return $this->adjuntos->filter(fn(TicketAdjunto $a) => $a->getTicketRespuesta() === null);
  246. }
  247. }