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.

TicketController.php 4.8KB

il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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\Services\UtilsManager;
  9. use Mailjet\MailjetSwiftMailer\SwiftMailer\MailjetTransport;
  10. use Symfony\Component\HttpFoundation\Response;
  11. use Symfony\Component\Security\Core\Security;
  12. use Symfony\Contracts\Translation\TranslatorInterface;
  13. class TicketController extends AdminController
  14. {
  15. protected $ticketUtils;
  16. public function __construct(Security $security, UserManagerInterface $userManager, EntityManagerInterface $em, MailjetTransport $mailjetTransport, UtilsManager $utilsManager, TranslatorInterface $translator)
  17. {
  18. $this->ticketUtils = $utilsManager->getTicketUtils();
  19. parent::__construct($security, $userManager, $em, $mailjetTransport, $utilsManager, $translator);
  20. }
  21. public function showAction()
  22. {
  23. $this->dispatch(EasyAdminEvents::PRE_SHOW);
  24. $id = $this->request->query->get('id');
  25. $easyadmin = $this->request->attributes->get('easyadmin');
  26. $entity = $easyadmin['item'];
  27. $fields = $this->entity['show']['fields'];
  28. $deleteForm = $this->createDeleteForm($this->entity['name'], $id);
  29. $this->dispatch(EasyAdminEvents::POST_SHOW, [
  30. 'deleteForm' => $deleteForm,
  31. 'fields' => $fields,
  32. 'entity' => $entity,
  33. ]);
  34. $parameters = [
  35. 'entity' => $entity,
  36. 'fields' => $fields,
  37. 'delete_form' => $deleteForm->createView(),
  38. ];
  39. return $this->executeDynamicMethod('render<EntityName>Template', ['show', $this->entity['templates']['show'], $parameters]);
  40. }
  41. /**
  42. * The method that is executed when the user performs a 'show' action on an entity.
  43. *
  44. * @return Response
  45. */
  46. public function renderTicketTemplate($actionName, $templatePath, array $parameters = [])
  47. {
  48. if ($actionName == 'show') {
  49. $parameters['form_add_ticket_message'] = $this->createCustomForm(TicketMessageType::class, 'newMessageTicket', $parameters, false)->createView();
  50. $parameters['form_ticket_status'] = $this->createCustomForm(TicketStatusType::class, 'ticketStatus', $parameters)->createView();
  51. }
  52. return parent::renderTemplate($actionName, $templatePath, $parameters);
  53. }
  54. public function ticketStatusAction(){
  55. $easyadmin = $this->request->attributes->get('easyadmin');
  56. $ticket = $easyadmin['item'];
  57. $formTicketStatusForm = $this->createForm(TicketStatusType::class, $ticket);
  58. $formTicketStatusForm->handleRequest($this->request);
  59. if ($formTicketStatusForm->isSubmitted() && $formTicketStatusForm->isValid()) {
  60. $this->em->persist($ticket);
  61. $this->em->flush();
  62. $this->utils->addFlash('success', 'success.ticket.statusChange');
  63. } else {
  64. $this->utils->addFlash('error', $formTicketStatusForm->getErrors());
  65. }
  66. $response['flashMessages'] = $this->utils->getFlashMessages();
  67. return new Response(json_encode($response));
  68. }
  69. public function newMessageTicketAction(){
  70. $easyadmin = $this->request->attributes->get('easyadmin');
  71. $ticket = $easyadmin['item'];
  72. $formAddTicketMessage = $this->createForm(TicketMessageType::class);
  73. $formAddTicketMessage->handleRequest($this->request);
  74. if ($formAddTicketMessage->isSubmitted() && $formAddTicketMessage->isValid()) {
  75. $this->ticketUtils->createTicketMessage(array(
  76. 'ticket'=>$ticket,
  77. 'message'=> $formAddTicketMessage->get('message')->getData(),
  78. 'answerByAdmin'=>true
  79. ));
  80. $this->utils->addFlash('success', 'success.ticket.addMessage');
  81. } else {
  82. $this->utils->addFlash('error', $formAddTicketMessage->getErrors());
  83. }
  84. return $this->redirectToRoute('easyadmin', [
  85. 'action' => 'show',
  86. 'entity' => 'Ticket',
  87. 'id' => $ticket->getId()
  88. ]);
  89. }
  90. }