We can now modify the Question object return by getQuestion
This commit is contained in:
parent
f8b1fbbd82
commit
3b2ee617d7
@ -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);
|
||||||
|
@ -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,8 +44,7 @@ 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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -52,11 +52,19 @@ class QuestionsFile
|
|||||||
*/
|
*/
|
||||||
public function get_question($id)
|
public function get_question($id)
|
||||||
{
|
{
|
||||||
$q = $this->treeXML->getElementById($id);
|
if (isset($this->tmp[$id]))
|
||||||
if (isset($q))
|
return $this->tmp[$id];
|
||||||
return new Question($q);
|
|
||||||
else
|
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)
|
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;
|
||||||
|
|
||||||
|
@ -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>
|
||||||
|
Reference in New Issue
Block a user