apiTableauFromClassement.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <?php
  2. require_once "libs/fnMain.php";
  3. /**************************
  4. * Contrôle du token JWT
  5. **************************/
  6. if (!isset($_GET["jwt"], $_SETTINGS["jwt_secret"])) {
  7. echo "Manque d'arguments";
  8. die();
  9. }
  10. verifyJWTtoken($_GET["jwt"], $_SETTINGS["jwt_secret"]);
  11. /**************************
  12. * Contrôle du statut premium de l'utilisateur
  13. **************************/
  14. verifyUserPremium($_GET["jwt"]);
  15. /**************************
  16. * GENERATION DES CLASSEMENTS
  17. **************************/
  18. $isClassementValid = isset($_GET["classement"]) && (int) $_GET["classement"] !== 0;
  19. if ($isClassementValid) {
  20. $rangMoyen = (int) $_GET["classement"];
  21. // HTML renvoyé au site
  22. $html = <<<EOF
  23. <link rel="stylesheet" href="assets/bootstrap.min.css">
  24. <style>
  25. /* Tableau */
  26. table {
  27. font-size: 13px;
  28. text-align: center;
  29. border-collapse: collapse;
  30. white-space: nowrap;
  31. overflow: auto;
  32. }
  33. th, td {
  34. padding: 2px;
  35. border: 1px solid black;
  36. --text-color: lightgrey;
  37. }
  38. .all-choices {
  39. background-color: #28a745;
  40. /* color: #8fd19e; */
  41. color: white;
  42. }
  43. .half-choices {
  44. background-color: #8fd19e;
  45. color: black;
  46. }
  47. .last-choice {
  48. background-color: #ffdf7e;
  49. color: grey;
  50. }
  51. .no-choice {
  52. background-color: #ed969e;
  53. }
  54. .never-available {
  55. background-color: lightgrey;
  56. }
  57. </style>
  58. <h2>Tableau de classement pour le rang {$rangMoyen}</h2>
  59. <h3>Légende</h3>
  60. <table>
  61. <thead>
  62. <th colspan="5">Légende (sur toutes les années)</th>
  63. </thead>
  64. <tbody>
  65. <tr>
  66. <td>Jamais proposé</td>
  67. <td class="no-choice">Aucun choix</td>
  68. <td class="last-choice">Une seule année</td>
  69. <td class="half-choices">Plusieurs choix</td>
  70. <td class="all-choices">Tous les choix</td>
  71. </tr>
  72. </tbody>
  73. </table>
  74. <p>
  75. Chaque nombre dans chaque case correspond au nombre d'années où ce choix était dispo au classement rentré <br>
  76. </p>
  77. EOF;
  78. $html .= "<h3>Résultats</h3>";
  79. // On va récupérer tous les rangs limited dispo triés par idChoix
  80. $reqRL = $db->query("SELECT idChoix, annee, rangLimite FROM dataset");
  81. $rangLimites = $reqRL->fetchAll(PDO::FETCH_GROUP|PDO::FETCH_ASSOC);
  82. // Récupération des datasets
  83. $specialityDatasetAbrev = getCsvToArrayKeyValue($_SETTINGS["datasetFolder"]."/liste_specialites_abrev.csv");
  84. $specialityDataset = getCsvToArrayKeyValue($_SETTINGS["datasetFolder"]."/liste_specialites.csv");
  85. $cityDataset = getCsvToArrayKeyValue($_SETTINGS["datasetFolder"]."/liste_villes.csv");
  86. $inputClassement = $rangMoyen;
  87. // Calcul et affichage des données
  88. // Affichage de la 1ère ligne = Titre des colonnes
  89. $html .= "<table><thead><tr><th></th>";
  90. foreach ($specialityDatasetAbrev as $specialityName) {
  91. $html .= "<th scope='col'>".$specialityName."</th>";
  92. }
  93. $html .= "</tr></thead><tbody>";
  94. // Affichage de la suite du tableau avec le calcul
  95. foreach ($cityDataset as $cityId => $cityName) {
  96. // On gère la séparation des différentes régions entre elles (représentées dans le csv villes par les lignes XX_:XX)
  97. // La notation des lignes de séparation est sous forme XX_x car si on laissait XX, la fonction getCsvToArrayKeyValue
  98. // ne retourne la position que pour la 1ère occurence de XX;XX
  99. // La manière de fix ça de manière la plus opti et sale, c'est de faire un substr et de tester les 2 premiers charactères
  100. // si ils sont égaux à XX, on fait une séparation
  101. // TODO : Faire un parseur csv qui prend en compte chaque ligne du csv dans l'ordre du fichier
  102. if (strpos($cityId, "XX") !== FALSE) {
  103. $html .= "<tr><th></th>";
  104. foreach ($specialityDatasetAbrev as $specialityName) {
  105. $html .= "<th scope='col'>".$specialityName."</th>";
  106. }
  107. $html .= "</th>";
  108. continue;
  109. }
  110. $html .= "<tr><th scope='row'>".$cityName."</th>";
  111. foreach ($specialityDatasetAbrev AS $specialityId => $specialityName) {
  112. $idChoice = "0".$cityId.$specialityId;
  113. if (!isset($rangLimites[$idChoice])) {
  114. $nbAnneePropose = 0;
  115. $nbPossibleAnneePropose = 0;
  116. } else {
  117. $nbAnneePropose = count($rangLimites[$idChoice]);
  118. $nbPossibleAnneePropose = 0;
  119. foreach ($rangLimites[$idChoice] as $rangLimite) {
  120. if ((int) $rangLimite["rangLimite"] >= $inputClassement) {$nbPossibleAnneePropose++;}
  121. }
  122. }
  123. // Affichage de la cellule
  124. $html .= "<td class=\"";
  125. switch (TRUE) {
  126. case ($nbPossibleAnneePropose === 0 && $nbAnneePropose === 0):
  127. $html .= "never-available";
  128. break;
  129. case ($nbPossibleAnneePropose === 0):
  130. $html .= "no-choice";
  131. break;
  132. case ($nbAnneePropose > $nbPossibleAnneePropose && $nbPossibleAnneePropose === 1):
  133. $html .= "last-choice";
  134. break;
  135. case ($nbAnneePropose > $nbPossibleAnneePropose && $nbPossibleAnneePropose !== 1):
  136. $html .= "half-choices";
  137. break;
  138. case ($nbAnneePropose === $nbPossibleAnneePropose):
  139. $html .= "all-choices";
  140. break;
  141. }
  142. $html .= "\">";
  143. if ($nbPossibleAnneePropose > 0) {
  144. $html .= $nbPossibleAnneePropose;
  145. } else if ($nbPossibleAnneePropose === 0) {
  146. $html .= "0";
  147. }
  148. $html .= "</td>";
  149. }
  150. $html .= "</tr>";
  151. }
  152. $html .= "</tbody></table><br>";
  153. // Affichage du HTML demandé
  154. echo $html;
  155. } else {
  156. echo "Classement entré incorrect.";
  157. }