src/Controller/AppController.php line 22

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