Plein de trucs fonctionnent maintenant
This commit is contained in:
parent
8758598104
commit
e3384eaa6b
22 changed files with 321 additions and 352 deletions
|
|
@ -16,29 +16,41 @@ class Exercice
|
|||
var $files = array();
|
||||
var $keys = array();
|
||||
|
||||
function Exercice($id=null)
|
||||
function Exercice($id=null, $theme=null)
|
||||
{
|
||||
if (!empty($id))
|
||||
{
|
||||
$db = new BDD();
|
||||
// TODO escape id ?
|
||||
$res = $db->unique_query("SELECT `id`, `id_theme`, `require`, `level`, `points`, `statement`
|
||||
FROM exercices
|
||||
WHERE id= '$id'");
|
||||
$res = $db->unique_query("SELECT id, id_theme, `require`, level, points, statement FROM exercices WHERE id = '$id'");
|
||||
|
||||
if (!empty($res))
|
||||
{
|
||||
$this->files = $db->query("SELECT `id`, `path`, `name`, `sha1`
|
||||
FROM exercice_files
|
||||
WHERE id_exercice = '$id'");
|
||||
// Decode sha1
|
||||
if ($this->files)
|
||||
foreach($this->files as &$f)
|
||||
$f["sha1"] = strhex($f["sha1"]);
|
||||
|
||||
$this->keys = $db->query("SELECT `id`, `format`, `value`
|
||||
FROM exercice_keys
|
||||
WHERE id_exercice = '$id'");
|
||||
|
||||
$db->deconnexion();
|
||||
|
||||
if (!empty($theme))
|
||||
{
|
||||
if ($res['id_theme'] == $theme->get_id())
|
||||
$this->theme = $theme;
|
||||
else
|
||||
throw new InvalidThemeException();
|
||||
}
|
||||
else
|
||||
$this->theme = new Theme($res['id_theme']);
|
||||
|
||||
$this->id = $res['id'];
|
||||
$this->theme = new Theme($res['id_theme']);
|
||||
$this->require = $res['require'];
|
||||
$this->level = $res['level'];
|
||||
$this->points = $res['points'];
|
||||
|
|
@ -49,6 +61,7 @@ class Exercice
|
|||
else
|
||||
{
|
||||
$db->deconnexion();
|
||||
throw new ExerciceNotFoundException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -58,6 +71,11 @@ class Exercice
|
|||
return $this->id;
|
||||
}
|
||||
|
||||
function get_name()
|
||||
{
|
||||
return "Exercice ".$this->number;
|
||||
}
|
||||
|
||||
// retourne le nombre d'equipes qui ont résolues l'exercice
|
||||
// trié par date
|
||||
function get_solved()
|
||||
|
|
@ -66,7 +84,7 @@ class Exercice
|
|||
|
||||
// TODO rename time by date in db ?
|
||||
$res = $db->query("SELECT `id_team`, `time` FROM solved
|
||||
WHERE id_exercice= '$this->id'
|
||||
WHERE id_exercice = '$this->id'
|
||||
ORDER BY time");
|
||||
|
||||
$db->deconnexion();
|
||||
|
|
@ -74,6 +92,23 @@ class Exercice
|
|||
return $res;
|
||||
}
|
||||
|
||||
function is_unlocked($team)
|
||||
{
|
||||
//TODO
|
||||
return mt_rand(0,1);
|
||||
}
|
||||
|
||||
function has_solved($team)
|
||||
{
|
||||
$db = new BDD();
|
||||
|
||||
$res = $db->unique_query("SELECT `time` FROM solved WHERE id_exercice = '$this->id' AND id_team = ".intval($team->get_id()));
|
||||
|
||||
$db->deconnexion();
|
||||
|
||||
return $res["time"];
|
||||
}
|
||||
|
||||
function set_number()
|
||||
{
|
||||
if ($this->require == "")
|
||||
|
|
@ -223,3 +258,11 @@ class Exercice
|
|||
return $res['max'];
|
||||
}
|
||||
}
|
||||
|
||||
class ExerciceNotFoundException extends Exception
|
||||
{
|
||||
}
|
||||
|
||||
class InvalidThemeException extends Exception
|
||||
{
|
||||
}
|
||||
|
|
@ -65,7 +65,7 @@ class Theme
|
|||
$db = new BDD();
|
||||
$res = $db->unique_query("SELECT count( id ) as nb_exercices FROM exercices
|
||||
WHERE id_theme = ".$this->id."
|
||||
GROUP BY id_theme");
|
||||
GROUP BY id_theme");
|
||||
$db->deconnexion();
|
||||
|
||||
return $res['nb_exercices'];
|
||||
|
|
@ -81,20 +81,6 @@ class Theme
|
|||
return false;
|
||||
}
|
||||
|
||||
public static function get_themes()
|
||||
{
|
||||
$db = new BDD();
|
||||
$ids = $db->query("SELECT `id` FROM `themes`");
|
||||
$db->deconnexion();
|
||||
|
||||
$array = array();
|
||||
foreach ($ids as $id){
|
||||
$array[] = new Theme($id['id']);
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
function get_exercicesOrdered()
|
||||
{
|
||||
$db = new BDD();
|
||||
|
|
@ -136,4 +122,18 @@ class Theme
|
|||
|
||||
return $res;
|
||||
}
|
||||
|
||||
public static function get_themes()
|
||||
{
|
||||
$db = new BDD();
|
||||
$ids = $db->query("SELECT `id` FROM `themes`");
|
||||
$db->deconnexion();
|
||||
|
||||
$array = array();
|
||||
foreach ($ids as $id) {
|
||||
$array[] = new Theme($id['id']);
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Reference in a new issue