2012-05-19 09:02:31 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class Question
|
|
|
|
{
|
2012-05-22 01:34:24 +00:00
|
|
|
private $id;
|
|
|
|
private $question;
|
|
|
|
private $course;
|
|
|
|
private $answers = array();
|
|
|
|
private $added_time;
|
|
|
|
private $validated = false;
|
|
|
|
private $validator = "";
|
2012-05-19 09:02:31 +00:00
|
|
|
|
|
|
|
public function __construct($node = null)
|
|
|
|
{
|
2012-05-22 01:34:24 +00:00
|
|
|
if (isset($node))
|
|
|
|
{
|
|
|
|
$this->id = $node->getAttribute("id");
|
|
|
|
$this->added_time = $node->getAttribute("addedtime");
|
|
|
|
if (intval($node->getAttribute("validated")))
|
|
|
|
$this->validated = true;
|
|
|
|
$this->validator = $node->getAttribute("validator");
|
|
|
|
$this->question = $node->getAttribute("question");
|
|
|
|
$this->course = $node->getAttribute("course");
|
2012-05-22 07:38:37 +00:00
|
|
|
|
2012-05-23 15:45:12 +00:00
|
|
|
$answers = $node->getElementsByTagName("answer");
|
2012-05-22 01:34:24 +00:00
|
|
|
for ($i = 0; $i < $answers->length; $i++)
|
|
|
|
$this->answers[] = $answers->item($i)->getAttribute("answer");
|
|
|
|
}
|
2012-05-19 09:02:31 +00:00
|
|
|
}
|
|
|
|
|
2012-05-22 01:34:24 +00:00
|
|
|
public static function new_Question($question, $answers, $course = null)
|
2012-05-19 09:02:31 +00:00
|
|
|
{
|
|
|
|
$q = new Question();
|
|
|
|
$q->id = md5(time().$question);
|
|
|
|
$q->added_time = time();
|
|
|
|
$q->question = $question;
|
2012-05-22 01:34:24 +00:00
|
|
|
$q->course = $course;
|
2012-05-19 09:02:31 +00:00
|
|
|
|
|
|
|
if (!empty($answers))
|
|
|
|
{
|
|
|
|
if (is_array($answers))
|
|
|
|
{
|
2012-05-22 01:34:24 +00:00
|
|
|
foreach ($answers as $ans)
|
|
|
|
$q->answers[] = $ans;
|
2012-05-19 09:02:31 +00:00
|
|
|
}
|
|
|
|
else
|
2012-05-22 01:34:24 +00:00
|
|
|
$q->answers[] = $answers;
|
2012-05-19 09:02:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return $q;
|
|
|
|
}
|
|
|
|
|
2012-05-22 01:34:24 +00:00
|
|
|
public function print_test()
|
|
|
|
{
|
|
|
|
echo 'Cours concerné : ' . $this->course . "<br>";
|
|
|
|
echo 'La question est : ' . $this->question . "<br>";
|
2012-05-22 07:39:52 +00:00
|
|
|
echo 'Les réponses sont : ' . print_r($this->answers, true) . "<br/>";
|
2012-05-22 07:38:37 +00:00
|
|
|
echo 'ID : ' . $this->id;
|
2012-05-22 01:34:24 +00:00
|
|
|
}
|
|
|
|
|
2012-05-19 09:02:31 +00:00
|
|
|
/**
|
|
|
|
* Generate and fill an answer node
|
|
|
|
* @param $answer The answer string
|
|
|
|
* @param $scrore The score given by this answer
|
|
|
|
*/
|
2012-05-22 08:44:16 +00:00
|
|
|
private function gen_anode($treeXML, $answer, $score = 1)
|
2012-05-19 09:02:31 +00:00
|
|
|
{
|
2012-05-22 08:44:16 +00:00
|
|
|
$anode = $treeXML->createElement("answer");
|
2012-05-19 09:02:31 +00:00
|
|
|
|
2012-05-22 08:44:16 +00:00
|
|
|
$anode->setAttribute("answer", $answer);
|
|
|
|
$anode->setAttribute("score", $score);
|
2012-05-19 09:02:31 +00:00
|
|
|
|
|
|
|
return $anode;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generate XML corresponding to this question
|
|
|
|
*/
|
|
|
|
public function to_xml($root)
|
|
|
|
{
|
|
|
|
$qnode = $root->createElement("question");
|
|
|
|
|
2012-05-23 15:45:12 +00:00
|
|
|
$qnode->setAttribute("xml:id", $this->id);
|
2012-05-19 09:02:31 +00:00
|
|
|
$qnode->setAttribute("addedtime", $this->added_time);
|
|
|
|
$qnode->setAttribute("validated", $this->validated);
|
|
|
|
$qnode->setAttribute("validator", $this->validator);
|
2012-05-22 01:34:24 +00:00
|
|
|
$qnode->setAttribute("course", $this->course);
|
2012-05-19 09:02:31 +00:00
|
|
|
$qnode->setAttribute("question", $this->question);
|
|
|
|
|
2012-05-22 08:44:16 +00:00
|
|
|
foreach ($this->answers as $ans)
|
|
|
|
$qnode->appendChild($this->gen_anode($root, $ans));
|
2012-05-19 09:02:31 +00:00
|
|
|
|
|
|
|
return $qnode;
|
|
|
|
}
|
2012-05-22 14:05:46 +00:00
|
|
|
|
2012-05-23 12:56:34 +00:00
|
|
|
public function validated()
|
2012-05-22 14:05:46 +00:00
|
|
|
{
|
|
|
|
$this->validated = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getId()
|
|
|
|
{
|
|
|
|
return $this->id;
|
|
|
|
}
|
2012-05-19 09:02:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
?>
|