src/Controller/DefaultController.php line 29

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