Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

TicketModel.php 7.3KB

pirms 3 gadiem
pirms 3 gadiem
pirms 3 gadiem
pirms 3 gadiem
pirms 3 gadiem
pirms 3 gadiem
pirms 3 gadiem
pirms 3 gadiem
pirms 3 gadiem
pirms 3 gadiem
pirms 3 gadiem
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  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 getChoicesType(): array
  126. {
  127. return [
  128. 'entity.Ticket.fields.typeOptions.' . TicketModel::TYPE_GENERAL_QUESTION => TicketModel::TYPE_GENERAL_QUESTION,
  129. 'entity.Ticket.fields.typeOptions.' . TicketModel::TYPE_TECHNICAL_PROBLEM => TicketModel::TYPE_TECHNICAL_PROBLEM,
  130. ];
  131. }
  132. public function getStatus(): ?string
  133. {
  134. return $this->status;
  135. }
  136. public function setStatus(string $status): self
  137. {
  138. $this->status = $status;
  139. return $this;
  140. }
  141. public function getStatusLabel(): string
  142. {
  143. return 'entity.Ticket.statusOptions.' . $this->getStatus();
  144. }
  145. public function getChoicesStatus(): array
  146. {
  147. return [
  148. 'entity.Ticket.fields.statusOptions.' . TicketModel::TICKET_STATUS_OPEN => TicketModel::TICKET_STATUS_OPEN,
  149. 'entity.Ticket.fields.statusOptions.' . TicketModel::TICKET_STATUS_BEING_PROCESSED => TicketModel::TICKET_STATUS_BEING_PROCESSED,
  150. 'entity.Ticket.fields.statusOptions.' . TicketModel::TICKET_STATUS_CLOSED => TicketModel::TICKET_STATUS_CLOSED,
  151. ];
  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. }