src/Controller/testController.php line 26

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Contracts\HttpClient\HttpClientInterface;
  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\Request;
  8. use App\Service\PublicFunction;
  9. class testController extends AbstractController
  10. {
  11.     private $client;
  12.     public function __construct(HttpClientInterface $client)
  13.     {
  14.         $this->client $client;
  15.     }
  16.     
  17.     /**
  18.      * @Route("/test-auditif-en-ligne/")
  19.      */
  20.     public function renderTestAccueilPage()
  21.     {
  22.         
  23.         return $this->render('./test/testaccueil.html.twig', array(
  24.         ));
  25.         
  26.     }
  27.         /**
  28.      * @Route("/test-auditif-en-ligne/test")
  29.      */
  30.     public function renderTestPage()
  31.     {
  32.         
  33.         return $this->render('./test/test.html.twig', array(
  34.         ));
  35.         
  36.     }
  37.         /**
  38.      * @Route("test-auditif-en-ligne/test/volume")
  39.      */
  40.     public function renderTestVolumePage()
  41.     {
  42.         
  43.         return $this->render('/test/tonal/calibrationVolume.html.twig', array(
  44.         ));
  45.         
  46.     }
  47.         /**
  48.      * @Route("test-auditif-en-ligne/test/annonce")
  49.      */
  50.     public function renderTestAnnoncePage()
  51.     {
  52.         
  53.         return $this->render('/test/tonal/annonce.html.twig', array(
  54.         ));
  55.         
  56.     }
  57.             /**
  58.      * @Route("test-auditif-en-ligne/test/tonalite")
  59.      */
  60.     public function renderTestTonalitePage()
  61.     {
  62.         
  63.         return $this->render('/test/tonal/tonalite.html.twig', array(
  64.         ));
  65.         
  66.     }
  67.             /**
  68.      * @Route("test-auditif-en-ligne/test/resultat")
  69.      */
  70.     public function renderTestResultatPageRequest $requestPublicFunction $publicFunction)
  71.     {
  72.         $data json_decode($request->getContent(), true);
  73.         
  74.         $ch curl_init();
  75.         curl_setopt($ch,CURLOPT_RETURNTRANSFERtrue);
  76.         curl_setopt($chCURLOPT_URL"{$_ENV['BASE_API']}test/client");
  77.         curl_setopt($chCURLOPT_POST1);
  78.         curl_setopt($chCURLOPT_POSTFIELDS$request->getContent());
  79.         $result curl_exec($ch);
  80.         $client json_decode($result);
  81.         
  82.         curl_close($ch);
  83.         
  84.         
  85.         return $this->render('/test/tonal/resultat.html.twig', array(
  86.             "data" => $client,
  87.         ));
  88.         
  89.     }
  90.             /**
  91.      * @Route("/testvocal/{id}")
  92.      */
  93.     public function renderTestVocalPageint $id )
  94.     {
  95.         
  96.         $response $this->client->request(
  97.             'GET',
  98.             "{$_ENV['BASE_API']}questions"
  99.         );
  100.         $content $response->toArray();
  101.         
  102.         return $this->render('./test/testvocal.html.twig', array(
  103.             "questions" => json_encode($content),
  104.             "id" => $id,
  105.         ));
  106.         
  107.     }
  108.         /**
  109.      * @Route("test-auditif-en-ligne/testvocal/annonce")
  110.      */
  111.     public function renderTestVocalAnnoncePage(Request $request)
  112.     {
  113.         $data json_decode($request->getContent(), true);
  114.         return $this->render('/test/vocal/annonce.html.twig', array(
  115.             "step"=> $data['step'],
  116.         ));
  117.         
  118.     }
  119.         /**
  120.      * @Route("test-auditif-en-ligne/testvocal/question")
  121.      */
  122.     public function renderTestVocalQuestion(Request $request)
  123.     {
  124.         $data json_decode($request->getContent(), true);
  125.         
  126.         return $this->render('/test/vocal/question.html.twig', array(
  127.             "dataCurrentQuestion" => $data['dataVocalDial'],
  128.             "etape"=> $data['etape'],
  129.             "dataCurrentAnswer" => $data['dataVocalAnswer'],
  130.             "questionid" => $data['id'],
  131.             "question" => $data['question'],
  132.             "numberQuestion" => $data['numberQuestion'],
  133.             "numberMot" => $data['numberMot'],
  134.             "step" => $data['step'],
  135.         ));
  136.         
  137.     }
  138.         /**
  139.      * @Route("test-auditif-en-ligne/testvocal/reponse")
  140.      */
  141.     public function renderTestVocalReponse(Request $request)
  142.     {
  143.         $data json_decode($request->getContent(), true);
  144.         
  145.         return $this->render('/test/vocal/reponse.html.twig', array(
  146.             "dataCurrentAnswer" => $data['dataVocalAnswer'],
  147.             "questionid" => $data['id'],
  148.             "question" => $data['question'],
  149.             "numberQuestion" => $data['numberQuestion'],
  150.             "numberMot" => $data['numberMot'],
  151.             "step" => $data['step'],
  152.         ));
  153.         
  154.     }
  155.         /**
  156.      * @Route("test-auditif-en-ligne/testvocal/resultat")
  157.      */
  158.     public function renderTestVocalResultat(Request $requestPublicFunction $publicFunction)
  159.     {
  160.         $data json_decode($request->getContent(), true);
  161.         $id$data['tonalId'];
  162.         $ch curl_init();
  163.         curl_setopt($ch,CURLOPT_RETURNTRANSFERtrue);
  164.         curl_setopt($chCURLOPT_URL"{$_ENV['BASE_API']}test/client/$id");
  165.         curl_setopt($chCURLOPT_CUSTOMREQUEST"PUT");
  166.         curl_setopt($chCURLOPT_POSTFIELDS$request->getContent());
  167.         
  168.         $result curl_exec($ch);
  169.         $client json_decode($result);
  170.         
  171.         curl_close($ch);
  172.         
  173.         return $this->render('/test/vocal/resultat.html.twig', array(
  174.             "data" => $client,
  175.         ));
  176.         
  177.         
  178.         
  179.     }
  180. }