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.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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('Catégorie introuvable');
  22. }
  23. }
  24. private function load() {
  25. $options = array(
  26. "where" => array(
  27. array("nom_cat", "=", $this->nomCat)
  28. )
  29. );
  30. $resp = $this->bdd->Select('*', 'reponses', $options);
  31. foreach($resp as $questset) {
  32. array_push($this->questsets, new Questset(array($questset['reponse1'], $questset['reponse2'])));
  33. }
  34. }
  35. public static function randSelect() {
  36. $bdd = new Connector();
  37. $arrayCat = $bdd->Select("*", "categorie");
  38. $return = array();
  39. for($i = 0; $i < 2; $i++) {
  40. $catIndex = rand(0, sizeof($arrayCat)-1);
  41. array_push($return, new Categorie($arrayCat[$catIndex]['nom_cat']));
  42. }
  43. return $return;
  44. }
  45. public function getArray() {
  46. $questsets = array();
  47. foreach($this->questsets as $questset) {
  48. array_push($questsets, $questset->getArray());
  49. }
  50. return array(
  51. "nom_cat" => $this->nomCat,
  52. "themes" => $questsets
  53. );
  54. }
  55. }