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("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);
|
||||
|
@ -7,6 +7,7 @@ class QuestionsFile
|
||||
private $filename;
|
||||
private $treeXML;
|
||||
private $root_node;
|
||||
private $tmp = array();
|
||||
|
||||
public function __construct($filename)
|
||||
{
|
||||
@ -43,19 +44,26 @@ class QuestionsFile
|
||||
*/
|
||||
public function add_question($question)
|
||||
{
|
||||
$qnode = $question->to_xml($this->treeXML);
|
||||
$this->root_node->appendChild($qnode);
|
||||
$this->tmp[$question->getId()] = $question;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a question from its unique identifiant
|
||||
*/
|
||||
public function get_question($id)
|
||||
{
|
||||
if (isset($this->tmp[$id]))
|
||||
return $this->tmp[$id];
|
||||
else
|
||||
{
|
||||
$q = $this->treeXML->getElementById($id);
|
||||
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;
|
||||
}
|
||||
|
||||
@ -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;
|
||||
|
||||
|
@ -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();
|
||||
|
||||
?>
|
||||
|
||||
<html>
|
||||
|
Reference in New Issue
Block a user