Code cleaned

This commit is contained in:
Li Chen 2013-11-12 16:52:50 +01:00
parent f7f277d46b
commit 2d77512cdc
13 changed files with 58 additions and 63 deletions

View File

@ -132,7 +132,7 @@ else if ($n && $p[0] == SALT_USER)
$id_exo = $p[3];
else if ($n == 3)
{
foreach($THEME->get_exercicesOrdered() as $exo)
foreach($THEME->get_exercices_ordered() as $exo)
{
if (! $exo->has_solved($TEAM))
break;

View File

@ -19,8 +19,10 @@ class Exercice
if (!empty($id))
{
$db = new BDD();
// TODO escape id ?
$res = $db->unique_query("SELECT id, id_theme, `require`, level, points, statement
$db->escape($id);
$res = $db->unique_query("SELECT `id`, `id_theme`, `require`, `level`,
`points`, `statement`
FROM exercices WHERE id = '$id'");
if (!empty($res))
@ -81,7 +83,6 @@ class Exercice
{
$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");
@ -256,7 +257,7 @@ class Exercice
);
}
public static function get_nbExoMax()
public static function get_nb_exo_max()
{
$db = new BDD();
$res = $db->unique_query("SELECT count(id) AS max FROM exercices

View File

@ -28,8 +28,8 @@ class Team
if (!empty($id))
{
$db = new BDD();
$res = $db->unique_query("SELECT id, team_name, key_hash, slogan, auth_level
FROM teams WHERE id=" . intval($id)) or die($db->erreur());
$res = $db->unique_query("SELECT `id`, `team_name`, `key_hash`, `slogan`, `auth_level`
FROM teams WHERE id = ".intval($id)) or die($db->erreur());
if (!empty($res))
{
@ -97,8 +97,8 @@ class Team
{
$db = new BDD();
$res = $db->query("SELECT id FROM team_members
WHERE id_team = " . intval($this->id));
$res = $db->query("SELECT `id` FROM team_members
WHERE id_team = ".intval($this->id));
$db->deconnexion();
@ -115,11 +115,11 @@ class Team
{
$db = new BDD();
$res = $db->unique_query("SELECT e.id, s.id_team, SUM(e.points) as sum_points
FROM exercices e
LEFT OUTER JOIN solved s ON e.id = s.id_exercice
WHERE s.id_team = " . $this->id . "
GROUP BY s.id_team");
$res = $db->unique_query("SELECT E.id, S.id_team, SUM(E.points) as sum_points
FROM exercices E
LEFT OUTER JOIN solved S ON E.id = S.id_exercice
WHERE S.id_team = ".$this->id."
GROUP BY S.id_team");
$db->deconnexion();
@ -132,7 +132,7 @@ class Team
return $this->points;
}
function get_groupIds()
function get_group_ids()
{
$db = new BDD();
@ -154,42 +154,40 @@ class Team
return 0;
}
function get_nbResExercisesByTheme($id_theme)
function get_nb_res_exercises_by_theme($id_theme)
{
$db = new BDD();
$res = $db->unique_query("SELECT e.id_theme AS theme, count( s.id ) AS solved
FROM solved AS s
RIGHT OUTER JOIN exercices AS e ON e.id = s.id_exercice
AND s.id_team = ".$this->id."
AND e.id_theme = ".$id_theme);
$res = $db->unique_query("SELECT E.id_theme AS theme, count(S.id) AS solved
FROM solved S
RIGHT OUTER JOIN exercices E ON E.id = S.id_exercice
AND S.id_team = ".$this->id."
AND E.id_theme = ".$id_theme);
$db->deconnexion();
return $res['solved'];
}
function get_solvedExercices($id_theme=-1)
function get_solved_exercices($id_theme=-1)
{
if ($id_theme != -1)
{
$db = new BDD();
$ids = $db->query("SELECT id_theme, id_exercice
FROM `solved`
LEFT OUTER JOIN exercices ON `solved`.id_exercice = `exercices`.id
$ids = $db->query("SELECT `id_theme`, `id_exercice`
FROM solved S
LEFT OUTER JOIN exercices E ON S.id_exercice = E.id
WHERE id_team =".$this->id." AND id_theme =".$id_theme);
$db->deconnexion();
$array = array();
$i = 0;
if ($ids)
{
foreach ($ids as $id){
$array[] = new Exercice($id['id_exercice']);
$array = array();
$i = 0;
if ($ids)
{
foreach ($ids as $id){
$array[] = new Exercice($id['id_exercice']);
}
}
}
return $array;
return $array;
}
return NULL;
}
@ -226,7 +224,7 @@ class Team
return $teams;
}
public static function get_nbTeams()
public static function get_nb_teams()
{
$db = new BDD();
$res = $db->unique_query("SELECT COUNT(id) as count_teams FROM teams");
@ -234,5 +232,4 @@ class Team
return $res['count_teams'];
}
}

View File

@ -12,7 +12,7 @@ class Theme
if (!empty($id))
{
$db = new BDD();
$res = $db->unique_query("SELECT id, name
$res = $db->unique_query("SELECT `id`, `name`
FROM themes WHERE id=" . intval($id));
if (!empty($res))
@ -41,8 +41,8 @@ class Theme
else
{
$db->query("UPDATE themes
SET name = '".$name."'
WHERE id = ".intval($this->id));
SET name = '".$name."'
WHERE id = ".intval($this->id));
$aff = $db->affected();
}
$db->deconnexion();
@ -60,12 +60,12 @@ class Theme
return $this->id;
}
function get_nbExercices()
function get_nb_exercices()
{
$db = new BDD();
$res = $db->unique_query("SELECT count( id ) as nb_exercices FROM exercices
WHERE id_theme = ".$this->id."
GROUP BY id_theme");
$res = $db->unique_query("SELECT count(id) as nb_exercices FROM exercices
WHERE id_theme = ".$this->id."
GROUP BY id_theme");
$db->deconnexion();
return $res['nb_exercices'];
@ -81,7 +81,7 @@ class Theme
return false;
}
function get_exercicesOrdered()
function get_exercices_ordered()
{
$db = new BDD();
$res = $db->query("SELECT E.id, E.require FROM exercices E

View File

@ -5,6 +5,6 @@ if(!defined('ONYX')) exit;
$template->assign("teams", Team::get_teams());
$template->assign("top", Team::get_top(10));
$template->assign("themes", Theme::get_themes());
$template->assign("nbExoMax", Exercice::get_nbExoMax());
$template->assign("nbExoMax", Exercice::get_nb_exo_max());
return "public/home";

View File

@ -3,7 +3,7 @@
if(!defined('ONYX')) exit;
$template->assign("themes", Theme::get_themes());
$template->assign("nbExoMax", Exercice::get_nbExoMax());
$template->assign("nbExoMax", Exercice::get_nb_exo_max());
$template->assign("my_team", new TEAM($TEAM));

View File

@ -2,10 +2,7 @@
if(!defined('ONYX')) exit;
//$solvedExercices = $TEAM->get_solvedExercices();
$template->assign("themes", Theme::get_themes());
$template->assign("nbExoMax", Exercice::get_nbExoMax());
//$template->assign("solvedExercices", $solvedExercices);
$template->assign("nbExoMax", Exercice::get_nb_exo_max());
return "teams/summary";

View File

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<theme>
<title>{$theme->get_name()}</title>
{if $theme->get_exercicesOrdered()}
{foreach from=$theme->get_exercicesOrdered() item=e}
{if $theme->get_exercices_ordered()}
{foreach from=$theme->get_exercices_ordered() item=e}
<exercice id="{$e->id}" level="{$e->level}"{if $e->require} depends="{$e->require}"{/if}>
<title>{$e->get_name()}</title>
<points>{$e->points}</points>

View File

@ -20,7 +20,7 @@
<li class="dropdown{if $menu_where == $t->get_name()} active{/if}">
<a href="/{$SALT_ADMIN}/{$t->get_id()}-{$t->get_name()}" class="dropdown-toggle" data-toggle="dropdown">{$t->get_name()} <b class="caret"></b></a>
<ul class="dropdown-menu">
{foreach from=$t->get_exercicesOrdered() item=e}
{foreach from=$t->get_exercices_ordered() item=e}
<li><a href="/{$SALT_ADMIN}/{$t->get_id()}-{$t->get_name()}/{$e->get_id()}">{$e->get_name()}</a></li>
{/foreach}
</ul>

View File

@ -21,7 +21,7 @@
</td>
<td><a href="/{$SALT_ADMIN}/{$t->id}-{$t->name}">{$t->name}</a></td>
<td><ul>
{foreach from=$t->get_exercicesOrdered() item=e}
{foreach from=$t->get_exercices_ordered() item=e}
<li><a href="/{$SALT_ADMIN}/{$t->id}-{$t->name}/{$e->id}">{$e->get_name()}</a></li>
{/foreach}
</ul></td>

View File

@ -15,13 +15,13 @@
<th>{$theme->get_name()}</th>
{$sum=0}
{$themeID=$theme->get_id()}
{$solvedExercices=$my_team->get_solvedExercices($themeID)}
{foreach from=$theme->get_exercicesOrdered() item=exo}
{$solved_exercices=$my_team->get_solved_exercices($themeID)}
{foreach from=$theme->get_exercices_ordered() item=exo}
{$pts=0}
{for $i=0 to $nbExoMax}
{if !empty($solvedExercices.$i)}
{if $solvedExercices.$i->get_id() == $exo->get_id()}
{$pts=$solvedExercices.$i->points}{$sum=$sum + $pts}
{if !empty($solved_exercices.$i)}
{if $solved_exercices.$i->get_id() == $exo->get_id()}
{$pts=$solved_exercices.$i->points}{$sum=$sum + $pts}
{/if}
{/if}
{/for}

View File

@ -41,14 +41,14 @@
</p>
<p>
{$my_team->get_pts()} points<a class="badge pull-right" href="/{$SALT_USER}/{$my_team->get_id()}/summary">Synthèse</a><br>
{$my_team->get_rank()}<sup>e</sup> sur {Team::get_nbTeams()}
{$my_team->get_rank()}<sup>e</sup> sur {Team::get_nb_teams()}
</p>
</aside>
<div class="list-group">
{foreach from=$themes item=t key=k}
<a class="list-group-item" href="/{$SALT_USER}/{$my_team->get_id()}/{$t->get_id()}-{$t->get_name()}">
<span class="badge">{$my_team->get_nbResExercisesByTheme($t->get_id())}/{$t->get_nbExercices()}</span>
<span class="badge">{$my_team->get_nb_res_exercises_by_theme($t->get_id())}/{$t->get_nb_exercices()}</span>
{$t->get_name()}
</a>
{/foreach}

View File

@ -4,7 +4,7 @@
<div class="jumbotron">
<h3 style="font-variant: small-caps">{$cur_theme->get_name()}</h3>
<p>
{foreach from=$cur_theme->get_exercicesOrdered() item=exercice}
{foreach from=$cur_theme->get_exercices_ordered() item=exercice}
{if $exercice->has_solved($my_team)}
<a class="btn btn-success" role="button" href="/{$SALT_USER}/{$my_team->get_id()}/{$cur_theme->get_id()}-{$cur_theme->get_name()}/{$exercice->get_id()}">{$exercice->get_name()}</a>
{elseif $exercice->is_unlocked($my_team)}