|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- <?php
-
- namespace Lc\ShopBundle\Controller\Backend;
-
- use Doctrine\ORM\EntityManagerInterface;
- use EasyCorp\Bundle\EasyAdminBundle\Event\EasyAdminEvents;
- use FOS\UserBundle\Model\UserManagerInterface;
- use Lc\ShopBundle\Form\Backend\Ticket\TicketMessageType;
- use Lc\ShopBundle\Form\Backend\Ticket\TicketStatusType;
- use Lc\ShopBundle\Model\Ticket;
- use Lc\ShopBundle\Services\UtilsManager;
- use Mailjet\MailjetSwiftMailer\SwiftMailer\MailjetTransport;
- use Symfony\Component\HttpFoundation\Response;
- use Symfony\Component\Security\Core\Security;
- use Symfony\Contracts\Translation\TranslatorInterface;
-
- class TicketController extends AdminController
- {
- protected $ticketUtils;
- public function __construct(Security $security, UserManagerInterface $userManager, EntityManagerInterface $em, MailjetTransport $mailjetTransport, UtilsManager $utilsManager, TranslatorInterface $translator)
- {
- $this->ticketUtils = $utilsManager->getTicketUtils();
- parent::__construct($security, $userManager, $em, $mailjetTransport, $utilsManager, $translator);
-
- }
-
-
- protected function createListQueryBuilder($entityClass, $sortDirection, $sortField = null, $dqlFilter = null)
- {
-
- $queryBuilder = parent::createListQueryBuilder($entityClass, $sortDirection, $sortField, $dqlFilter);
-
- if ($this->filtersForm->get('status')->getData() === null) {
- $queryBuilder->andWhere('entity.status LIKE :open OR entity.status LIKE :beingprocessed');
- $queryBuilder->setParameter('open', Ticket::TICKET_STATUS_OPEN);
- $queryBuilder->setParameter('beingprocessed', Ticket::TICKET_STATUS_BEING_PROCESSED);
- }
-
- return $queryBuilder;
- }
-
- public function showAction()
- {
- $this->dispatch(EasyAdminEvents::PRE_SHOW);
-
- $id = $this->request->query->get('id');
- $easyadmin = $this->request->attributes->get('easyadmin');
- $entity = $easyadmin['item'];
-
- $fields = $this->entity['show']['fields'];
- $deleteForm = $this->createDeleteForm($this->entity['name'], $id);
-
- $this->dispatch(EasyAdminEvents::POST_SHOW, [
- 'deleteForm' => $deleteForm,
- 'fields' => $fields,
- 'entity' => $entity,
- ]);
-
- $parameters = [
- 'entity' => $entity,
- 'fields' => $fields,
- 'delete_form' => $deleteForm->createView(),
- ];
-
- return $this->executeDynamicMethod('render<EntityName>Template', ['show', $this->entity['templates']['show'], $parameters]);
- }
-
-
-
- public function renderTicketTemplate($actionName, $templatePath, array $parameters = [])
- {
- if ($actionName == 'show') {
- $parameters['form_add_ticket_message'] = $this->createCustomForm(TicketMessageType::class, 'newMessageTicket', $parameters, false)->createView();
- $parameters['form_ticket_status'] = $this->createCustomForm(TicketStatusType::class, 'ticketStatus', $parameters)->createView();
- }
- return parent::renderTemplate($actionName, $templatePath, $parameters);
-
- }
-
-
- public function ticketStatusAction(){
- $easyadmin = $this->request->attributes->get('easyadmin');
- $ticket = $easyadmin['item'];
-
- $formTicketStatusForm = $this->createForm(TicketStatusType::class, $ticket);
- $formTicketStatusForm->handleRequest($this->request);
-
- if ($formTicketStatusForm->isSubmitted() && $formTicketStatusForm->isValid()) {
- $this->em->persist($ticket);
- $this->em->flush();
-
- $this->utils->addFlash('success', 'success.ticket.statusChange');
- } else {
- $this->utils->addFlash('error', $formTicketStatusForm->getErrors());
- }
- $response['flashMessages'] = $this->utils->getFlashMessages();
-
- return new Response(json_encode($response));
- }
-
- public function newMessageTicketAction(){
- $easyadmin = $this->request->attributes->get('easyadmin');
- $ticket = $easyadmin['item'];
-
- $formAddTicketMessage = $this->createForm(TicketMessageType::class);
- $formAddTicketMessage->handleRequest($this->request);
-
- if ($formAddTicketMessage->isSubmitted() && $formAddTicketMessage->isValid()) {
- $this->ticketUtils->createTicketMessage(array(
- 'ticket'=>$ticket,
- 'message'=> $formAddTicketMessage->get('message')->getData(),
- 'answerByAdmin'=>true
- ));
-
- $this->utils->addFlash('success', 'success.ticket.addMessage');
- } else {
- $this->utils->addFlash('error', $formAddTicketMessage->getErrors());
- }
-
- return $this->redirectToRoute('easyadmin', [
- 'action' => 'show',
- 'entity' => 'Ticket',
- 'id' => $ticket->getId()
- ]);
- }
- }
|