src/Controller/Admin/AdminNotificationController.php line 18

Open in your IDE?
  1. <?php
  2. /**
  3.  * Created by PhpStorm.
  4.  * User: yural
  5.  * Date: 29.01.2018
  6.  * Time: 18:24
  7.  */
  8. namespace Slivki\Controller\Admin;
  9. use Slivki\Entity\Notification;
  10. use Symfony\Component\Routing\Annotation\Route;
  11. use Symfony\Component\HttpFoundation\JsonResponse;
  12. use Symfony\Component\HttpFoundation\Request;
  13. class AdminNotificationController extends AdminController {
  14.     /** @Route("/admin/get_notification_list/{pageParam}") */
  15.     public function getNotificationListAction(Request $request$pageParam '') {
  16.         if (!$request->isXmlHttpRequest()) {
  17.             return $this->redirect("/admin");
  18.         }
  19.         if (!empty($pageParam) and $pageParam == 'page') {
  20.             $view 'Slivki/admin/notifications/notifications_list_page.html.twig';
  21.         } else {
  22.             $view 'Slivki/admin/notifications/notifications_list_content.html.twig';
  23.         }
  24.         $notifications $this->getDoctrine()->getManager('admin')->getRepository(Notification::class)->findBy(['active' => true], ['createdOn' => 'desc']);
  25.         return new JsonResponse(['html' => $this->get('twig')->render($view, ['notifications' => $notifications]), 'count' => count($notifications)]);
  26.     }
  27.     /** @Route("/admin/disable_notification/{notificationID}") */
  28.     public function disableNotificationAction(Request $request$notificationID) {
  29.         if (!$request->isXmlHttpRequest()) {
  30.             return $this->redirect("/admin");
  31.         }
  32.         $entityManager $this->getDoctrine()->getManager('admin');
  33.         $notification $entityManager->getRepository(Notification::class)->find($notificationID);
  34.         $data = ['message' => []];
  35.         if (!empty($notification)) {
  36.             $notification->setActive(false);
  37.             $entityManager->flush($notification);
  38.             $data['message'] = array(
  39.                 'success' => true
  40.             );
  41.         }
  42.         return new JsonResponse($data);
  43.     }
  44. }