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