src/Controller/ApiController.php line 57

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Component\HttpFoundation\Response;
  4. use Symfony\Component\Routing\Annotation\Route;
  5. use Symfony\Component\HttpFoundation\JsonResponse;
  6. use Symfony\Contracts\HttpClient\HttpClientInterface;
  7. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  8. #[Route('/api')]
  9. class ApiController extends AbstractController
  10. {
  11.     private $client;
  12.     public function __construct(HttpClientInterface $client)
  13.     {
  14.         $this->client $client;
  15.     }
  16.     #[Route('/formation/{id}'name'getformation')]
  17.     public function getformation($id): Response
  18.     {
  19.         $request $this->client->request('GET'$this->getParameter("api")."/getformation/$id");
  20.         $formations $request->toArray();
  21.         $data self::dropdown($formations,'Formation');
  22.         return new JsonResponse($data);
  23.     }
  24.     #[Route('/promotion/{id}'name'getpromotion')]
  25.     public function getpromotion($id): Response
  26.     {
  27.         $request $this->client->request('GET'$this->getParameter("api")."/getpromotion/$id");
  28.         $promotions $request->toArray();
  29.         $data self::dropdown($promotions,'Promotion');
  30.         return new JsonResponse($data);
  31.     }
  32.     #[Route('/semestre/{id}'name'getsemestre')]
  33.     public function getsemestre($id): Response
  34.     {
  35.         $request $this->client->request('GET'$this->getParameter("api")."/getsemestre/$id");
  36.         $semestres $request->toArray();
  37.         $data self::dropdown($semestres,'Semestre');
  38.         return new JsonResponse($data);
  39.     }
  40.     #[Route('/niveau/{id}'name'getniveau')]
  41.     public function getniveau($id): Response
  42.     {
  43.         $request $this->client->request('GET'$this->getParameter("api")."/getniveau/$id");
  44.         $niveaux $request->toArray();
  45.         // dd($niveaux);
  46.         $data "<option selected enabled value=''>Choix Niveau</option>";
  47.         foreach ($niveaux as $niveau) {
  48.             $data .="<option value=".$niveau['niv_3'].">".$niveau['niv_3']."</option>";
  49.         }
  50.         // dd($niveaux);
  51.         return new JsonResponse($data);
  52.     }
  53.     #[Route('/cycle/{id}'name'getcycle')]
  54.     public function getcycle($id): Response
  55.     {
  56.         $request $this->client->request('GET'$this->getParameter("api")."/getlistofstagebysemestreannee/$id");
  57.         $cycles $request->toArray()['cycles'];
  58.         // dd($cycles);
  59.         $data "<option selected enabled value=''>Choix Cycle</option>";
  60.         foreach ($cycles as $key => $cycle) {
  61.             $data .="<option value=".$key.">".$cycle['cycle']."</option>";
  62.         }
  63.         return new JsonResponse($data);
  64.     }
  65.     static function dropdown($objects,$choix)
  66.     {
  67.         $data "<option selected enabled value=''>Choix ".$choix."</option>";
  68.         foreach ($objects as $object) {
  69.             $data .="<option value=".$object['id'].">".$object['designation']."</option>";
  70.         }
  71.         return $data;
  72.     }
  73. }