Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

TicketUtils.php 3.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. namespace Lc\ShopBundle\Services ;
  3. use App\Entity\TicketMessage;
  4. use Doctrine\ORM\EntityManagerInterface;
  5. use Lc\ShopBundle\Context\MerchantUtilsInterface;
  6. use Lc\ShopBundle\Context\OrderShopInterface;
  7. use Lc\ShopBundle\Context\TicketInterface;
  8. use Lc\ShopBundle\Context\TicketMessageInterface;
  9. use Lc\ShopBundle\Model\Ticket;
  10. class TicketUtils
  11. {
  12. protected $em ;
  13. protected $merchantUtils ;
  14. public function __construct(EntityManagerInterface $em, MerchantUtilsInterface $merchantUtils)
  15. {
  16. $this->em = $em ;
  17. $this->merchantUtils = $merchantUtils ;
  18. }
  19. public function createTicket($params): TicketInterface
  20. {
  21. $classTicket = $this->em->getClassMetadata(TicketInterface::class)->getName() ;
  22. $ticket = new $classTicket ;
  23. $ticket->setMerchant($this->merchantUtils->getMerchantCurrent()) ;
  24. $ticket->setStatus(1) ;
  25. if(isset($params['user'])) {
  26. $ticket->setUser($params['user']) ;
  27. }
  28. else {
  29. $ticket->setVisitorFirstname($params['visitorFirstname']) ;
  30. $ticket->setVisitorLastname($params['visitorLastname']) ;
  31. $ticket->setVisitorEmail($params['visitorEmail']) ;
  32. $ticket->setVisitorToken(uniqid()) ;
  33. }
  34. $ticket->setTicketStatus(Ticket::TICKET_STATUS_OPEN) ;
  35. $ticket->setType($params['type']) ;
  36. if(isset($params['orderShop']) && $params['orderShop'] && $params['orderShop'] instanceof OrderShopInterface) {
  37. $ticket->setOrderShop($params['orderShop']) ;
  38. }
  39. $ticket->setSubject($params['subject']) ;
  40. $this->em->persist($ticket);
  41. $classTicketMessage = $this->em->getClassMetadata(TicketMessageInterface::class)->getName() ;
  42. $ticketMessage = new $classTicketMessage ;
  43. $ticketMessage->setStatus(1) ;
  44. $ticketMessage->setTicket($ticket) ;
  45. $ticketMessage->setMessage($params['message']) ;
  46. $this->em->persist($ticketMessage);
  47. $this->em->flush() ;
  48. return $ticket ;
  49. }
  50. public function createTicketMessage($params)
  51. {
  52. $classTicketMessage = $this->em->getClassMetadata(TicketMessageInterface::class)->getName() ;
  53. $ticketMessage = new $classTicketMessage ;
  54. $ticket = $params['ticket'] ;
  55. $ticketMessage->setStatus(1) ;
  56. $ticketMessage->setTicket($ticket) ;
  57. $ticketMessage->setMessage($params['message']) ;
  58. $this->em->persist($ticketMessage);
  59. if(isset($params['closeTicket']) && $params['closeTicket']) {
  60. $ticket->setTicketStatus(Ticket::TICKET_STATUS_CLOSED) ;
  61. }
  62. $ticket->setUpdatedAt(new \DateTime()) ;
  63. $this->em->persist($ticket);
  64. $this->em->flush() ;
  65. return $ticketMessage ;
  66. }
  67. }