Fix lots of bugs in classes (now correctly creating file)
This commit is contained in:
parent
6885c2883c
commit
9b545226d2
@ -63,12 +63,12 @@ class Question
|
|||||||
* @param $answer The answer string
|
* @param $answer The answer string
|
||||||
* @param $scrore The score given by this answer
|
* @param $scrore The score given by this answer
|
||||||
*/
|
*/
|
||||||
private function gen_anode($answer, $score = 1)
|
private function gen_anode($treeXML, $answer, $score = 1)
|
||||||
{
|
{
|
||||||
$anode = $this->treeXML->createElement("answer");
|
$anode = $treeXML->createElement("answer");
|
||||||
|
|
||||||
$qnode->setAttribute("answer", $answer);
|
$anode->setAttribute("answer", $answer);
|
||||||
$qnode->setAttribute("score", $score);
|
$anode->setAttribute("score", $score);
|
||||||
|
|
||||||
return $anode;
|
return $anode;
|
||||||
}
|
}
|
||||||
@ -87,8 +87,8 @@ class Question
|
|||||||
$qnode->setAttribute("course", $this->course);
|
$qnode->setAttribute("course", $this->course);
|
||||||
$qnode->setAttribute("question", $this->question);
|
$qnode->setAttribute("question", $this->question);
|
||||||
|
|
||||||
foreach ($answers as $ans)
|
foreach ($this->answers as $ans)
|
||||||
$qnode->appendChild(gen_anode($ans));
|
$qnode->appendChild($this->gen_anode($root, $ans));
|
||||||
|
|
||||||
return $qnode;
|
return $qnode;
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ class QuestionsFile
|
|||||||
{
|
{
|
||||||
private $filename;
|
private $filename;
|
||||||
private $treeXML;
|
private $treeXML;
|
||||||
|
private $root_node;
|
||||||
|
|
||||||
public function __construct($filename)
|
public function __construct($filename)
|
||||||
{
|
{
|
||||||
@ -22,7 +23,7 @@ class QuestionsFile
|
|||||||
$this->treeXML = new DOMDocument('1.0', 'UTF-8');
|
$this->treeXML = new DOMDocument('1.0', 'UTF-8');
|
||||||
$this->treeXML->formatOutput = true;
|
$this->treeXML->formatOutput = true;
|
||||||
|
|
||||||
if (isfile($this->filename))
|
if (is_file($this->filename))
|
||||||
{
|
{
|
||||||
$this->treeXML->load($this->filename);
|
$this->treeXML->load($this->filename);
|
||||||
|
|
||||||
@ -45,7 +46,7 @@ class QuestionsFile
|
|||||||
*/
|
*/
|
||||||
public function add_question($question)
|
public function add_question($question)
|
||||||
{
|
{
|
||||||
$this->root_node->appendChild($question->to_xml($this->root_node));
|
$this->root_node->appendChild($question->to_xml($this->treeXML));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
define("FILENAME", "questions_file.nemubot");
|
define("FILENAME", "questions_file.nemubot");
|
||||||
|
|
||||||
include("Question.class.php");
|
include("Question.class.php");
|
||||||
include("QuestionsFile.php");
|
include("QuestionsFile.class.php");
|
||||||
|
|
||||||
if (isset ($_POST['send']))
|
if (isset ($_POST['send']))
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user