Browse Source

Merge remote-tracking branch 'origin/master'

PCYoshi 9 years ago
parent
commit
fc27d47f99

+ 9
- 4
web/model/class.categorie.php View File

@@ -30,7 +30,9 @@ class Categorie {
30 30
 		$options = array(
31 31
 			"where" => array(
32 32
 				array("nom_cat", "=", $this->nomCat)
33
-			)
33
+			),
34
+			"order by" => array("rand()"),
35
+			"limit" => array("2")
34 36
 		);
35 37
 
36 38
 		$resp = $this->bdd->Select('*', 'reponses', $options);
@@ -51,10 +53,13 @@ class Categorie {
51 53
 	}
52 54
 
53 55
 	public function getArray() {
54
-		$return = array();
56
+		$questsets = array();
55 57
 		foreach($this->questsets as $questset) {
56
-			array_push($return, $questset->getArray());
58
+			array_push($questsets, $questset->getArray());
57 59
 		}
58
-		return $return;
60
+		return array(
61
+			"nom_cat" => utf8_encode($this->nomCat),
62
+			"themes" => $questsets
63
+		);
59 64
 	}
60 65
 }

+ 1
- 1
web/model/class.connector.php View File

@@ -47,7 +47,7 @@ class Connector {
47 47
 					throw new Exception('Problème lors de la création du substring');
48 48
 				}
49 49
 			} else if(($upName = strtoupper($name)) == "ORDER BY") {
50
-				if(sizeof($value) != 2) {
50
+				if(sizeof($value) != 2 && substr($value[0], -2) != "()") { 
51 51
 					throw new Exception('Nombre de paramètres incorrects (ORDER BY). Les paramètres passés sont : '
52 52
 						.implode(',', $value));
53 53
 				}

+ 7
- 0
web/model/class.question.php View File

@@ -42,4 +42,11 @@ class Question {
42 42
 	function getBonneReponse() {
43 43
 		return $this->bonneReponse;
44 44
 	}
45
+
46
+	function getArray() {
47
+		return array(
48
+			"intitule" => utf8_encode($this->intitule),
49
+			"bonneReponse" => utf8_encode($this->bonneReponse)
50
+		);
51
+	}
45 52
 }

+ 8
- 3
web/model/class.questset.php View File

@@ -43,10 +43,15 @@ class Questset {
43 43
 	}
44 44
 
45 45
 	function getArray() {
46
-		$return = array();
46
+		$questions = array();
47 47
 		foreach($this->questions as $question) {
48
-			array_push($return, $question->getArray())
48
+			array_push($questions, $question->getArray());
49 49
 		}
50
-		return $return;
50
+
51
+		return array(
52
+			"reponse1" => utf8_encode($this->reponse1),
53
+			"reponse2" => utf8_encode($this->reponse2),
54
+			"questions" => $questions
55
+		);
51 56
 	}
52 57
 }

+ 17
- 0
web/questions.php View File

@@ -0,0 +1,17 @@
1
+<?php
2
+
3
+// Fichier de tests du modèle
4
+
5
+require_once('model/classes.php');
6
+header("Content-Type:application/json");
7
+
8
+try{
9
+	$categoriesObj = Categorie::randSelect();
10
+	$categories = array();
11
+	foreach($categoriesObj as $categorie) {
12
+		array_push($categories, $categorie->getArray());
13
+	}
14
+	echo json_encode($categories);
15
+}catch(Exception $e) {
16
+	echo("<strong>Erreur : </strong>".$e->getMessage());
17
+}

+ 0
- 12
web/test.php View File

@@ -1,12 +0,0 @@
1
-<?php
2
-
3
-// Fichier de tests du modèle
4
-
5
-require_once('model/classes.php');
6
-
7
-try{
8
-	$categories = Categorie::randSelect();
9
-	var_dump($categories);
10
-}catch(Exception $e) {
11
-	echo("<strong>Erreur : </strong>".$e->getMessage());
12
-}