ReminderController.php 2.1KB

hace 4 años
hace 4 años
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. namespace Lc\ShopBundle\Controller\Backend;
  3. use EasyCorp\Bundle\EasyAdminBundle\Event\EasyAdminEvents;
  4. use Lc\ShopBundle\Form\Backend\Common\ReminderType;
  5. use Symfony\Component\HttpFoundation\Response;
  6. class ReminderController extends AdminController
  7. {
  8. public function renderTemplate($actionName, $templatePath, array $parameters = [])
  9. {
  10. if($this->request->isXmlHttpRequest() && ($actionName == 'new' || $actionName == 'edit')) {
  11. $response['flashMessages'] = $this->utils->getFlashMessages();
  12. $response['data'] = $this->render('@LcShop/backend/default/modal/edit_reminder.twig', $parameters)->getContent();
  13. return new Response(json_encode($response));
  14. }else{
  15. return parent::renderTemplate($actionName, $templatePath, $parameters);
  16. }
  17. }
  18. protected function redirectToReferrer(){
  19. $action = $this->request->query->get('action');
  20. if($action == 'new'){
  21. $this->utils->addFlash('success', 'success.reminder.add');
  22. }elseif($action == 'edit'){
  23. $this->utils->addFlash('success', 'success.reminder.edit');
  24. }elseif($action == ' setReminderDone'){
  25. $this->utils->addFlash('success', 'success.reminder.done');
  26. }
  27. if($this->request->isXmlHttpRequest()) {
  28. $response['flashMessages'] = $this->utils->getFlashMessages();
  29. return new Response(json_encode($response));
  30. }
  31. }
  32. public function setReminderDoneAction(){
  33. $id = $this->request->query->get('id');
  34. $done = $this->request->query->get('done');
  35. $easyadmin = $this->request->attributes->get('easyadmin');
  36. $reminder = $easyadmin['item'];
  37. $reminder->setDone($done);
  38. $this->em->persist($reminder);
  39. $this->em->flush();
  40. return $this->redirectToReferrer();
  41. }
  42. }