Add classes to abstract Users and Courses

Can refuse a question (email the author)
Can modify question before validation
This commit is contained in:
Némunaire 2012-06-18 20:09:31 +02:00
commit 42fec70edf
14 changed files with 667 additions and 401 deletions

View file

@ -1,5 +1,8 @@
<?php
include_once("User.class.php");
include_once("Course.class.php");
class Question
{
private $id;
@ -9,6 +12,7 @@ class Question
private $added_time;
private $validated = false;
private $validator = "";
private $writer = "";
public function __construct($node = null)
{
@ -19,6 +23,7 @@ class Question
if (intval($node->getAttribute("validated")))
$this->validated = true;
$this->validator = $node->getAttribute("validator");
$this->writer = $node->getAttribute("writer");
$this->question = $node->getAttribute("question");
$this->course = $node->getAttribute("course");
@ -50,20 +55,19 @@ class Question
return $q;
}
public function regen_id()
{
$this->id = md5(time().$this->question.$this->validator);
}
public function set_validator($val)
{
$this->validator = $val;
$this->regen_id();
$this->validator = $val->getId();
}
public function get_writer()
{
return User::getUser($this->writer);
}
public function get_validator()
{
return $this->validator;
return User::getUser($this->validator);
}
public function print_test()
@ -99,6 +103,7 @@ class Question
$qnode->setAttribute("addedtime", $this->added_time);
$qnode->setAttribute("validated", intval($this->validated));
$qnode->setAttribute("validator", $this->validator);
$qnode->setAttribute("writer", $this->writer);
$qnode->setAttribute("course", $this->course);
$qnode->setAttribute("question", $this->question);
@ -111,6 +116,9 @@ class Question
public function validated()
{
$this->validated = true;
//Return to normal ID
$this->getNormalId();
}
public function getId()
@ -118,6 +126,18 @@ class Question
return $this->id;
}
public function getValidatorId()
{
$this->id = md5($this->added_time.$this->validator);
return $this->id;
}
public function getNormalId()
{
$this->id = md5($this->added_time.$this->writer);
return $this->id;
}
public function isValidated()
{
return $this->validated;
@ -125,12 +145,12 @@ class Question
public function getCourse()
{
return $this->course;
return Course::getCourse($this->course);
}
public function setCourse($course)
{
$this->course = $course;
$this->course = $course->getId();
}
public function getQuestion()
@ -148,17 +168,31 @@ class Question
return $this->answers;
}
public function getAnswersMail()
{
$str = "";
foreach($this->answers as $a)
$str .= " * ".$a."\n";
return $str;
}
public function set_writer($writer)
{
$this->writer = $writer->getId();
}
public function setAnswer($answers)
{
$this->answers = array();
if (!empty($answers))
{
if (is_array($answers))
{
foreach ($answers as $ans)
$q->answers[] = $ans;
$this->answers[] = $ans;
}
else
$q->answers[] = $answers;
$this->answers[] = $answers;
}
}