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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,4 +2,9 @@
|
|||
|
||||
if(!defined('ONYX')) exit;
|
||||
|
||||
$page = "public/score";
|
||||
$template->assign("themes", Theme::get_themes());
|
||||
$template->assign("nbExoMax", Exercice::get_nbExoMax());
|
||||
|
||||
$template->assign("my_team", new TEAM($TEAM));
|
||||
|
||||
return "public/score";
|
||||
|
|
|
|||
|
|
@ -1,5 +0,0 @@
|
|||
<?php
|
||||
|
||||
if(!defined('ONYX')) exit;
|
||||
|
||||
return "teams/confirmation";
|
||||
|
|
@ -2,35 +2,20 @@
|
|||
|
||||
if(!defined('ONYX')) exit;
|
||||
|
||||
try
|
||||
$solved = count($EXERCICE->get_solved());
|
||||
|
||||
if ($n == 5 && $p[4] == "submission")
|
||||
{
|
||||
$exercice = new Exercice($EXERCICE);
|
||||
$template->assign("ERRcolor", "success");
|
||||
$template->assign("ERRmessage", "Votre réponse a bien été prise en compte et sera évaluée dans quelques instants...");
|
||||
|
||||
//TOP10
|
||||
// $template->assign("top10", Team::get_top(10));
|
||||
//
|
||||
// //RANK
|
||||
// $template->assign("my_team", new Team($TEAM));
|
||||
//
|
||||
// //BEGIN LISTING THEMES
|
||||
// $template->assign("themes", Theme::get_themes());
|
||||
|
||||
if (!isset($exercice->id))
|
||||
return "404";
|
||||
|
||||
if (!isset($exercice->theme) || $exercice->theme->name != $THEME)
|
||||
return "404";
|
||||
|
||||
$solved = count($exercice->get_solved());
|
||||
|
||||
$template->assign("Exercice", $exercice);
|
||||
$template->assign("team", $TEAM);
|
||||
$template->assign("solved", $solved);
|
||||
$template->assign("files", $exercice->files);
|
||||
|
||||
return "teams/exercice";
|
||||
}
|
||||
catch(Exception $e)
|
||||
{
|
||||
return "404";
|
||||
if (!empty($_POST["solution"]))
|
||||
{
|
||||
header("Location: /".implode("/", $p));
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
$template->assign("solved", $solved);
|
||||
|
||||
return "teams/exercice";
|
||||
|
|
|
|||
|
|
@ -2,12 +2,10 @@
|
|||
|
||||
if(!defined('ONYX')) exit;
|
||||
|
||||
$team = new Team($TEAM);
|
||||
//$solvedExercices = $team->get_solvedExercices();
|
||||
//$solvedExercices = $TEAM->get_solvedExercices();
|
||||
|
||||
$template->assign("themes", Theme::get_themes());
|
||||
$template->assign("nbExoMax", Exercice::get_nbExoMax());
|
||||
$template->assign("team", $team);
|
||||
//$template->assign("solvedExercices", $solvedExercices);
|
||||
|
||||
return "teams/summary";
|
||||
|
|
|
|||
|
|
@ -2,15 +2,4 @@
|
|||
|
||||
if(!defined('ONYX')) exit;
|
||||
|
||||
try
|
||||
{
|
||||
$team = new Team($TEAM);
|
||||
|
||||
$template->assign("team", $team);
|
||||
|
||||
return "teams/team";
|
||||
}
|
||||
catch(Exception $e)
|
||||
{
|
||||
return "404";
|
||||
}
|
||||
return "teams/team";
|
||||
|
|
|
|||
Reference in a new issue