You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

TicketController.php 5.5KB

4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php
  2. namespace Lc\ShopBundle\Controller\Backend;
  3. use Doctrine\ORM\EntityManagerInterface;
  4. use EasyCorp\Bundle\EasyAdminBundle\Event\EasyAdminEvents;
  5. use FOS\UserBundle\Model\UserManagerInterface;
  6. use Lc\ShopBundle\Form\Backend\Ticket\TicketMessageType;
  7. use Lc\ShopBundle\Form\Backend\Ticket\TicketStatusType;
  8. use Lc\ShopBundle\Model\Ticket;
  9. use Lc\ShopBundle\Services\UtilsManager;
  10. use Mailjet\MailjetSwiftMailer\SwiftMailer\MailjetTransport;
  11. use Symfony\Component\HttpFoundation\Response;
  12. use Symfony\Component\Security\Core\Security;
  13. use Symfony\Contracts\Translation\TranslatorInterface;
  14. class TicketController extends AdminController
  15. {
  16. protected $ticketUtils;
  17. public function __construct(Security $security, UserManagerInterface $userManager, EntityManagerInterface $em, MailjetTransport $mailjetTransport, UtilsManager $utilsManager, TranslatorInterface $translator)
  18. {
  19. $this->ticketUtils = $utilsManager->getTicketUtils();
  20. parent::__construct($security, $userManager, $em, $mailjetTransport, $utilsManager, $translator);
  21. }
  22. protected function createListQueryBuilder($entityClass, $sortDirection, $sortField = null, $dqlFilter = null)
  23. {
  24. $queryBuilder = parent::createListQueryBuilder($entityClass, $sortDirection, $sortField, $dqlFilter);
  25. if ($this->filtersForm->get('status')->getData() === null) {
  26. $queryBuilder->andWhere('entity.status LIKE :open OR entity.status LIKE :beingprocessed');
  27. $queryBuilder->setParameter('open', Ticket::TICKET_STATUS_OPEN);
  28. $queryBuilder->setParameter('beingprocessed', Ticket::TICKET_STATUS_BEING_PROCESSED);
  29. }
  30. return $queryBuilder;
  31. }
  32. public function showAction()
  33. {
  34. $this->dispatch(EasyAdminEvents::PRE_SHOW);
  35. $id = $this->request->query->get('id');
  36. $easyadmin = $this->request->attributes->get('easyadmin');
  37. $entity = $easyadmin['item'];
  38. $fields = $this->entity['show']['fields'];
  39. $deleteForm = $this->createDeleteForm($this->entity['name'], $id);
  40. $this->dispatch(EasyAdminEvents::POST_SHOW, [
  41. 'deleteForm' => $deleteForm,
  42. 'fields' => $fields,
  43. 'entity' => $entity,
  44. ]);
  45. $parameters = [
  46. 'entity' => $entity,
  47. 'fields' => $fields,
  48. 'delete_form' => $deleteForm->createView(),
  49. ];
  50. return $this->executeDynamicMethod('render<EntityName>Template', ['show', $this->entity['templates']['show'], $parameters]);
  51. }
  52. /**
  53. * The method that is executed when the user performs a 'show' action on an entity.
  54. *
  55. * @return Response
  56. */
  57. public function renderTicketTemplate($actionName, $templatePath, array $parameters = [])
  58. {
  59. if ($actionName == 'show') {
  60. $parameters['form_add_ticket_message'] = $this->createCustomForm(TicketMessageType::class, 'newMessageTicket', $parameters, false)->createView();
  61. $parameters['form_ticket_status'] = $this->createCustomForm(TicketStatusType::class, 'ticketStatus', $parameters)->createView();
  62. }
  63. return parent::renderTemplate($actionName, $templatePath, $parameters);
  64. }
  65. public function ticketStatusAction(){
  66. $easyadmin = $this->request->attributes->get('easyadmin');
  67. $ticket = $easyadmin['item'];
  68. $formTicketStatusForm = $this->createForm(TicketStatusType::class, $ticket);
  69. $formTicketStatusForm->handleRequest($this->request);
  70. if ($formTicketStatusForm->isSubmitted() && $formTicketStatusForm->isValid()) {
  71. $this->em->persist($ticket);
  72. $this->em->flush();
  73. $this->utils->addFlash('success', 'success.ticket.statusChange');
  74. } else {
  75. $this->utils->addFlash('error', $formTicketStatusForm->getErrors());
  76. }
  77. $response['flashMessages'] = $this->utils->getFlashMessages();
  78. return new Response(json_encode($response));
  79. }
  80. public function newMessageTicketAction(){
  81. $easyadmin = $this->request->attributes->get('easyadmin');
  82. $ticket = $easyadmin['item'];
  83. $formAddTicketMessage = $this->createForm(TicketMessageType::class);
  84. $formAddTicketMessage->handleRequest($this->request);
  85. if ($formAddTicketMessage->isSubmitted() && $formAddTicketMessage->isValid()) {
  86. $this->ticketUtils->createTicketMessage(array(
  87. 'ticket'=>$ticket,
  88. 'message'=> $formAddTicketMessage->get('message')->getData(),
  89. 'answerByAdmin'=>true
  90. ));
  91. $this->utils->addFlash('success', 'success.ticket.addMessage');
  92. } else {
  93. $this->utils->addFlash('error', $formAddTicketMessage->getErrors());
  94. }
  95. return $this->redirectToRoute('easyadmin', [
  96. 'action' => 'show',
  97. 'entity' => 'Ticket',
  98. 'id' => $ticket->getId()
  99. ]);
  100. }
  101. }