<?php
// src/Controller/DashboardController.php
namespace App\Controller\Web;
use App\Entity\Sensor;
use App\Entity\GpioValue;
use App\Entity\Elevator;
use App\Form\ContractorDisorderMessageType;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Core\Security as SFSecurity;
class DashboardController extends AbstractController
{
private $security;
public function __construct(SFSecurity $security)
{
$this->security = $security;
}
/**
* @Route("/", name="aco_dashboard")
*
* @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')")
*/
public function checkDashboard(Request $request)
{
if ($this->security->isGranted('ROLE_ELV')) {
return $this->redirectToRoute('elevator_dashboard');
}
if ($this->security->isGranted('ROLE_NEA')) {
return $this->redirectToRoute('nea_dashboard');
}
throw new \Exception(AccessDeniedException::class);
// exit('Leider ist ein Fehler aufgetreten.');
}
/**
* @Route("/elevator", name="elevator")
*/
public function elevatorOverviewAction(Request $request)
{
$em = $this->getDoctrine()->getManager();
$currentYear = date('Y');
$sensors = $em->getRepository(Sensor::class)->findAll();
$statsByMonth = $em->getRepository(Sensor::class)->getStatsByMonth($sensors, $currentYear);
$devicesWorking = $em->getRepository(Elevator::class)->findByState(Elevator::ELEVATOR_STATE_OK);
$devicesMaintenance = $em->getRepository(Elevator::class)->findByState(Elevator::ELEVATOR_STATE_MAINTENANCE);
$devicesError = $em->getRepository(Elevator::class)->findByState(Elevator::ELEVATOR_STATE_MALFUNCTION);
$tuevMaengel = $em->getRepository(Elevator::class)->getAllTuevErrors();
$awmErrors = $em->getRepository(Elevator::class)->getAllAWMErrors();
$elevators = $em->getRepository(Elevator::class)->findAll();
return $this->render('admin/elevator/index.html.twig', [
'errors' => count($devicesError),
'elevatorErrors' => $devicesError,
'warnings' => count($devicesMaintenance),
'working' => count($devicesWorking),
'tuevMaengel' => count($tuevMaengel),
'awmErrors' => count($awmErrors),
'stats' => $statsByMonth,
'elevators' => $elevators,
]);
}
/**
* @Route("/playSound", name="play_sound")
*/
public function playSoundAction(Request $request)
{
return $this->render('admin/elevator/playSound.html.twig');
}
/**
* @Route("/showAwmDetail/{elevatorId}", name="showAwmDetail")
*
* @param mixed $elevatorId
*/
public function showAwmDetailsAction(Request $request, $elevatorId)
{
$em = $this->getDoctrine()->getManager();
$elvRepo = $em->getRepository(Elevator::class);
$elevator = $elvRepo->find($elevatorId);
$gpvRepo = $em->getRepository(GpioValue::class);
if ($request->isXmlHttpRequest()) {
return $this->render('admin/elevator/showAwmDetail.html.twig', [
'elevator' => $elevator,
]);
}
return $this->render('admin/elevator/showAwmDetailFull.html.twig', [
'elevator' => $elevator,
]);
}
public function renderContractorDisorderComment()
{
$form = $this->createForm(ContractorDisorderMessageType::class);
return $this->render('admin/contractorDisorderMessage.html.twig', ['messageForm' => $form->createView()]);
}
}