From 48a77a0d10b4f6e22cdb6fa3788967ec38d29a8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?N=C3=A9munaire?= Date: Tue, 22 May 2012 03:34:24 +0200 Subject: [PATCH] Fix simples errors in the two classes JavaScript now generates inputs with a unique name Add todo in questions.php and manage multiple answers; start using Question class --- Question.class.php | 56 +++++++++++++++++++++++++---------------- QuestionsFile.class.php | 6 ++--- index.html | 6 +++-- questions.php | 43 ++++++++++++++++++++++++------- 4 files changed, 76 insertions(+), 35 deletions(-) diff --git a/Question.class.php b/Question.class.php index 1c3ea39..107e7ad 100644 --- a/Question.class.php +++ b/Question.class.php @@ -2,48 +2,61 @@ class Question { - private var $id; - private var $question; - private var $answers = array(); - private var $added_time; - private var $validated = false; - private var $validator = ""; + private $id; + private $question; + private $course; + private $answers = array(); + private $added_time; + private $validated = false; + private $validator = ""; public function __construct($node = null) { - $this->id = $node->getAttribute("id"); - $this->added_time = $node->getAttribute("addedtime"); - if (intval($node->getAttribute("validated"))) - $this->validated = true; - $this->validator = $node->getAttribute("validator"); - $this->question = $node->getAttribute("question"); - - $answers = $node->getElementByTagName("answer"); - for ($i = 0; $i < $answers->length; $i++) - $this->answers[] = $answers->item($i)->getAttribute("answer"); + if (isset($node)) + { + $this->id = $node->getAttribute("id"); + $this->added_time = $node->getAttribute("addedtime"); + if (intval($node->getAttribute("validated"))) + $this->validated = true; + $this->validator = $node->getAttribute("validator"); + $this->question = $node->getAttribute("question"); + $this->course = $node->getAttribute("course"); + + $answers = $node->getElementByTagName("answer"); + for ($i = 0; $i < $answers->length; $i++) + $this->answers[] = $answers->item($i)->getAttribute("answer"); + } } - public static function new_Question($question, $answers = null) + public static function new_Question($question, $answers, $course = null) { $q = new Question(); $q->id = md5(time().$question); $q->added_time = time(); $q->question = $question; + $q->course = $course; if (!empty($answers)) { if (is_array($answers)) { - foreach ($answers => $ans) - $this->answers[] = $ans; + foreach ($answers as $ans) + $q->answers[] = $ans; } else - $this->answers[] = $answers; + $q->answers[] = $answers; } return $q; } + public function print_test() + { + echo 'Cours concerné : ' . $this->course . "
"; + echo 'La question est : ' . $this->question . "
"; + echo 'Les réponses sont : ' . print_r($this->answers, true); + } + /** * Generate and fill an answer node * @param $answer The answer string @@ -70,9 +83,10 @@ class Question $qnode->setAttribute("addedtime", $this->added_time); $qnode->setAttribute("validated", $this->validated); $qnode->setAttribute("validator", $this->validator); + $qnode->setAttribute("course", $this->course); $qnode->setAttribute("question", $this->question); - foreach ($answers => $ans) + foreach ($answers as $ans) $qnode->appendChild(gen_anode($ans)); return $qnode; diff --git a/QuestionsFile.class.php b/QuestionsFile.class.php index 33fc604..5cfc12a 100644 --- a/QuestionsFile.class.php +++ b/QuestionsFile.class.php @@ -1,11 +1,11 @@ Every Questions