src/Controller/AnalyticController.php line 98

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Component\HttpFoundation\Response;
  4. use Symfony\Component\HttpFoundation\Request;
  5. use Symfony\Component\HttpFoundation\Session\Session;
  6. use Symfony\Component\Routing\Annotation\Route;
  7. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  8. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
  9. use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
  10. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  11. use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
  12. use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
  13. use Symfony\Component\Serializer\SerializerInterface;
  14. use Doctrine\Common\Annotations\AnnotationReader;
  15. use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactory;
  16. use Symfony\Component\Serializer\Mapping\Loader\AnnotationLoader;
  17. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  18. use Doctrine\DBAL\DriverManager;
  19. use Doctrine\ORM\EntityManagerInterface;
  20. use Doctrine\Common\Collections\ArrayCollection;
  21. use Doctrine\ORM\Tools\Pagination\Paginator;
  22. use App\Entity\ConfigGeoServer;
  23. use App\Entity\ConfigGeoLayers;
  24. use App\Entity\FilterRange;
  25. use App\Entity\FilterOptions;
  26. use App\Entity\Layers;
  27. use App\Entity\Styles;
  28. use App\Entity\Municipio;
  29. use App\Repository\MunicipioRepository;
  30. use App\Entity\Analytic;
  31. use App\Repository\AnalyticRepository;
  32. use App\Repository\OpenaiRepository;
  33. use App\Entity\Project;
  34. use App\Entity\CacheAi;
  35. use Symfony\Component\Security\Core\Security;
  36. //use OpenAI\OpenAI;
  37. //use OpenAI;
  38. class AnalyticController extends AbstractController
  39. {
  40.     #[Route('/{_locale}/explora',
  41.             locale"en",
  42.             format"html",
  43.             requirements: ["_locale" => "en|es|ca""_format" => "html|xml", ],
  44.             defaults: ["_locale" => "en"], 
  45.             name'app_analytic_home')]
  46.     public function home(Request $requestSerializerInterface $serializerSecurity $security): Response
  47.     {
  48.         $em $this->getDoctrine()->getManager();
  49.         $data['mun'] = null;
  50.         
  51.         $baseurl $this->generateUrl('home', [], UrlGeneratorInterface::ABSOLUTE_URL);
  52.         $data['base_url'] = substr($baseurl0, -1);
  53.         $data['municipios'] = $em->getRepository(Municipio::class)->getMunicipios();
  54.         $data['kpismulti'] = $em->getRepository(Municipio::class)->getKpisMultiInfo();
  55.         $data['analytic_filters'] = $em->getRepository(Municipio::class)->getAnalyticFilters();
  56.         // if($userId){
  57.             
  58.         //     $data['user_projects'] = $em->getRepository(Project::class)->findBy(['id_user'=>$userId]);
  59.         //     $data['mun'] = null;
  60.         //     return $this->render('home/index.html.twig', $data);
  61.         // }else{
  62.         //     return $this->render('Login/login.html.twig');
  63.         // }
  64.         
  65.         return $this->render('analytic/index.html.twig'$data);
  66.     }
  67.     #[Route('/{_locale}/explora/{mun}',
  68.     locale"en",
  69.     format"html",
  70.     requirements: ["_locale" => "en|es|ca""_format" => "html|xml", ],
  71.     defaults: ["_locale" => "en"],  
  72.     name'app_analytic'methods: ['GET'])]
  73.     public function index(int $munRequest $requestSerializerInterface $serializerSecurity $security): Response
  74.     {
  75.         
  76.         $em $this->getDoctrine()->getManager();
  77.         $data['chatai'] = $em->getRepository(CacheAi::class)->findAll();
  78.         $baseurl $this->generateUrl('home', [], UrlGeneratorInterface::ABSOLUTE_URL);
  79.         $data['base_url'] = substr($baseurl0, -1);
  80.         // Get Municipio data
  81.         $data['mun'] = $mun;
  82.         $data['municipioname'] = $em->getRepository(Municipio::class)->getMunicipioName($mun);
  83.         $data['mundatainfo'] = $em->getRepository(Municipio::class)->mun_data_info($mun);
  84.         // Get Analytic data
  85.         $data['analytic'] = $serializer->normalize($em->getRepository(Analytic::class)->analytic_data(), 'array');
  86.         $data['analytic_data'] = $em->getRepository(Analytic::class)->analytic_data_filter($mun,1);
  87.         // Get legend
  88.         $data['kpi_rank'] = $serializer->normalize($em->getRepository(Municipio::class)->indicators_rank_group(), 'array');
  89.         // $data['statData'] = json_encode($data['analytic_data']);
  90.         $data['statData'] = $em->getRepository(Analytic::class)->analytic_stat_data($mun);
  91.         
  92.         return $this->render('analytic/home.html.twig'$data);
  93.     }
  94.     #[Route('/{_locale}/explora/{mun}/{slug}',
  95.     locale"en",
  96.     format"html",
  97.     requirements: ["_locale" => "en|es|ca""_format" => "html|xml", ],
  98.     defaults: ["_locale" => "en"],  
  99.     name'explore_analytic'methods: ['GET'])]
  100.     public function explore (int $munstring $slugRequest $requestSerializerInterface $serializerSecurity $security) : Response
  101.     {
  102.         $em $this->getDoctrine()->getManager();
  103.         $baseurl $this->generateUrl('home', [], UrlGeneratorInterface::ABSOLUTE_URL);
  104.         $data['base_url'] = substr($baseurl0, -1);
  105.         $data['mun'] = $mun;
  106.         $data['slug'] = $slug;
  107.         // Get Municipio data
  108.         $data['municipioname'] = $em->getRepository(Municipio::class)->getMunicipioName($mun);
  109.         $filterData $em->getRepository(Analytic::class)->findBy(['slug'=>$slug]);
  110.         $filter $filterData[0]->getId();
  111.         // Get Analytic data
  112.         $data['analytic'] = $em->getRepository(Analytic::class)->analytic_data();
  113.         $data['analytic_data'] = $em->getRepository(Analytic::class)->analytic_data_filter_one_multi($mun,1,$filter);
  114.         $data['filtered_data'] = json_encode($em->getRepository(Analytic::class)->get_filtered_data($mun,$filter));
  115.         
  116.         $data['analytic_general_mun'] = $em->getRepository(Analytic::class)->analytic_general_mun($mun);
  117.         $data['analytic_data_relation'] = $em->getRepository(Analytic::class)->analytic_relation($mun,$filter,2);
  118.         // Get legend
  119.         $data['kpi_rank'] = $serializer->normalize($em->getRepository(Municipio::class)->indicators_rank_group(), 'array');
  120.         $data['useStatData'] = json_encode($data['analytic_data'][0]['use_stats']);
  121.         $data['yearStatData'] = json_encode($data['analytic_data'][0]['year_stats']);
  122.         $data['areaStatData'] = json_encode($data['analytic_data'][0]['area_stats']);
  123.         $data['occupationStatData'] = json_encode($data['analytic_data'][0]['occupation_stats']);
  124.         $data['layers'] = $serializer->serialize($em->getRepository(Layers::class)->getAll(), 'json');
  125.         $data['configLayers'] = $serializer->serialize($em->getRepository(ConfigGeoLayers::class)->getAll(), 'json');
  126.         // Get indicators list
  127.         $data['kpi_list'] = $serializer->serialize($em->getRepository(Municipio::class)->all_kpi(), 'json');
  128.         $data['mun_data'] = $serializer->normalize($em->getRepository(Municipio::class)->mun_data($mun), 'array');
  129.         // Get kpi colors
  130.         $data['kpi_colors'] = $serializer->serialize($em->getRepository(Municipio::class)->get_indicator_colors(3), 'json');
  131.         $session $request->getSession();
  132.         $foo $session->get('init_message');
  133.         if($foo != true){
  134.             $this->addFlash(
  135.                 'notice',
  136.                 "Se presentan los edificios identificados como vulnerables según diversos indicadores asociados a la vulnerabilidad.<br>Además, se ofrecen datos sobre los edificios en función de otros indicadores, que abarcan diferentes ámbitos y características particulares."
  137.             );
  138.             $session->set('init_message'true);
  139.         }
  140.         return $this->render('analytic/explore.html.twig'$data);
  141.         
  142.     }
  143. }