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_ELV')) {
  28.             return $this->redirectToRoute('elevator_dashboard');
  29.         }
  30.         if ($this->security->isGranted('ROLE_NEA')) {
  31.             return $this->redirectToRoute('nea_dashboard');
  32.         }
  33.         throw new \Exception(AccessDeniedException::class);
  34.         // exit('Leider ist ein Fehler aufgetreten.');
  35.     }
  36.     /**
  37.      * @Route("/elevator", name="elevator")
  38.      */
  39.     public function elevatorOverviewAction(Request $request)
  40.     {
  41.         $em $this->getDoctrine()->getManager();
  42.         $currentYear date('Y');
  43.         $sensors $em->getRepository(Sensor::class)->findAll();
  44.         $statsByMonth $em->getRepository(Sensor::class)->getStatsByMonth($sensors$currentYear);
  45.         $devicesWorking $em->getRepository(Elevator::class)->findByState(Elevator::ELEVATOR_STATE_OK);
  46.         $devicesMaintenance $em->getRepository(Elevator::class)->findByState(Elevator::ELEVATOR_STATE_MAINTENANCE);
  47.         $devicesError $em->getRepository(Elevator::class)->findByState(Elevator::ELEVATOR_STATE_MALFUNCTION);
  48.         $tuevMaengel $em->getRepository(Elevator::class)->getAllTuevErrors();
  49.         $awmErrors $em->getRepository(Elevator::class)->getAllAWMErrors();
  50.         $elevators $em->getRepository(Elevator::class)->findAll();
  51.         return $this->render('admin/elevator/index.html.twig', [
  52.             'errors' => count($devicesError),
  53.             'elevatorErrors' => $devicesError,
  54.             'warnings' => count($devicesMaintenance),
  55.             'working' => count($devicesWorking),
  56.             'tuevMaengel' => count($tuevMaengel),
  57.             'awmErrors' => count($awmErrors),
  58.             'stats' => $statsByMonth,
  59.             'elevators' => $elevators,
  60.         ]);
  61.     }
  62.     /**
  63.      * @Route("/playSound", name="play_sound")
  64.      */
  65.     public function playSoundAction(Request $request)
  66.     {
  67.         return $this->render('admin/elevator/playSound.html.twig');
  68.     }
  69.     /**
  70.      * @Route("/showAwmDetail/{elevatorId}", name="showAwmDetail")
  71.      *
  72.      * @param mixed $elevatorId
  73.      */
  74.     public function showAwmDetailsAction(Request $request$elevatorId)
  75.     {
  76.         $em $this->getDoctrine()->getManager();
  77.         $elvRepo $em->getRepository(Elevator::class);
  78.         $elevator $elvRepo->find($elevatorId);
  79.         $gpvRepo $em->getRepository(GpioValue::class);
  80.         if ($request->isXmlHttpRequest()) {
  81.             return $this->render('admin/elevator/showAwmDetail.html.twig', [
  82.                 'elevator' => $elevator,
  83.             ]);
  84.         }
  85.         return $this->render('admin/elevator/showAwmDetailFull.html.twig', [
  86.             'elevator' => $elevator,
  87.         ]);
  88.     }
  89.     public function renderContractorDisorderComment()
  90.     {
  91.         $form $this->createForm(ContractorDisorderMessageType::class);
  92.         return $this->render('admin/contractorDisorderMessage.html.twig', ['messageForm' => $form->createView()]);
  93.     }
  94. }