src/Controller/DefaultController.php line 35

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Notification;
  4. use App\Service\NotificationService;
  5. use Exception;
  6. use Symfony\Component\HttpFoundation\RedirectResponse;
  7. use Symfony\Component\HttpFoundation\Response;
  8. use Symfony\Component\Routing\Annotation\Route;
  9. class DefaultController extends AbstractController
  10. {
  11.     /**
  12.      * @var NotificationService
  13.      */
  14.     protected NotificationService $notificationService;
  15.     /**
  16.      * @param NotificationService $notificationService
  17.      */
  18.     public function __construct(NotificationService $notificationService)
  19.     {
  20.         $this->notificationService $notificationService;
  21.     }
  22.     /**
  23.      * @Route(
  24.      *     "/",
  25.      *     name="app.home"
  26.      * )
  27.      *
  28.      * @return RedirectResponse
  29.      */
  30.     public function indexAction(): RedirectResponse
  31.     {
  32.         if ($this->isLoggedIn()) {
  33.             if ($this->isGranted('ROLE_INVENTORY')) {
  34.                 return $this->redirectResponse('app.product.inventory');
  35.             } else {
  36.                 return $this->redirectResponse('app.sales_case.index');
  37.             }
  38.         }
  39.         return $this->redirectResponse('nucleos_user_security_login');
  40.     }
  41.     /**
  42.      * @Route(
  43.      *     "/notifications/{notification}/acknowledge",
  44.      *     name="app.notifications.acknowledge",
  45.      *     requirements={"notification" = "\d+"}
  46.      * )
  47.      *
  48.      * @param Notification $notification
  49.      *
  50.      * @return RedirectResponse
  51.      */
  52.     public function notificationsAcknowledgeAction(Notification $notification): RedirectResponse
  53.     {
  54.         try {
  55.             $this->notificationService->delete($notification);
  56.             $this->flashSuccess('entity.success.acknowledge', [], 'Notification');
  57.         } catch (Exception $e) {
  58.             $this->flashError('entity.error.acknowledge', [], 'Notification');
  59.             if ($this->getCurrentUser()->isSuperAdmin()) {
  60.                 $this->flashError($e->getMessage());
  61.             }
  62.         }
  63.         return $this->redirectResponse('app.notifications');
  64.     }
  65.     /**
  66.      * @Route(
  67.      *     "/notifications",
  68.      *     name="app.notifications"
  69.      * )
  70.      *
  71.      * @return Response
  72.      */
  73.     public function notificationsAction(): Response
  74.     {
  75.         return $this->render(
  76.             'Default/notifications.html.twig',
  77.             [
  78.                 'present'  => $this->notificationService->getPresent(),
  79.                 'upcoming' => $this->notificationService->getUpcoming(),
  80.             ]
  81.         );
  82.     }
  83.     /**
  84.      * @Route(
  85.      *     "/notifications/alert",
  86.      *     name="app.notifications.alert"
  87.      * )
  88.      *
  89.      * @return Response
  90.      */
  91.     public function notificationsAlertAction(): Response
  92.     {
  93.         if (!$this->isGranted('ROLE_BASIC')) {
  94.             return new Response('');
  95.         }
  96.         return $this->render(
  97.             'Default/notificationsAlert.html.twig',
  98.             [
  99.                 'notifications' => $this->notificationService->getPresent(),
  100.             ]
  101.         );
  102.     }
  103. }