Exercice.class: Fixed the constructor, add get_solved and set_number

This commit is contained in:
Li Chen 2013-11-04 23:49:18 +01:00
parent e571151456
commit 41b83ef725

View File

@ -7,6 +7,7 @@ if(!defined('ONYX')) exit;
class Exercice
{
var $id = null;
var $number;
var $theme;
var $require;
var $level;
@ -27,22 +28,63 @@ class Exercice
if (!empty($res))
{
$this->id = $res['id'];
$this->theme = new Theme($res['id_theme']);
$this->require = $res['require'];
$this->level = $res['level'];
$this->points = $res['points'];
$this->statement = $res['statement'];
$this->files = $db->query("SELECT `id`, `path`, `name`
FROM exercice_files
WHERE id_exercice = '$id'");
$this->keys = $db->query("SELECT `id`, `format`, `value`
FROM exercice_keys
WHERE id_exercice = '$id'");
$db->deconnexion();
$this->id = $res['id'];
$this->theme = new Theme($res['id_theme']);
$this->require = $res['require'];
$this->level = $res['level'];
$this->points = $res['points'];
$this->statement = $res['statement'];
$this->set_number();
}
else
{
$db->deconnexion();
}
}
}
// retourne le nombre d'equipes qui ont résolues l'exercice
// trié par date
function get_solved()
{
$db = new BDD();
// TODO rename time by date in db ?
$res = $db->query("SELECT `id_team`, `time` FROM solved
WHERE id_exercice= '$this->id'
ORDER BY time");
$db->deconnexion();
return $res;
}
function set_number()
{
if ($this->require == "")
$this->number = 1;
$exo = $this;
$ret = 1;
do
{
$exo = new Exercice($exo->require);
$ret++;
} while ($exo->require != "");
$this->number = $ret;
}
function update($create)
{