src/Controller/IndexController.php line 38

Open in your IDE?
  1. <?php
  2. // src/Controller/IndexController.php
  3. namespace App\Controller;
  4. use Symfony\Component\HttpFoundation\Response;
  5. use Symfony\Component\Routing\Annotation\Route;
  6. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  7. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  8. use Symfony\Component\Security\Core\Security;
  9. use Symfony\Component\HttpFoundation\Request;
  10. use App\Service\HelperService;
  11. use App\Entity\UrlServ;
  12. use App\Entity\AlsReportData;
  13. use App\Entity\CipiaEventLog;
  14. use App\Entity\PanicAlert;
  15. use Nzo\UrlEncryptorBundle\Annotations\ParamDecryptor;
  16. use Nzo\UrlEncryptorBundle\Annotations\ParamEncryptor;
  17. use App\Entity\Calendar;
  18. class IndexController extends AbstractController
  19. {
  20.     
  21.    private $session;
  22.     
  23.    public function __construct(SessionInterface $session)
  24.    {
  25.       $this->session $session;
  26.    }
  27.     /**
  28.      * @Route("/", name="homepage", methods={"GET", "POST"})
  29.      */
  30.     public function homepage(Request $request): Response
  31.     {
  32.               
  33.         return $this->redirectToRoute('app_login', [], Response::HTTP_SEE_OTHER);
  34.         
  35.     }
  36.     
  37.     /**
  38.       * @Route("/reminders", name="homepage_custom_1", methods={"GET", "POST"})
  39.       */
  40.      public function getReminders(Request $request): Response
  41.      {
  42.          
  43.          $mp["dp"] = 0;    
  44.          $user $this->getUser();
  45.          $calendar_today_notifications $this->getDoctrine()->getRepository(Calendar::class)->getReminders(date("Y-m-d"), $user->getId());
  46.          $today_notifications_amount count($calendar_today_notifications);
  47.          
  48.          return $this->render('reminders.html.twig', array(
  49.             "today_notifications_amount" => $today_notifications_amount,
  50.             "permits" => $mp
  51.          ));
  52.      }
  53.      
  54.      //"/notifications-modal", name="notifications_modal"
  55.      /**
  56.        * @Route("/notifications-modal", name="homepage_custom_3")
  57.        */
  58.      public function notificationsModalAction(Request $request) {
  59.          //$userData = $this->get("session")->get("userData");
  60.          $user $this->getUser();
  61.          return $this->render('Reminders/modal_info_calendar.html.twig', array(
  62.            "user" => $user,
  63.            "calendar_modal_name" => "detailsModalNotification"        
  64.          ));
  65.       }
  66.       
  67.      
  68.      //"/view-fleet/{plate}", name="website_view_fleet"
  69.      /**
  70.        * @Route("/view-fleet/{plate}", name="homepage_custom_2")
  71.        */
  72.       public function viewFleetAction (Request $requestHelperService $helperService)
  73.       {
  74.           $em $this->getDoctrine ()->getManager ();
  75.           $sessionHelper = new SessionHelper();
  76.      
  77.           $plate $request->get "plate" );
  78.         
  79.           $panicAlert = array();
  80.           $alertLog $em->getRepository(UrlServ::class)->findOneBy(array("urlServId" => 1));
  81.           $url $alertLog->getUrl();
  82.           //$url = "https://megadashboard.disatelgps.com/?u=gt-disatel&s=".$plate;
  83.           if (substr($url, -3) !== '&s=') {
  84.               // Si no termina con '&s=', agregarlo
  85.               $url .= '&s=';
  86.           }
  87.           $url $url.urlencode($plate);
  88.           $url str_replace(" ""%20"$url);
  89.           $objApi $helperService->open_url($url);
  90.           $api json_decode($objApi);
  91.           
  92.           if ($api && $api[0]){
  93.               $panicAlert['latitude'] = $api[0]->Latitude;
  94.               $panicAlert['longitude'] = $api[0]->Longitude;
  95.               $panicAlert['address'] = $api[0]->Address;
  96.               $panicAlert['plate'] = $api[0]->Fleet;
  97.               $panicAlert['fleet'] = $api[0]->Plate;
  98.               $panicAlert['name'] = $api[0]->Name;
  99.           }else{
  100.               $panicAlert['latitude'] = "";
  101.               $panicAlert['longitude'] = "";
  102.               $panicAlert['address'] = "";
  103.               $panicAlert['plate'] = "";
  104.               $panicAlert['fleet'] = "";
  105.               $panicAlert['name'] = "";
  106.           }
  107.      
  108.           return $this->render('ViewMap/index.html.twig', array (
  109.               "alert" => $panicAlert,
  110.               "desc" => true
  111.           ));
  112.           
  113.       }
  114.       
  115.       
  116.       //"/view-map-als-report/{id}", name="website_view_map_als_report"
  117.       /**
  118.         *
  119.         * @Route("/view-map-als-report/{id}", name="homepage_custom_4")
  120.         * @ParamDecryptor({"id"})
  121.         */
  122.        public function viewMapAlsReportAction (Request $request,$id)
  123.        {
  124.          $em $this->getDoctrine ()->getManager ();
  125.          //$md5Id = $request->get ( "id" );
  126.          //$alsReportDataId = $em->getRepository ( 'AppBundle:AlsReportData' )->findOneByMd5Id ( $md5Id );
  127.          $alsReportData $em->getRepository AlsReportData::class )->findOneBy ( array (
  128.                "alsReportDataId" => $id 
  129.          ) );
  130.            return $this->render('ViewMapAlsReport/index.html.twig', array (
  131.                "alsReportData" => $alsReportData,
  132.                "desc" => true
  133.            ));
  134.            
  135.        }
  136.        
  137.     
  138.     //"/view-map-cipia/{id}", name="website_view_map_cipia"
  139.     /**
  140.     *
  141.     * @Route("/view-map-cipia/{id}", name="homepage_custom_5")
  142.     * @ParamDecryptor({"id"})
  143.     */
  144.     public function viewMapCipiaAction (Request $request$id)
  145.     {
  146.         
  147.         $em $this->getDoctrine ()->getManager ();
  148.         //md5Id = $request->get ( "id" );
  149.         
  150.         
  151.         //$cipiaEventLogId = $em->getRepository ( 'AppBundle:CipiaEventLog' )->findOneByMd5Id ( $md5Id );
  152.         $cipiaEventLog $em->getRepository CipiaEventLog::class )->findOneBy ( array (
  153.               "cipiaEventLogId" => $id 
  154.         ) );
  155.           return $this->render('ViewMapCipia/index.html.twig', array (
  156.               "cipiaEventLog" => $cipiaEventLog,
  157.               "desc" => true
  158.           ));
  159.           
  160.     }
  161.     
  162.     //"/view-map/{id}", name="website_view_map"
  163.     /**
  164.       * @Route("/view-map/{id}", name="homepage_custom_6")
  165.       * @ParamDecryptor({"id"})
  166.       */
  167.      public function viewMapAction (Request $request,$id)
  168.      {
  169.        
  170.        $em $this->getDoctrine ()->getManager ();
  171.        $panicAlert $em->getRepository PanicAlert::class )->findOneBy ( array (
  172.              "panicAlertId" => $id 
  173.        ) );
  174.     
  175.          return $this->render('ViewMap/index.html.twig', array (
  176.              "alert" => $panicAlert,
  177.              "desc" => true
  178.          ));
  179.          
  180.      }
  181.       
  182.       
  183.       
  184.     public function mainNav(Request $request): Response
  185.     {        
  186.         $lastUsername $this->session->get(Security::LAST_USERNAME);      
  187.         $userData     $request->getSession()->get($lastUsername);  
  188.           $menu         $this->session->get($lastUsername."_menu");      
  189.         $selected_module     $request->getSession()->get("module_id");  
  190.         /*echo "<pre>";
  191.         print_r($menu);
  192.         echo "</pre>";
  193.         exit;*/
  194.         return $this->render('main_menu.html.twig', [
  195.             "userData"    => $userData,
  196.                'userModules' => $menu,
  197.             "menuId"      => $selected_module,
  198.             "roleStaff"   => ""
  199.         ]);
  200.     }
  201.     public function profile(Request $request): Response
  202.     {
  203.         
  204.         $lastUsername $this->session->get(Security::LAST_USERNAME);      
  205.         $userData     $request->getSession()->get($lastUsername);  
  206.         
  207.         // replace this example code with whatever you need
  208.         return $this->render('profile.html.twig', array(
  209.                 "userData" => $userData,
  210.         ));
  211.     
  212.     }
  213. }