<?php
/**
* Created by PhpStorm.
* User: yural
* Date: 29.01.2018
* Time: 18:24
*/
namespace Slivki\Controller\Admin;
use Slivki\Entity\Notification;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
class AdminNotificationController extends AdminController {
/** @Route("/admin/get_notification_list/{pageParam}") */
public function getNotificationListAction(Request $request, $pageParam = '') {
if (!$request->isXmlHttpRequest()) {
return $this->redirect("/admin");
}
if (!empty($pageParam) and $pageParam == 'page') {
$view = 'Slivki/admin/notifications/notifications_list_page.html.twig';
} else {
$view = 'Slivki/admin/notifications/notifications_list_content.html.twig';
}
$notifications = $this->getDoctrine()->getManager('admin')->getRepository(Notification::class)->findBy(['active' => true], ['createdOn' => 'desc']);
return new JsonResponse(['html' => $this->get('twig')->render($view, ['notifications' => $notifications]), 'count' => count($notifications)]);
}
/** @Route("/admin/disable_notification/{notificationID}") */
public function disableNotificationAction(Request $request, $notificationID) {
if (!$request->isXmlHttpRequest()) {
return $this->redirect("/admin");
}
$entityManager = $this->getDoctrine()->getManager('admin');
$notification = $entityManager->getRepository(Notification::class)->find($notificationID);
$data = ['message' => []];
if (!empty($notification)) {
$notification->setActive(false);
$entityManager->flush($notification);
$data['message'] = array(
'success' => true
);
}
return new JsonResponse($data);
}
}