From 3b2ee617d7b068896add0e7e1086199bab13fa50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?N=C3=A9munaire?= Date: Thu, 24 May 2012 20:19:42 +0200 Subject: [PATCH] We can now modify the Question object return by getQuestion --- Question.class.php | 2 +- QuestionsFile.class.php | 26 ++++++++++++++++++++------ validation.php | 7 +++++++ 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/Question.class.php b/Question.class.php index a11d8e2..b66b1fa 100644 --- a/Question.class.php +++ b/Question.class.php @@ -91,7 +91,7 @@ class Question $qnode->setAttribute("xml:id", $this->id); $qnode->setAttribute("addedtime", $this->added_time); - $qnode->setAttribute("validated", $this->validated); + $qnode->setAttribute("validated", intval($this->validated)); $qnode->setAttribute("validator", $this->validator); $qnode->setAttribute("course", $this->course); $qnode->setAttribute("question", $this->question); diff --git a/QuestionsFile.class.php b/QuestionsFile.class.php index 904dffc..3857c01 100644 --- a/QuestionsFile.class.php +++ b/QuestionsFile.class.php @@ -7,6 +7,7 @@ class QuestionsFile private $filename; private $treeXML; private $root_node; + private $tmp = array(); public function __construct($filename) { @@ -43,8 +44,7 @@ class QuestionsFile */ public function add_question($question) { - $qnode = $question->to_xml($this->treeXML); - $this->root_node->appendChild($qnode); + $this->tmp[$question->getId()] = $question; } /** @@ -52,11 +52,19 @@ class QuestionsFile */ public function get_question($id) { - $q = $this->treeXML->getElementById($id); - if (isset($q)) - return new Question($q); + if (isset($this->tmp[$id])) + return $this->tmp[$id]; else - return NULL; + { + $q = $this->treeXML->getElementById($id); + if (isset($q)) + { + $this->root_node->removeChild($q); + $this->tmp[$id] = new Question($q); + return $this->tmp[$id]; + } + } + return NULL; } /** @@ -64,6 +72,12 @@ class QuestionsFile */ public function save($newfilename = null) { + foreach ($this->tmp as $question) + { + $qnode = $question->to_xml($this->treeXML); + $this->root_node->appendChild($qnode); + } + if (!empty($newfilename)) $this->filename = $newfilename; diff --git a/validation.php b/validation.php index 48a6906..cd41ae9 100644 --- a/validation.php +++ b/validation.php @@ -8,6 +8,13 @@ $id = $_GET['id']; $file = new QuestionsFile("questions.xml"); $question = $file->get_question($id); +var_dump($question); + +$question->validated(); +$question->set_validator("other@pomail.fr"); +var_dump($question); +$file->save(); + ?>