src/Controller/AppController.php line 25

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Category;
  4. use App\Entity\Competition;
  5. use App\Entity\Event;
  6. use App\Entity\Result;
  7. use App\Services\CSVPersonServices;
  8. use App\Services\PodiumServices;
  9. use Doctrine\ORM\EntityManagerInterface;
  10. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  11. use Symfony\Component\Dotenv\Dotenv;
  12. use Symfony\Component\HttpFoundation\Request;
  13. use Symfony\Component\HttpFoundation\Response;
  14. use Symfony\Component\Routing\Annotation\Route;
  15. use Symfony\Component\HttpClient\CurlHttpClient;
  16. use function PHPUnit\Framework\isNull;
  17. class AppController extends AbstractController
  18. {
  19.     public function __constructEntityManagerInterface $em)
  20.     {
  21.         $this->em =$em;
  22.     }
  23.     /**
  24.      * @Route("/resultats", name="resultats_ffme")
  25.      */
  26.     public function resultats_ffme(): Response
  27.     {
  28.         return $this->render('app/resultats_ffme.html.twig');
  29.     }
  30.     /**
  31.      * @Route("/api/ffme", name="api_ffme")
  32.      */
  33.     public function apiresultat(): Response
  34.     {
  35.         $dotenv = new Dotenv();
  36.         $dotenv->load(__DIR__ '/../../.env');
  37.         $this->dirCacheJson '../var/cache/' $_ENV['APP_ENV'] . '/ffme';
  38.         $this->fileCacheJson $this->dirCacheJson '/config_resultat_ffme.json';
  39.         $jsonString file_get_contents($this->fileCacheJson);
  40.         $config json_decode($jsonStringtrue);
  41.         $date = new \DateTimeImmutable();
  42.         $ch curl_init();
  43.         curl_setopt($chCURLOPT_URL$config["url"].$config["id"]."?z=".uniqid());
  44.         curl_setopt($chCURLOPT_HEADERfalse);
  45.         curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
  46.         curl_setopt($chCURLOPT_CONNECTTIMEOUT5);
  47.         curl_setopt($chCURLOPT_TIMEOUT5);
  48.         curl_setopt($chCURLOPT_FOLLOWLOCATIONtrue);
  49.         curl_setopt($chCURLOPT_MAXREDIRS1);
  50.         curl_setopt($chCURLOPT_SSL_VERIFYPEERtrue);
  51.         //recuperer les information url
  52.         $response curl_exec($ch);
  53.         $arrResultat json_decode($response);
  54.         $Res=$config;
  55.         $Res["name"]=$arrResultat->nomCompetition;
  56.         $Res["lieu"]=$arrResultat->lieu;
  57.         $Res["timestamp"]=$arrResultat->timestamp;
  58.         //  $Res["groupes"]=$arrResultat->groupes;
  59.         foreach ( $arrResultat->groupes as $vague){
  60.             //   $Res["vague"][$vague->sequence][$vague->categorie][$vague->sexe]["etapes"] = $vague->etapes;
  61.             if(count($vague->resultats) > 0){
  62.                 $Res["VAGUES"][$vague->categorie."_".$vague->sexe][$vague->sequence] = $vague->resultats;
  63.                 $Res["VAGUES"][$vague->categorie."_".$vague->sexe]["CAT"]=$vague->categorie;
  64.                 $Res["VAGUES"][$vague->categorie."_".$vague->sexe]["GENRE"]=$vague->sexe;
  65.                 if(!isset($config["VAGUES"][$vague->categorie."_".$vague->sexe])){
  66.                     $Res["VAGUES"][$vague->categorie."_".$vague->sexe]["mode"] ='INVISIBLE';
  67.                 }
  68.             }
  69.         }
  70.         foreach (  $Res["VAGUES"] as $key=> $vague){
  71.             if($vague["mode"]=="INVISIBLE"){
  72.                 unset( $Res["VAGUES"][$key]);
  73.             }
  74.         }
  75.         // $Res["states"] =['INVISIBLE',"QUALIF_IN_PROGRESS","QUALIF_RESULT","FINAL"];
  76.         //recuperation des donnĂ© save pour chaque cles "U18_HOMME" ...etc
  77.         // $Res["VAGUES"]["U18_HOMME"]["mode"] ='QUALIF_IN_PROGRESS';
  78.         //  $Res["VAGUES"]["U16_FEMME"]["mode"] ='FINAL';
  79.         ksort($Res["VAGUES"]);
  80. //        $arrResultat->update=date("d/m/Y h:i",substr($arrResultat->timestamp,0,-3));
  81. //        $arrResultat->read=date("d/m/Y h:i",$date->getTimestamp());
  82. //        $arrResultat->urlFfme="demo.escalade.online";
  83. //        $arrResultat->idFfme=555;
  84. //        $arrResultat->numCompetition=10;
  85.         //$json = $client->request('GET', "https://demo.escalade.online/ws/app/resultatJson/555", ['headers' => ['accept' => 'application/json']])->toArray();
  86.         return $this->json($Res);
  87.     }
  88.     /**
  89.      * @Route("/", name="home")
  90.      */
  91.     public function index(): Response
  92.     {
  93.         return $this->redirectToRoute("app_login");
  94.     }
  95.     /**
  96.      * @Route("/test", name="test_podium")
  97.      */
  98.     public function test_podium(): Response
  99.     {
  100.         $podium = new PodiumServices($this->em);
  101.         $test $podium->getTestPodium(["cid"=>4]);
  102.         dd$test);
  103.         $competitions $this->em->getRepository(Competition::class)->findBy([],["id"=>"ASC"]);
  104.         return $this->render('app/index.html.twig', [
  105.             'controller_name' => 'AppController',
  106.             'competitions'=>$competitions
  107.         ]);
  108.     }
  109.     /**
  110.      * @Route("/live", name="lives_podium")
  111.      */
  112.     public function lives_podium(): Response
  113.     {
  114.         $events $this->em->getRepository(Event::class)->findBy([],["date_start"=>"ASC"]);
  115.         dd($events);
  116.         return $this->render('podium/events.html.twig', [
  117.             'controller_name' => 'AppController',
  118.             'event'=>$events
  119.         ]);
  120.     }
  121.     /**
  122.      * @Route("/live/{id}/podium", name="live_podium")
  123.      */
  124.     public function live_podium(Event $event): Response
  125.     {
  126.       //  $competitions = $this->em->getRepository(Competition::class)->findBy([],["date_start"=>"ASC"]);
  127.         return $this->render('podium/index.html.twig', [
  128.             'controller_name' => 'AppController',
  129.             'competitions'=>$event->getCompetitions()
  130.         ]);
  131.     }
  132.     /**
  133.      * @Route("/api/podium/vague", name="api_json_podium")
  134.      */
  135.     public function api_podium(Request $request): Response
  136.     {
  137.         $datasForm =  $request->getContent();
  138.         $datasForm json_decode($datasFormtrue);
  139.         if(!isset($datasForm["cid"])){
  140.             return [];
  141.         }
  142.         $competition $this->em->getRepository(Competition::class)->find($datasForm["cid"]);
  143.         $podium = new PodiumServices($this->em);
  144.         [$competitors,$BlocsInfo] = $podium->getPodium($datasForm);
  145.         $event =[];
  146.         $event["name"]=$competition->getEvent()->getName();
  147.         $event["competition"]=$competition->getName();
  148.         foreach ($competition->getTrials() as $trial){
  149.             $bloc $trial->getBloc();
  150.             if(!in_array($bloc->getName(),array_keys($BlocsInfo))){
  151.                 $event["blocs"][$bloc->getName()]["name"]=$bloc->getName();
  152.                 $event["blocs"][$bloc->getName()]["pts_total_zone"]=$bloc->getPtsDefault()/2;
  153.                 $event["blocs"][$bloc->getName()]["pts_total_top"]=$bloc->getPtsDefault()/2;
  154.             }else{
  155.                 $event["blocs"][$bloc->getName()]=$BlocsInfo[$bloc->getName()];
  156.             }
  157.             $event["blocs"][$bloc->getName()]["id"]=$bloc->getId();
  158.             $event["blocs"][$bloc->getName()]["pts_default_zone"]=$bloc->getPtsDefault()/2;
  159.             $event["blocs"][$bloc->getName()]["pts_default_top"]=$bloc->getPtsDefault()/2;
  160.         }
  161.         return $this->json(["competitors"=>$competitors,"event"=>$event]);
  162.     }
  163. }