src/Entity/Ticket.php line 16

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Concern\Codifiable;
  4. use App\Repository\TicketRepository;
  5. use DateTimeImmutable;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use Symfony\Component\Uid\Uuid;
  10. #[ORM\Entity(repositoryClass: TicketRepository::class)]
  11. #[ORM\Index(columns: ['place'], name: 'tickets_idx_place')]
  12. #[ORM\Index(columns: ['notifier'], name: 'tickets_idx_notifier')]
  13. class Ticket
  14. {
  15. use Codifiable;
  16. public const CODE_NUMBER_LENGTH = 5;
  17. public const TICKET_CODE_PREFIX = 'IN';
  18. public const IN_PROGRESS = '2b78d5d9-d1ec-40d3-82ba-6d6d66ad713f';
  19. public const REOPENED = '376e061f-dcda-4f44-bdfb-6f8182d309e9';
  20. public const CLOSED = '41912f3d-c4db-4fb0-bd1e-74bbb6020cc9';
  21. public const CREATED = 'ec4032b7-5407-4977-80cf-97f1e0e6eb36';
  22. #[ORM\OneToMany(mappedBy: 'ticket', targetEntity: Update::class)]
  23. private Collection $updates;
  24. public function __construct(
  25. #[ORM\Id]
  26. #[ORM\Column(type:"string", length:36)]
  27. private ?string $id = null,
  28. #[ORM\Column(type:"text", nullable: true)]
  29. private ?string $summary = null,
  30. #[ORM\Column(type:"text", nullable: true)]
  31. private ?string $description = null,
  32. #[ORM\Column(type:"string", nullable: true)]
  33. private ?string $userCode = null,
  34. #[ORM\Column(type:"string", nullable: true)]
  35. private ?string $receiver = null,
  36. #[ORM\Column(type: 'string', nullable: true)]
  37. private ?string $notifier = null,
  38. #[ORM\Column(type: 'string', nullable: true)]
  39. private ?string $place = null,
  40. #[ORM\Column(type: 'json', nullable: true)]
  41. private ?array $extraData = null,
  42. #[ORM\Column(type: 'datetime_immutable', nullable: true)]
  43. private ?DateTimeImmutable $createdAt = null,
  44. #[ORM\Column(type: 'datetime_immutable', nullable: true)]
  45. private ?DateTimeImmutable $updatedAt = null,
  46. #[ORM\ManyToOne(inversedBy: 'tickets')]
  47. #[ORM\JoinColumn(name:"statusId", referencedColumnName:"id")]
  48. private ?Status $status = null,
  49. #[ORM\ManyToOne(inversedBy: 'tickets')]
  50. #[ORM\JoinColumn(name:"priorityId", referencedColumnName:"id")]
  51. private ?Priority $priority = null,
  52. #[ORM\ManyToOne(inversedBy: 'tickets')]
  53. #[ORM\JoinColumn(name:"reasonId", referencedColumnName:"id")]
  54. private ?Reason $reason = null,
  55. #[ORM\ManyToOne(inversedBy: 'tickets')]
  56. #[ORM\JoinColumn(name:"categoryId", referencedColumnName:"id")]
  57. private ?Category $category = null,
  58. #[ORM\ManyToOne(inversedBy: 'tickets')]
  59. #[ORM\JoinColumn(name:"locationId", referencedColumnName:"id")]
  60. private ?Location $location = null,
  61. #[ORM\ManyToOne(inversedBy: 'tickets')]
  62. #[ORM\JoinColumn(name:"rateId", referencedColumnName:"id")]
  63. private ?Rate $rate = null,
  64. #[ORM\ManyToOne(inversedBy: 'tickets')]
  65. #[ORM\JoinColumn(name:"agentId", referencedColumnName:"id")]
  66. private ?Agent $agent = null,
  67. #[ORM\Column(type: 'datetime_immutable', nullable: true)]
  68. private ?DateTimeImmutable $adminReadedAt = null,
  69. #[ORM\Column(type: 'datetime_immutable', nullable: true)]
  70. private ?DateTimeImmutable $userReadedAt = null,
  71. #[ORM\Column(type:"string", length: 36, nullable: true)]
  72. private ?string $marketId = null,
  73. #[ORM\Column(type:"boolean", options: ['default' => false])]
  74. private bool $isInquiry = false,
  75. ) {
  76. $this->id = is_null($this->id) ? Uuid::v4()->toRfc4122() : $this->id;
  77. $this->updates = new ArrayCollection();
  78. $this->createdAt = $this->createdAt ?? new DateTimeImmutable('now');
  79. }
  80. public function setIsInquiry(bool $isInquiry): void
  81. {
  82. $this->isInquiry = $isInquiry;
  83. }
  84. public function getIsInquiry(): bool
  85. {
  86. return $this->isInquiry;
  87. }
  88. public function getId(): ?string
  89. {
  90. return $this->id;
  91. }
  92. public function getTicketCode(): string
  93. {
  94. $codeNumber = $this->getCodeNumberString();
  95. return sprintf('%s-%s', self::TICKET_CODE_PREFIX, $codeNumber);
  96. }
  97. public function getSummary(): ?string
  98. {
  99. return $this->summary;
  100. }
  101. public function setSummary(string $summary): self
  102. {
  103. $this->summary = $summary;
  104. $this->markAsUpdated();
  105. return $this;
  106. }
  107. public function getDescription(): ?string
  108. {
  109. return $this->description;
  110. }
  111. public function setDescription(string $description): self
  112. {
  113. $this->description = $description;
  114. $this->markAsUpdated();
  115. return $this;
  116. }
  117. public function getUserCode(): ?string
  118. {
  119. return $this->userCode;
  120. }
  121. /**
  122. * @return string|null
  123. */
  124. public function getPlace(): ?string
  125. {
  126. return $this->place;
  127. }
  128. /**
  129. * @param string|null $place
  130. * @return self
  131. */
  132. public function setPlace(?string $place): self
  133. {
  134. $this->place = $place;
  135. $this->markAsUpdated();
  136. return $this;
  137. }
  138. /**
  139. * @return string|null
  140. */
  141. public function getNotifier(): ?string
  142. {
  143. return $this->notifier;
  144. }
  145. /**
  146. * @param string|null $notifier
  147. * @return self
  148. */
  149. public function setNotifier(?string $notifier): self
  150. {
  151. $this->notifier = $notifier;
  152. $this->markAsUpdated();
  153. return $this;
  154. }
  155. public function setUserCode(string $userCode): self
  156. {
  157. $this->userCode = $userCode;
  158. $this->markAsUpdated();
  159. return $this;
  160. }
  161. public function getCreatedAt(): ?DateTimeImmutable
  162. {
  163. return $this->createdAt;
  164. }
  165. public function setCreatedAt(DateTimeImmutable $createdAt): self
  166. {
  167. $this->createdAt = $createdAt;
  168. return $this;
  169. }
  170. public function getUpdatedAt(): ?\DateTimeInterface
  171. {
  172. return $this->updatedAt;
  173. }
  174. public function setUpdatedAt(\DateTimeImmutable $updatedAt): self
  175. {
  176. $this->updatedAt = $updatedAt;
  177. return $this;
  178. }
  179. public function markAsUpdated(): void
  180. {
  181. $this->updatedAt = new \DateTimeImmutable();
  182. }
  183. public function __toString(): string
  184. {
  185. return $this->getCodeNumberString();
  186. }
  187. public function getPriority(): ?Priority
  188. {
  189. return $this->priority;
  190. }
  191. public function setPriority(?Priority $priority): self
  192. {
  193. $this->priority = $priority;
  194. $this->markAsUpdated();
  195. return $this;
  196. }
  197. public function getReason(): ?Reason
  198. {
  199. return $this->reason;
  200. }
  201. public function setReason(?Reason $reason): self
  202. {
  203. $this->reason = $reason;
  204. $this->markAsUpdated();
  205. return $this;
  206. }
  207. public function getStatus(): ?Status
  208. {
  209. return $this->status;
  210. }
  211. public function setStatus(?Status $status): self
  212. {
  213. $this->status = $status;
  214. $this->markAsUpdated();
  215. return $this;
  216. }
  217. public function getCategory(): ?Category
  218. {
  219. return $this->category;
  220. }
  221. public function setCategory(?Category $category): self
  222. {
  223. $this->category = $category;
  224. $this->markAsUpdated();
  225. return $this;
  226. }
  227. public function getLocation(): ?Location
  228. {
  229. return $this->location;
  230. }
  231. public function setLocation(?Location $location): self
  232. {
  233. $this->location = $location;
  234. $this->markAsUpdated();
  235. return $this;
  236. }
  237. public function getRate(): ?Rate
  238. {
  239. return $this->rate;
  240. }
  241. public function setRate(?Rate $rate): self
  242. {
  243. $this->rate = $rate;
  244. $this->markAsUpdated();
  245. return $this;
  246. }
  247. public function getAgent(): ?Agent
  248. {
  249. return $this->agent;
  250. }
  251. public function setAgent(?Agent $agent): self
  252. {
  253. $this->agent = $agent;
  254. $this->markAsUpdated();
  255. return $this;
  256. }
  257. /**
  258. * @return Collection<int, Update>
  259. */
  260. public function getUpdates(): Collection
  261. {
  262. return $this->updates;
  263. }
  264. public function addUpdate(Update $update): self
  265. {
  266. if (!$this->updates->contains($update)) {
  267. $this->updates->add($update);
  268. $update->setTicket($this);
  269. }
  270. return $this;
  271. }
  272. public function removeUpdate(Update $update): self
  273. {
  274. if ($this->updates->removeElement($update)) {
  275. // set the owning side to null (unless already changed)
  276. if ($update->getTicket() === $this) {
  277. $update->setTicket(null);
  278. }
  279. }
  280. return $this;
  281. }
  282. public function getExtraData(): ?array
  283. {
  284. return $this->extraData;
  285. }
  286. public function setExtraData(?array $extraData): void
  287. {
  288. $this->extraData = $extraData;
  289. }
  290. /**
  291. * @return DateTimeImmutable|null
  292. */
  293. public function getAdminReadedAt(): ?DateTimeImmutable
  294. {
  295. return $this->adminReadedAt;
  296. }
  297. /**
  298. * @param DateTimeImmutable|null $adminReadedAt
  299. */
  300. public function setAdminReadedAt(?DateTimeImmutable $adminReadedAt): void
  301. {
  302. $this->adminReadedAt = $adminReadedAt;
  303. }
  304. /**
  305. * @return DateTimeImmutable|null
  306. */
  307. public function getUserReadedAt(): ?DateTimeImmutable
  308. {
  309. return $this->userReadedAt;
  310. }
  311. /**
  312. * @param DateTimeImmutable|null $userReadedAt
  313. */
  314. public function setUserReadedAt(?DateTimeImmutable $userReadedAt): void
  315. {
  316. $this->userReadedAt = $userReadedAt;
  317. }
  318. /**
  319. * @return string|null
  320. */
  321. public function getReceiver(): ?string
  322. {
  323. return $this->receiver;
  324. }
  325. /**
  326. * @param string|null $receiver
  327. */
  328. public function setReceiver(?string $receiver): void
  329. {
  330. $this->receiver = $receiver;
  331. }
  332. public function getMarketId(): ?string
  333. {
  334. return $this->marketId;
  335. }
  336. public function setMarketId(?string $marketId): void
  337. {
  338. $this->marketId = $marketId;
  339. }
  340. public function isClose(): bool
  341. {
  342. return $this->status instanceof Status && $this->status->getIsClose();
  343. }
  344. }