We can now modify the Question object return by getQuestion

This commit is contained in:
Némunaire 2012-05-24 20:19:42 +02:00
parent f8b1fbbd82
commit 3b2ee617d7
3 changed files with 28 additions and 7 deletions

View File

@ -91,7 +91,7 @@ class Question
$qnode->setAttribute("xml:id", $this->id); $qnode->setAttribute("xml:id", $this->id);
$qnode->setAttribute("addedtime", $this->added_time); $qnode->setAttribute("addedtime", $this->added_time);
$qnode->setAttribute("validated", $this->validated); $qnode->setAttribute("validated", intval($this->validated));
$qnode->setAttribute("validator", $this->validator); $qnode->setAttribute("validator", $this->validator);
$qnode->setAttribute("course", $this->course); $qnode->setAttribute("course", $this->course);
$qnode->setAttribute("question", $this->question); $qnode->setAttribute("question", $this->question);

View File

@ -7,6 +7,7 @@ class QuestionsFile
private $filename; private $filename;
private $treeXML; private $treeXML;
private $root_node; private $root_node;
private $tmp = array();
public function __construct($filename) public function __construct($filename)
{ {
@ -43,19 +44,26 @@ class QuestionsFile
*/ */
public function add_question($question) public function add_question($question)
{ {
$qnode = $question->to_xml($this->treeXML); $this->tmp[$question->getId()] = $question;
$this->root_node->appendChild($qnode);
} }
/** /**
* Get a question from its unique identifiant * Get a question from its unique identifiant
*/ */
public function get_question($id) public function get_question($id)
{
if (isset($this->tmp[$id]))
return $this->tmp[$id];
else
{ {
$q = $this->treeXML->getElementById($id); $q = $this->treeXML->getElementById($id);
if (isset($q)) if (isset($q))
return new Question($q); {
else $this->root_node->removeChild($q);
$this->tmp[$id] = new Question($q);
return $this->tmp[$id];
}
}
return NULL; return NULL;
} }
@ -64,6 +72,12 @@ class QuestionsFile
*/ */
public function save($newfilename = null) public function save($newfilename = null)
{ {
foreach ($this->tmp as $question)
{
$qnode = $question->to_xml($this->treeXML);
$this->root_node->appendChild($qnode);
}
if (!empty($newfilename)) if (!empty($newfilename))
$this->filename = $newfilename; $this->filename = $newfilename;

View File

@ -8,6 +8,13 @@ $id = $_GET['id'];
$file = new QuestionsFile("questions.xml"); $file = new QuestionsFile("questions.xml");
$question = $file->get_question($id); $question = $file->get_question($id);
var_dump($question);
$question->validated();
$question->set_validator("other@pomail.fr");
var_dump($question);
$file->save();
?> ?>
<html> <html>