|
@@ -0,0 +1,53 @@
|
|
1
|
+<?php
|
|
2
|
+
|
|
3
|
+class Categorie {
|
|
4
|
+ private $bdd;
|
|
5
|
+ private $nomCat;
|
|
6
|
+ private $questsets;
|
|
7
|
+
|
|
8
|
+ function __construct($nomCat) {
|
|
9
|
+ $this->bdd = new Connector();
|
|
10
|
+ $this->selectCat($nomCat);
|
|
11
|
+ $this->questsets = array();
|
|
12
|
+ $this->load();
|
|
13
|
+ }
|
|
14
|
+
|
|
15
|
+ private function selectCat($nomCat) {
|
|
16
|
+ $options = array(
|
|
17
|
+ "where" => array(
|
|
18
|
+ array("nom_cat", "=", $nomCat)
|
|
19
|
+ )
|
|
20
|
+ );
|
|
21
|
+
|
|
22
|
+ if(!is_null($this->bdd->Select('*', 'categorie', $options)) {
|
|
23
|
+ $this->nomCat = $nomCat;
|
|
24
|
+ } else {
|
|
25
|
+ throw new Exception('Catégorie introuvable');
|
|
26
|
+ }
|
|
27
|
+ }
|
|
28
|
+
|
|
29
|
+ private function load() {
|
|
30
|
+ $options = array(
|
|
31
|
+ "where" => array(
|
|
32
|
+ array("nom_cat", "=", $this->nomCat)
|
|
33
|
+ )
|
|
34
|
+ );
|
|
35
|
+
|
|
36
|
+ $resp = $this->bdd->Select('*', 'reponses', $options);
|
|
37
|
+ foreach($resp as $questset) {
|
|
38
|
+ array_push($this->questsets, new Questset(array($questset['reponse1'], $questset['reponse2'])));
|
|
39
|
+ }
|
|
40
|
+ }
|
|
41
|
+
|
|
42
|
+ public static randSelect() {
|
|
43
|
+ $bdd = new Connector();
|
|
44
|
+ $arrayCat = $bdd->Select("*", "categorie");
|
|
45
|
+ $count = $bdd->Select("COUNT(*)", "categorie")[0];
|
|
46
|
+ $return = array();
|
|
47
|
+ for($i = 0; $i < 2; $i++) {
|
|
48
|
+ $catIndex = rand(0, $count);
|
|
49
|
+ array_push($return, new Categorie($arrayCat[$catIndex-1]['nom_cat']));
|
|
50
|
+ }
|
|
51
|
+ return $return;
|
|
52
|
+ }
|
|
53
|
+}
|