Browse Source

Modèle de question presque complet

Brendan Abolivier 9 years ago
parent
commit
d08576a5e7
3 changed files with 58 additions and 1 deletions
  1. 53
    0
      web/model/class.categorie.php
  2. 1
    1
      web/model/class.connector.php
  3. 4
    0
      web/model/class.questset.php

+ 53
- 0
web/model/class.categorie.php View File

@@ -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
+}

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

@@ -26,7 +26,7 @@ class Connector {
26 26
 			"limit" => array(0, 10) // Ou array(10)
27 27
 		);
28 28
 	*/
29
-	function Select($fields, $tables, $options) {
29
+	function Select($fields, $tables, $options = array()) {
30 30
 		$request = "SELECT $fields FROM $tables ";
31 31
 		$arrayVerif = array();
32 32
 		foreach($options as $name=>$value) {

+ 4
- 0
web/model/class.questset.php View File

@@ -40,4 +40,8 @@ class Questset {
40 40
 	function getQuestions() {
41 41
 		return $this->questions;
42 42
 	}
43
+
44
+	function getLength() {
45
+		return sizeof($this->questions);
46
+	}
43 47
 }