<?php
// src/Controller/IndexController.php
namespace App\Controller;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\Security\Core\Security;
use Symfony\Component\HttpFoundation\Request;
use App\Service\HelperService;
use App\Entity\UrlServ;
use App\Entity\AlsReportData;
use App\Entity\CipiaEventLog;
use App\Entity\PanicAlert;
use Nzo\UrlEncryptorBundle\Annotations\ParamDecryptor;
use Nzo\UrlEncryptorBundle\Annotations\ParamEncryptor;
use App\Entity\Calendar;
class IndexController extends AbstractController
{
private $session;
public function __construct(SessionInterface $session)
{
$this->session = $session;
}
/**
* @Route("/", name="homepage", methods={"GET", "POST"})
*/
public function homepage(Request $request): Response
{
return $this->redirectToRoute('app_login', [], Response::HTTP_SEE_OTHER);
}
/**
* @Route("/reminders", name="homepage_custom_1", methods={"GET", "POST"})
*/
public function getReminders(Request $request): Response
{
$mp["dp"] = 0;
$user = $this->getUser();
$calendar_today_notifications = $this->getDoctrine()->getRepository(Calendar::class)->getReminders(date("Y-m-d"), $user->getId());
$today_notifications_amount = count($calendar_today_notifications);
return $this->render('reminders.html.twig', array(
"today_notifications_amount" => $today_notifications_amount,
"permits" => $mp
));
}
//"/notifications-modal", name="notifications_modal"
/**
* @Route("/notifications-modal", name="homepage_custom_3")
*/
public function notificationsModalAction(Request $request) {
//$userData = $this->get("session")->get("userData");
$user = $this->getUser();
return $this->render('Reminders/modal_info_calendar.html.twig', array(
"user" => $user,
"calendar_modal_name" => "detailsModalNotification"
));
}
//"/view-fleet/{plate}", name="website_view_fleet"
/**
* @Route("/view-fleet/{plate}", name="homepage_custom_2")
*/
public function viewFleetAction (Request $request, HelperService $helperService)
{
$em = $this->getDoctrine ()->getManager ();
$sessionHelper = new SessionHelper();
$plate = $request->get ( "plate" );
$panicAlert = array();
$alertLog = $em->getRepository(UrlServ::class)->findOneBy(array("urlServId" => 1));
$url = $alertLog->getUrl();
//$url = "https://megadashboard.disatelgps.com/?u=gt-disatel&s=".$plate;
if (substr($url, -3) !== '&s=') {
// Si no termina con '&s=', agregarlo
$url .= '&s=';
}
$url = $url.urlencode($plate);
$url = str_replace(" ", "%20", $url);
$objApi = $helperService->open_url($url);
$api = json_decode($objApi);
if ($api && $api[0]){
$panicAlert['latitude'] = $api[0]->Latitude;
$panicAlert['longitude'] = $api[0]->Longitude;
$panicAlert['address'] = $api[0]->Address;
$panicAlert['plate'] = $api[0]->Fleet;
$panicAlert['fleet'] = $api[0]->Plate;
$panicAlert['name'] = $api[0]->Name;
}else{
$panicAlert['latitude'] = "";
$panicAlert['longitude'] = "";
$panicAlert['address'] = "";
$panicAlert['plate'] = "";
$panicAlert['fleet'] = "";
$panicAlert['name'] = "";
}
return $this->render('ViewMap/index.html.twig', array (
"alert" => $panicAlert,
"desc" => true
));
}
//"/view-map-als-report/{id}", name="website_view_map_als_report"
/**
*
* @Route("/view-map-als-report/{id}", name="homepage_custom_4")
* @ParamDecryptor({"id"})
*/
public function viewMapAlsReportAction (Request $request,$id)
{
$em = $this->getDoctrine ()->getManager ();
//$md5Id = $request->get ( "id" );
//$alsReportDataId = $em->getRepository ( 'AppBundle:AlsReportData' )->findOneByMd5Id ( $md5Id );
$alsReportData = $em->getRepository ( AlsReportData::class )->findOneBy ( array (
"alsReportDataId" => $id
) );
return $this->render('ViewMapAlsReport/index.html.twig', array (
"alsReportData" => $alsReportData,
"desc" => true
));
}
//"/view-map-cipia/{id}", name="website_view_map_cipia"
/**
*
* @Route("/view-map-cipia/{id}", name="homepage_custom_5")
* @ParamDecryptor({"id"})
*/
public function viewMapCipiaAction (Request $request, $id)
{
$em = $this->getDoctrine ()->getManager ();
//md5Id = $request->get ( "id" );
//$cipiaEventLogId = $em->getRepository ( 'AppBundle:CipiaEventLog' )->findOneByMd5Id ( $md5Id );
$cipiaEventLog = $em->getRepository ( CipiaEventLog::class )->findOneBy ( array (
"cipiaEventLogId" => $id
) );
return $this->render('ViewMapCipia/index.html.twig', array (
"cipiaEventLog" => $cipiaEventLog,
"desc" => true
));
}
//"/view-map/{id}", name="website_view_map"
/**
* @Route("/view-map/{id}", name="homepage_custom_6")
* @ParamDecryptor({"id"})
*/
public function viewMapAction (Request $request,$id)
{
$em = $this->getDoctrine ()->getManager ();
$panicAlert = $em->getRepository ( PanicAlert::class )->findOneBy ( array (
"panicAlertId" => $id
) );
return $this->render('ViewMap/index.html.twig', array (
"alert" => $panicAlert,
"desc" => true
));
}
public function mainNav(Request $request): Response
{
$lastUsername = $this->session->get(Security::LAST_USERNAME);
$userData = $request->getSession()->get($lastUsername);
$menu = $this->session->get($lastUsername."_menu");
$selected_module = $request->getSession()->get("module_id");
/*echo "<pre>";
print_r($menu);
echo "</pre>";
exit;*/
return $this->render('main_menu.html.twig', [
"userData" => $userData,
'userModules' => $menu,
"menuId" => $selected_module,
"roleStaff" => ""
]);
}
public function profile(Request $request): Response
{
$lastUsername = $this->session->get(Security::LAST_USERNAME);
$userData = $request->getSession()->get($lastUsername);
// replace this example code with whatever you need
return $this->render('profile.html.twig', array(
"userData" => $userData,
));
}
}