Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

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