Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

293 linhas
7.0KB

  1. <?php
  2. namespace Lc\SovBundle\Model\Ticket;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Gedmo\Mapping\Annotation as Gedmo;
  7. use Lc\SovBundle\Doctrine\EntityInterface;
  8. use Lc\SovBundle\Doctrine\Pattern\AbstractLightEntity;
  9. use Lc\SovBundle\Model\User\UserInterface;
  10. /**
  11. * @ORM\MappedSuperclass()
  12. */
  13. abstract class TicketModel extends AbstractLightEntity implements TicketInterface, EntityInterface
  14. {
  15. const TYPE_TECHNICAL_PROBLEM = 'technical-problem';
  16. const TYPE_GENERAL_QUESTION = 'general-question';
  17. const TICKET_STATUS_OPEN = 'open';
  18. const TICKET_STATUS_BEING_PROCESSED = 'being-processed';
  19. const TICKET_STATUS_CLOSED = 'closed';
  20. /**
  21. * @Gedmo\Blameable(on="create")
  22. * @ORM\ManyToOne(targetEntity="Lc\SovBundle\Model\User\UserInterface")
  23. * @ORM\JoinColumn(nullable=true)
  24. */
  25. protected $createdBy;
  26. /**
  27. * @Gedmo\Blameable(on="update")
  28. * @ORM\ManyToOne(targetEntity="Lc\SovBundle\Model\User\UserInterface")
  29. * @ORM\JoinColumn(nullable=true)
  30. */
  31. protected $updatedBy;
  32. /**
  33. * @ORM\Column(type="string", length=32)
  34. */
  35. protected $type;
  36. /**
  37. * @ORM\Column(type="string", length=32)
  38. */
  39. protected $status;
  40. /**
  41. * @ORM\Column(type="string", length=255)
  42. */
  43. protected $subject;
  44. /**
  45. * @ORM\Column(type="array", nullable=true)
  46. */
  47. protected $tags = [];
  48. /**
  49. * @ORM\Column(type="string", length=64, nullable=true)
  50. */
  51. protected $visitorFirstname;
  52. /**
  53. * @ORM\Column(type="string", length=64, nullable=true)
  54. */
  55. protected $visitorLastname;
  56. /**
  57. * @ORM\Column(type="string", length=128, nullable=true)
  58. */
  59. protected $visitorEmail;
  60. /**
  61. * @ORM\Column(type="string", length=255, nullable=true)
  62. */
  63. protected $visitorToken;
  64. /**
  65. * @ORM\OneToMany(targetEntity="Lc\SovBundle\Model\Ticket\TicketMessageInterface", mappedBy="ticket", orphanRemoval=true, cascade={"persist", "remove"})
  66. * @ORM\OrderBy({"id" = "ASC"})
  67. */
  68. protected $ticketMessages;
  69. /**
  70. * @ORM\ManyToOne(targetEntity="Lc\SovBundle\Model\User\UserInterface", inversedBy="tickets")
  71. */
  72. protected $user;
  73. public function __construct()
  74. {
  75. $this->ticketMessages = new ArrayCollection();
  76. }
  77. public function getUsername()
  78. {
  79. if ($this->getUser()) {
  80. return $this->getUser()->getName();
  81. } else {
  82. return strtoupper($this->getVisitorLastname()) . ' ' . $this->getVisitorFirstname();
  83. }
  84. }
  85. public function getUserInfosTicket()
  86. {
  87. $user = $this->getUser();
  88. if ($user) {
  89. return '#' . $user->getId() . ' ' . $user->getName() . ' ' . $user->getEmail();
  90. } else {
  91. return strtoupper($this->getVisitorLastname()) . ' ' . $this->getVisitorFirstname(
  92. ) . ' ' . $this->getVisitorEmail();
  93. }
  94. }
  95. public function getEmail()
  96. {
  97. if ($this->getUser()) {
  98. return $this->getUser()->getEmail();
  99. } else {
  100. return $this->getVisitorEmail();
  101. }
  102. }
  103. public function getVisitorInfos()
  104. {
  105. return strtoupper($this->getVisitorLastname()) . ' ' . $this->getVisitorFirstname(
  106. ) . ' (' . $this->getVisitorEmail() . ')';
  107. }
  108. public function getLastMessage()
  109. {
  110. return $this->getTicketMessages()->last();
  111. }
  112. public function getType(): ?string
  113. {
  114. return $this->type;
  115. }
  116. public function setType(string $type): self
  117. {
  118. $this->type = $type;
  119. return $this;
  120. }
  121. public function getTypeLabel(): string
  122. {
  123. return 'entity.Ticket.fields.typeOptions.' . $this->getType();
  124. }
  125. public function getStatus(): ?string
  126. {
  127. return $this->status;
  128. }
  129. public function setStatus(string $status): self
  130. {
  131. $this->status = $status;
  132. return $this;
  133. }
  134. public function getStatusLabel(): string
  135. {
  136. return 'entity.Ticket.statusOptions.' . $this->getStatus();
  137. }
  138. public function getChoicesStatus(): array
  139. {
  140. return [
  141. 'entity.Ticket.fields.statusOptions.' . TicketModel::TICKET_STATUS_OPEN => TicketModel::TICKET_STATUS_OPEN,
  142. 'entity.Ticket.fields.statusOptions.' . TicketModel::TICKET_STATUS_BEING_PROCESSED => TicketModel::TICKET_STATUS_BEING_PROCESSED,
  143. 'entity.Ticket.fields.statusOptions.' . TicketModel::TICKET_STATUS_CLOSED => TicketModel::TICKET_STATUS_CLOSED,
  144. ];
  145. }
  146. public function getSubject(): ?string
  147. {
  148. return $this->subject;
  149. }
  150. public function setSubject(string $subject): self
  151. {
  152. $this->subject = $subject;
  153. return $this;
  154. }
  155. public function getTags(): ?array
  156. {
  157. return $this->tags;
  158. }
  159. public function setTags(?array $tags): self
  160. {
  161. $this->tags = $tags;
  162. return $this;
  163. }
  164. public function getVisitorFirstname(): ?string
  165. {
  166. return $this->visitorFirstname;
  167. }
  168. public function setVisitorFirstname(?string $visitorFirstname): self
  169. {
  170. $this->visitorFirstname = $visitorFirstname;
  171. return $this;
  172. }
  173. public function getVisitorLastname(): ?string
  174. {
  175. return $this->visitorLastname;
  176. }
  177. public function setVisitorLastname(?string $visitorLastname): self
  178. {
  179. $this->visitorLastname = $visitorLastname;
  180. return $this;
  181. }
  182. public function getVisitorEmail(): ?string
  183. {
  184. return $this->visitorEmail;
  185. }
  186. public function setVisitorEmail(?string $visitorEmail): self
  187. {
  188. $this->visitorEmail = $visitorEmail;
  189. return $this;
  190. }
  191. public function getVisitorToken(): ?string
  192. {
  193. return $this->visitorToken;
  194. }
  195. public function setVisitorToken(?string $visitorToken): self
  196. {
  197. $this->visitorToken = $visitorToken;
  198. return $this;
  199. }
  200. /**
  201. * @return Collection|TicketMessageInterface[]
  202. */
  203. public function getTicketMessages(): Collection
  204. {
  205. return $this->ticketMessages;
  206. }
  207. public function addTicketMessage(TicketMessageInterface $ticketMessage): self
  208. {
  209. if (!$this->ticketMessages->contains($ticketMessage)) {
  210. $this->ticketMessages[] = $ticketMessage;
  211. $ticketMessage->setTicket($this);
  212. }
  213. return $this;
  214. }
  215. public function removeTicketMessage(TicketMessageInterface $ticketMessage): self
  216. {
  217. if ($this->ticketMessages->contains($ticketMessage)) {
  218. $this->ticketMessages->removeElement($ticketMessage);
  219. // set the owning side to null (unless already changed)
  220. if ($ticketMessage->getTicket() === $this) {
  221. $ticketMessage->setTicket(null);
  222. }
  223. }
  224. return $this;
  225. }
  226. public function getUser(): ?UserInterface
  227. {
  228. return $this->user;
  229. }
  230. public function setUser(?UserInterface $user): self
  231. {
  232. $this->user = $user;
  233. return $this;
  234. }
  235. }