src/Controller/IndexController.php line 26

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Notification;
  4. use App\Services\ConfigurationService;
  5. use App\Services\NotificationService;
  6. use App\Services\PersonService;
  7. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  8. use Symfony\Component\HttpFoundation\RequestStack;
  9. use Symfony\Component\HttpFoundation\Response;
  10. use Symfony\Component\Routing\Annotation\Route;
  11. use Symfony\Contracts\Translation\TranslatorInterface;
  12. class IndexController extends AbstractController
  13. {
  14.     /**
  15.      * @Route(path="/", name="dashboard", methods={"GET"})
  16.      * @param PersonService $personService
  17.      * @param ConfigurationService $configurationService
  18.      * @return Response
  19.      */
  20.     public function index(PersonService $personServiceConfigurationService $configurationService): Response
  21.     {
  22.         $countPersons $personService->countPersonTypes();
  23.         $goalNumbers $configurationService->getGoalNumbers();
  24.         return $this->render('dashboard.html.twig', [
  25. //            'coordinators' => $countPersons['coordinators'],
  26. //            'operators' => $countPersons['operators'],
  27.             'promoters' => $countPersons['promoters'],
  28.             'promoted' => $countPersons['promoted'],
  29.             'total' => $countPersons['promoters'] + $countPersons['promoted'],
  30. //            'goalCoordinators' => $goalNumbers['coordinators'],
  31. //            'goalOperators' => $goalNumbers['operators'],
  32.             'goalPromoters' => $goalNumbers['promoters'],
  33.             'goalPromoted' => $goalNumbers['promoted']
  34.         ]);
  35.     }
  36.     /**
  37.      * @Route("/chart/person/suburb", methods={"GET"}, name="app_dashboard_person_suburb")
  38.      * @param PersonService $personService
  39.      * @return Response
  40.      */
  41.     public function countPeopleBySuburbs(PersonService $personService): Response
  42.     {
  43.         $result $personService->countPeopleBySuburb();
  44.         return $this->json(['data' => $result'status' => true]);
  45.     }
  46.     /**
  47.      * @Route("/chart/person/program", methods={"GET"}, name="app_dashboard_person_program")
  48.      * @param PersonService $personService
  49.      * @return Response
  50.      */
  51.     public function countPeopleByProgram(PersonService $personService): Response
  52.     {
  53.         $result $personService->countPeopleByHelpPrograms();
  54.         return $this->json(['data' => $result'status' => true]);
  55.     }
  56.     /**
  57.      * @Route("/chart/person/database", methods={"GET"}, name="app_dashboard_person_database")
  58.      * @param PersonService $personService
  59.      * @return Response
  60.      */
  61.     public function countPeopleByExternalDatabase(PersonService $personService): Response
  62.     {
  63.         $personsByDatabase $personService->countPersonsByExternalDatabase();
  64.         $totalPersons $personService->countAll();
  65.         for ($i 0$i count($personsByDatabase); $i++) {
  66.             $percent = ($personsByDatabase[$i]['persons'] * 100) / $totalPersons;
  67.             $personsByDatabase[$i]['persons'] = intval($percent);
  68.         }
  69.         return $this->json(['data' => $personsByDatabase'status' => true]);
  70.     }
  71.     public function sidebar(RequestStack $requestStack): Response
  72.     {
  73.         $currentRequest $requestStack->getMainRequest();
  74.         $currentPath $currentRequest->attributes->get('_route');
  75.         return $this->render('structure/_sidebar.html.twig', [
  76.             'currentPath' => $currentPath
  77.         ]);
  78.     }
  79.     public function renderNotificationCount(NotificationService $notificationService): Response
  80.     {
  81.         return $this->render('structure/_notification_count.html.twig');
  82. //        return $this->render('structure/_notification_count.html.twig', [
  83. //            'count' => $notificationService->countByUser($this->getUser()->getId())
  84. //        ]);
  85.     }
  86.     /**
  87.      * @Route("/notification/find/user", methods={"GET"}, name="app_notification_find_user")
  88.      * @param NotificationService $notificationService
  89.      * @param TranslatorInterface $translator
  90.      * @return \Symfony\Component\HttpFoundation\JsonResponse
  91.      */
  92.     public function findNotificationForUser(NotificationService $notificationServiceTranslatorInterface $translator): Response
  93.     {
  94.         $notifications $notificationService->findByUser($this->getUser()->getId());
  95.         $response = [];
  96.         foreach ($notifications as $notification) {
  97.             $foundType false;
  98.             for ($i 0$i count($response); $i++) {
  99.                 if ($notification->getType() == $response[$i]['type']) {
  100.                     $foundType true;
  101.                     $response[$i]['notifications'][] = [
  102.                         'id' => $notification->getId(),
  103.                         'generatedAt' => date_format($notification->getGeneratedAt(), 'Y-m-d H:i'),
  104.                         'generatedBy' => $notification->getGeneratedBy()->getUserIdentifier(),
  105.                         'extraInfo' => $notification->getExtraInfo()
  106.                     ];
  107.                 }
  108.             }
  109.             if (!$foundType) {
  110.                 $response[] = [
  111.                     'type' => $notification->getType(),
  112.                     'text' => $translator->trans($notification->getType()),
  113.                     'notifications' => [[
  114.                         'id' => $notification->getId(),
  115.                         'generatedAt' => date_format($notification->getGeneratedAt(), 'Y-m-d H:i'),
  116.                         'generatedBy' => $notification->getGeneratedBy()->getUserIdentifier(),
  117.                         'extraInfo' => $notification->getExtraInfo()
  118.                     ]]
  119.                 ];
  120.             }
  121.         }
  122.         return $this->json(['data' => $response'status' => true]);
  123.     }
  124.     /**
  125.      * @Route("/notification/read/{id}", name="app_notification_read")
  126.      * @param int $id
  127.      * @param NotificationService $notificationService
  128.      * @return Response
  129.      */
  130.     public function readNotification(int $idNotificationService $notificationService): Response
  131.     {
  132.         $notification $notificationService->wellRead($id);
  133.         $path 'dashboard';
  134.         $params = [];
  135.         switch ($notification->getType()) {
  136.             case Notification::PERSON_CREATE:
  137.             case Notification::PERSON_UPDATE:
  138.                 $path 'app_person_update';
  139.                 $params['id'] = $notification->getReference();
  140.                 break;
  141.             case Notification::PERSON_REMOVE:
  142.                 $path 'app_person';
  143.                 break;
  144.             case Notification::HELP_PROGRAM_CREATE:
  145.             case Notification::HELP_PROGRAM_UPDATE:
  146.                 $path 'app_help_program_update';
  147.                 $params['id'] = $notification->getReference();
  148.                 break;
  149.             case Notification::HELP_PROGRAM_REMOVE:
  150.                 $path 'app_help_program_remove';
  151.                 break;
  152.             case Notification::SUBURB_CREATE:
  153.             case Notification::SUBURB_UPDATE:
  154.                 $path 'app_suburb_update';
  155.                 break;
  156.             case Notification::SUBURB_REMOVE:
  157.                 $path 'app_suburb_remove';
  158.                 break;
  159.             case Notification::SECTION_CREATE:
  160.             case Notification::SECTION_UPDATE:
  161.                 $path 'app_section_update';
  162.                 $params['id'] = $notification->getReference();
  163.                 break;
  164.             case Notification::SECTION_REMOVE:
  165.                 $path 'app_section_remove';
  166.                 break;
  167.             case Notification::EXTERNAL_DB_CREATE:
  168.             case Notification::EXTERNAL_DB_UPDATE:
  169.                 $path 'app_external_db_update';
  170.                 $params['id'] = $notification->getReference();
  171.                 break;
  172.             case Notification::EXTERNAL_DB_REMOVE:
  173.                 $path 'app_external_db_remove';
  174.                 break;
  175.             case Notification::USER_CREATE:
  176.             case Notification::USER_UPDATE:
  177.                 $path 'app_user_update';
  178.                 $params['id'] = $notification->getReference();
  179.                 break;
  180.             case Notification::USER_REMOVE:
  181.                 $path 'app_user_remove';
  182.         }
  183.         return $this->redirectToRoute($path$params);
  184.     }
  185. }