TicketController.php 3.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. namespace Lc\ShopBundle\Controller\Backend;
  3. use Doctrine\ORM\EntityManagerInterface;
  4. use FOS\UserBundle\Model\UserManagerInterface;
  5. use Lc\ShopBundle\Form\Backend\Ticket\TicketMessageType;
  6. use Lc\ShopBundle\Form\Backend\Ticket\TicketStatusType;
  7. use Lc\ShopBundle\Services\UtilsManager;
  8. use Mailjet\MailjetSwiftMailer\SwiftMailer\MailjetTransport;
  9. use Symfony\Component\HttpFoundation\Response;
  10. use Symfony\Component\Security\Core\Security;
  11. use Symfony\Contracts\Translation\TranslatorInterface;
  12. class TicketController extends AdminController
  13. {
  14. protected $ticketUtils;
  15. public function __construct(Security $security, UserManagerInterface $userManager, EntityManagerInterface $em, MailjetTransport $mailjetTransport, UtilsManager $utilsManager, TranslatorInterface $translator)
  16. {
  17. $this->ticketUtils = $utilsManager->getTicketUtils();
  18. parent::__construct($security, $userManager, $em, $mailjetTransport, $utilsManager, $translator);
  19. }
  20. /**
  21. * The method that is executed when the user performs a 'show' action on an entity.
  22. *
  23. * @return Response
  24. */
  25. public function renderTicketTemplate($actionName, $templatePath, array $parameters = [])
  26. {
  27. if ($actionName == 'show') {
  28. $parameters['form_add_ticket_message'] = $this->createCustomForm(TicketMessageType::class, 'newMessageTicket', $parameters, false)->createView();
  29. $parameters['form_ticket_status'] = $this->createCustomForm(TicketStatusType::class, 'ticketStatus', $parameters)->createView();
  30. }
  31. return parent::renderTemplate($actionName, $templatePath, $parameters);
  32. }
  33. public function ticketStatusAction(){
  34. $easyadmin = $this->request->attributes->get('easyadmin');
  35. $ticket = $easyadmin['item'];
  36. $formTicketStatusForm = $this->createForm(TicketStatusType::class, $ticket);
  37. $formTicketStatusForm->handleRequest($this->request);
  38. if ($formTicketStatusForm->isSubmitted() && $formTicketStatusForm->isValid()) {
  39. $this->em->persist($ticket);
  40. $this->em->flush();
  41. $this->utils->addFlash('success', 'success.ticket.statusChange');
  42. } else {
  43. $this->utils->addFlash('error', $formTicketStatusForm->getErrors());
  44. }
  45. $response['flashMessages'] = $this->utils->getFlashMessages();
  46. return new Response(json_encode($response));
  47. }
  48. public function newMessageTicketAction(){
  49. $easyadmin = $this->request->attributes->get('easyadmin');
  50. $ticket = $easyadmin['item'];
  51. $formAddTicketMessage = $this->createForm(TicketMessageType::class);
  52. $formAddTicketMessage->handleRequest($this->request);
  53. if ($formAddTicketMessage->isSubmitted() && $formAddTicketMessage->isValid()) {
  54. $this->ticketUtils->createTicketMessage(array(
  55. 'ticket'=>$ticket,
  56. 'message'=> $formAddTicketMessage->get('message')->getData(),
  57. 'answerByAdmin'=>true
  58. ));
  59. $this->utils->addFlash('success', 'success.ticket.addMessage');
  60. } else {
  61. $this->utils->addFlash('error', $formAddTicketMessage->getErrors());
  62. }
  63. return $this->redirectToRoute('easyadmin', [
  64. 'action' => 'show',
  65. 'entity' => 'Ticket',
  66. 'id' => $ticket->getId()
  67. ]);
  68. }
  69. }