Bläddra i källkod

Travail du modèle

Brendan Abolivier 9 år sedan
förälder
incheckning
7d7d57d79c

+ 1
- 1
web/index.php Visa fil

@@ -1,6 +1,6 @@
1 1
 <?php
2 2
 
3
-require_once('classes.php');
3
+require_once('model/classes.php');
4 4
 
5 5
 header("Content-Type:application/json");
6 6
 

web/class.connector.php → web/model/class.connector.php Visa fil


+ 45
- 0
web/model/class.question.php Visa fil

@@ -0,0 +1,45 @@
1
+<?php
2
+
3
+class Question {
4
+	private $reponse1;
5
+	private $reponse2;
6
+	private $intitule;
7
+	private $bonneReponse;
8
+
9
+	function __construct($intitule) {
10
+		try{
11
+			$this->intitule;
12
+
13
+			$bdd = new Connector();
14
+
15
+			$options = array(
16
+				"where" => array(
17
+					array("intitule", "=", $intitule)
18
+				)
19
+			);
20
+			$question = $bdd->Select('*', 'questions', $options);
21
+
22
+			$this->reponse1 = $question[0]['reponse1'];
23
+			$this->reponse2 = $question[0]['reponse2'];
24
+			
25
+			$this->bonneReponse = $question[0]['num_reponse'];
26
+		} catch(Exception $e) {
27
+			throw $e;
28
+		}
29
+	}
30
+
31
+	function getIntitule() {
32
+		return $this->intitule;
33
+	}
34
+
35
+	function getReponses() {
36
+		return array(
37
+			"reponse1" => $this->reponse1,
38
+			"reponse2" => $this->reponse2
39
+		);
40
+	}
41
+
42
+	function getBonneReponse() {
43
+		return $this->bonneReponse;
44
+	}
45
+}

web/class.questset.php → web/model/class.questset.php Visa fil

@@ -4,15 +4,15 @@ class Questset {
4 4
 	private $categorie;
5 5
 	private $reponse1;
6 6
 	private $reponse2;
7
-	private $intitules;
8
-	private $bdd;
7
+	private $questions;
9 8
 
10 9
 	function __construct($reponses) {
11 10
 		if(is_array($reponses)) {
11
+			$this->intitules = array();
12 12
 			$this->reponse1 = $reponse[0];
13 13
 			$this->reponse2 = $reponse[1];
14 14
 			try {
15
-				$this->bdd = new Connector();
15
+				$bdd = new Connector();
16 16
 
17 17
 				$options = array(
18 18
 					"where" => array(
@@ -21,7 +21,13 @@ class Questset {
21 21
 					)
22 22
 				);
23 23
 
24
+				$questions = $bdd->Select('*', 'questions', $options);
24 25
 
26
+				foreach($questions as $question) {
27
+					array_push($this->questions, new Question($question['intitule']));
28
+				}
29
+
30
+				$this->categorie = $bdd->Select('*', 'reponses', $options)['nom_cat'];
25 31
 			} catch(Exception $e) {
26 32
 				throw $e;
27 33
 			}
@@ -29,4 +35,8 @@ class Questset {
29 35
 			throw new Exception('Un tableau de réponses est attendu dans le constructeur.');
30 36
 		}
31 37
 	}
38
+
39
+	function getQuestions() {
40
+		return $this->questions;
41
+	}
32 42
 }

web/classes.php → web/model/classes.php Visa fil

@@ -1,4 +1,5 @@
1 1
 <?php
2 2
 
3 3
 require_once('class.connector.php');
4
+require_once('class.questions.php');
4 5
 require_once('class.questset.php');

+ 12
- 0
web/test.php Visa fil

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

web/palmares.php → web/view/palmares.php Visa fil

@@ -1,12 +1,12 @@
1 1
 <?php
2 2
 
3
-require_once('classes.php');
3
+require_once('../model/classes.php');
4 4
 
5 5
 $bdd = new Connector();
6 6
 
7 7
 $options = array(
8 8
 	"order by" => array("score", "desc"),
9
-	"limit" => array(0, 10) // Ou array(10)
9
+	"limit" => array(10)
10 10
 );
11 11
 
12 12
 try {
@@ -15,10 +15,4 @@ try {
15 15
 	echo("Erreur : ".$e->getMessage());
16 16
 }
17 17
 
18
-echo("<ol>");
19
-
20
-foreach($res as $row) {
21
-	echo(utf8_encode("<li>".$row["login"]." (".$row["score"].")</li>"));
22
-}
23
-
24
-echo("</ol>");
18
+// $res contient les résultats