src/Controller/Web/DashboardController.php line 31

Open in your IDE?
  1. <?php
  2. // src/Controller/DashboardController.php
  3. namespace App\Controller\Web;
  4. use App\Entity\Sensor;
  5. use App\Entity\GpioValue;
  6. use App\Entity\Elevator;
  7. use App\Form\ContractorDisorderMessageType;
  8. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
  9. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  10. use Symfony\Component\HttpFoundation\Request;
  11. use Symfony\Component\Routing\Annotation\Route;
  12. use Symfony\Component\Security\Core\Security as SFSecurity;
  13. class DashboardController extends AbstractController
  14. {
  15.     private $security;
  16.     public function __construct(SFSecurity $security)
  17.     {
  18.         $this->security $security;
  19.     }
  20.     /**
  21.      * @Route("/", name="aco_dashboard")
  22.      *
  23.      * @Security("is_granted('ROLE_SUPER_ADMIN') or is_granted('ROLE_OPERATOR') or is_granted('ROLE_CUSTODIAN') or is_granted('ROLE_DL') or is_granted('ROLE_SBS') or is_granted('ROLE_ZUES') or is_granted('ROLE_TANK') or is_granted('ROLE_INSTALL') or is_granted('ROLE_CLIENT') or is_granted('ROLE_LIFTMANAGER')")
  24.      */
  25.     public function checkDashboard(Request $request)
  26.     {
  27.         if ($this->security->isGranted('ROLE_SUPER_ADMIN')
  28.             && 'default' !== $this->getUser()->getStartDashboard()) {
  29.             return $this->redirectToRoute('super_admin_dashboard');
  30.         }
  31.         if ($this->security->isGranted('ROLE_ELV')) {
  32.             return $this->redirectToRoute('elevator_dashboard');
  33.         }
  34.         if ($this->security->isGranted('ROLE_NEA')) {
  35.             return $this->redirectToRoute('nea_dashboard');
  36.         }
  37.         throw new \Exception(AccessDeniedException::class);
  38.         // exit('Leider ist ein Fehler aufgetreten.');
  39.     }
  40.     /**
  41.      * @Route("/elevator", name="elevator")
  42.      */
  43.     public function elevatorOverviewAction(Request $request)
  44.     {
  45.         $em $this->getDoctrine()->getManager();
  46.         $currentYear date('Y');
  47.         $sensors $em->getRepository(Sensor::class)->findAll();
  48.         $statsByMonth $em->getRepository(Sensor::class)->getStatsByMonth($sensors$currentYear);
  49.         $devicesWorking $em->getRepository(Elevator::class)->findByState(Elevator::ELEVATOR_STATE_OK);
  50.         $devicesMaintenance $em->getRepository(Elevator::class)->findByState(Elevator::ELEVATOR_STATE_MAINTENANCE);
  51.         $devicesError $em->getRepository(Elevator::class)->findByState(Elevator::ELEVATOR_STATE_MALFUNCTION);
  52.         $tuevMaengel $em->getRepository(Elevator::class)->getAllTuevErrors();
  53.         $awmErrors $em->getRepository(Elevator::class)->getAllAWMErrors();
  54.         $elevators $em->getRepository(Elevator::class)->findAll();
  55.         return $this->render('admin/elevator/index.html.twig', [
  56.             'errors' => count($devicesError),
  57.             'elevatorErrors' => $devicesError,
  58.             'warnings' => count($devicesMaintenance),
  59.             'working' => count($devicesWorking),
  60.             'tuevMaengel' => count($tuevMaengel),
  61.             'awmErrors' => count($awmErrors),
  62.             'stats' => $statsByMonth,
  63.             'elevators' => $elevators,
  64.         ]);
  65.     }
  66.     /**
  67.      * @Route("/playSound", name="play_sound")
  68.      */
  69.     public function playSoundAction(Request $request)
  70.     {
  71.         return $this->render('admin/elevator/playSound.html.twig');
  72.     }
  73.     /**
  74.      * @Route("/showAwmDetail/{elevatorId}", name="showAwmDetail")
  75.      *
  76.      * @param mixed $elevatorId
  77.      */
  78.     public function showAwmDetailsAction(Request $request$elevatorId)
  79.     {
  80.         $em $this->getDoctrine()->getManager();
  81.         $elvRepo $em->getRepository(Elevator::class);
  82.         $elevator $elvRepo->find($elevatorId);
  83.         if (!$elevator || !$elvRepo->companyHasPermission($this->getUser(), $elevator)) {
  84.             throw $this->createAccessDeniedException();
  85.         }
  86.         $gpvRepo $em->getRepository(GpioValue::class);
  87.         if ($request->isXmlHttpRequest()) {
  88.             return $this->render('admin/elevator/showAwmDetail.html.twig', [
  89.                 'elevator' => $elevator,
  90.             ]);
  91.         }
  92.         return $this->render('admin/elevator/showAwmDetailFull.html.twig', [
  93.             'elevator' => $elevator,
  94.         ]);
  95.     }
  96.     public function renderContractorDisorderComment()
  97.     {
  98.         $form $this->createForm(ContractorDisorderMessageType::class);
  99.         return $this->render('admin/contractorDisorderMessage.html.twig', ['messageForm' => $form->createView()]);
  100.     }
  101. }