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
commit 3b2ee617d7
3 changed files with 28 additions and 7 deletions

View file

@ -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;