Créé dans le cadre du projet de fin d'année de la promo 2018 de CIR2 de l'ISEN Brest/Rennes, le Burger Quizz est une adaptation numérique du jeu télévisé éponyme, plus précisément d'une épreuve spécifique de ce jeu : le "Sel ou Poivre".

class.categorie.php 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. class Categorie {
  3. private $bdd;
  4. private $nomCat;
  5. private $questsets;
  6. function __construct($nomCat) {
  7. $this->bdd = new Connector();
  8. $this->selectCat($nomCat);
  9. $this->questsets = array();
  10. $this->load();
  11. }
  12. private function selectCat($nomCat) {
  13. $options = array(
  14. "where" => array(
  15. array("nom_cat", "=", $nomCat)
  16. )
  17. );
  18. if(!is_null($this->bdd->Select('*', 'categorie', $options))) {
  19. $this->nomCat = $nomCat;
  20. } else {
  21. throw new Exception('cant_find_cat');
  22. }
  23. }
  24. private function load() {
  25. $options = array(
  26. "where" => array(
  27. array("nom_cat", "=", $this->nomCat)
  28. ),
  29. "order by" => array("rand()"),
  30. "limit" => array("2")
  31. );
  32. $resp = $this->bdd->Select('*', 'reponses', $options);
  33. foreach($resp as $questset) {
  34. array_push($this->questsets, new Questset(array($questset['reponse1'], $questset['reponse2'])));
  35. }
  36. }
  37. public static function randSelect() {
  38. $bdd = new Connector();
  39. $arrayCat = $bdd->Select("*", "categorie");
  40. $return = array();
  41. $catIndex = -1;
  42. $previousIndex = -1;
  43. for($i = 0; $i < 2; $i++) {
  44. do {
  45. $filled = true;
  46. $previousIndex = $catIndex;
  47. $catIndex = rand(0, sizeof($arrayCat)-1);
  48. $category = new Categorie($arrayCat[$catIndex]['nom_cat']);
  49. if(sizeof($category->getArray()['themes']) >=2) {
  50. foreach($category->getArray()['themes'] as $theme) {
  51. if(sizeof($theme['questions']) < 3) {
  52. $filled = false;
  53. }
  54. }
  55. } else {
  56. $filled = false;
  57. }
  58. } while(($catIndex == $previousIndex) || !$filled);
  59. array_push($return, new Categorie($arrayCat[$catIndex]['nom_cat']));
  60. }
  61. return $return;
  62. }
  63. public function getArray() {
  64. $questsets = array();
  65. foreach($this->questsets as $questset) {
  66. array_push($questsets, $questset->getArray());
  67. }
  68. return array(
  69. "nom_cat" => utf8_encode($this->nomCat),
  70. "themes" => $questsets
  71. );
  72. }
  73. }