Code cleaned
This commit is contained in:
parent
f7f277d46b
commit
2d77512cdc
@ -132,7 +132,7 @@ else if ($n && $p[0] == SALT_USER)
|
|||||||
$id_exo = $p[3];
|
$id_exo = $p[3];
|
||||||
else if ($n == 3)
|
else if ($n == 3)
|
||||||
{
|
{
|
||||||
foreach($THEME->get_exercicesOrdered() as $exo)
|
foreach($THEME->get_exercices_ordered() as $exo)
|
||||||
{
|
{
|
||||||
if (! $exo->has_solved($TEAM))
|
if (! $exo->has_solved($TEAM))
|
||||||
break;
|
break;
|
||||||
|
@ -19,8 +19,10 @@ class Exercice
|
|||||||
if (!empty($id))
|
if (!empty($id))
|
||||||
{
|
{
|
||||||
$db = new BDD();
|
$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'");
|
FROM exercices WHERE id = '$id'");
|
||||||
|
|
||||||
if (!empty($res))
|
if (!empty($res))
|
||||||
@ -81,7 +83,6 @@ class Exercice
|
|||||||
{
|
{
|
||||||
$db = new BDD();
|
$db = new BDD();
|
||||||
|
|
||||||
// TODO rename time by date in db ?
|
|
||||||
$res = $db->query("SELECT `id_team`, `time` FROM solved
|
$res = $db->query("SELECT `id_team`, `time` FROM solved
|
||||||
WHERE id_exercice = '$this->id'
|
WHERE id_exercice = '$this->id'
|
||||||
ORDER BY time");
|
ORDER BY time");
|
||||||
@ -256,7 +257,7 @@ class Exercice
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function get_nbExoMax()
|
public static function get_nb_exo_max()
|
||||||
{
|
{
|
||||||
$db = new BDD();
|
$db = new BDD();
|
||||||
$res = $db->unique_query("SELECT count(id) AS max FROM exercices
|
$res = $db->unique_query("SELECT count(id) AS max FROM exercices
|
||||||
|
@ -28,8 +28,8 @@ class Team
|
|||||||
if (!empty($id))
|
if (!empty($id))
|
||||||
{
|
{
|
||||||
$db = new BDD();
|
$db = new BDD();
|
||||||
$res = $db->unique_query("SELECT id, team_name, key_hash, slogan, auth_level
|
$res = $db->unique_query("SELECT `id`, `team_name`, `key_hash`, `slogan`, `auth_level`
|
||||||
FROM teams WHERE id=" . intval($id)) or die($db->erreur());
|
FROM teams WHERE id = ".intval($id)) or die($db->erreur());
|
||||||
|
|
||||||
if (!empty($res))
|
if (!empty($res))
|
||||||
{
|
{
|
||||||
@ -97,8 +97,8 @@ class Team
|
|||||||
{
|
{
|
||||||
$db = new BDD();
|
$db = new BDD();
|
||||||
|
|
||||||
$res = $db->query("SELECT id FROM team_members
|
$res = $db->query("SELECT `id` FROM team_members
|
||||||
WHERE id_team = " . intval($this->id));
|
WHERE id_team = ".intval($this->id));
|
||||||
|
|
||||||
$db->deconnexion();
|
$db->deconnexion();
|
||||||
|
|
||||||
@ -115,11 +115,11 @@ class Team
|
|||||||
{
|
{
|
||||||
$db = new BDD();
|
$db = new BDD();
|
||||||
|
|
||||||
$res = $db->unique_query("SELECT e.id, s.id_team, SUM(e.points) as sum_points
|
$res = $db->unique_query("SELECT E.id, S.id_team, SUM(E.points) as sum_points
|
||||||
FROM exercices e
|
FROM exercices E
|
||||||
LEFT OUTER JOIN solved s ON e.id = s.id_exercice
|
LEFT OUTER JOIN solved S ON E.id = S.id_exercice
|
||||||
WHERE s.id_team = " . $this->id . "
|
WHERE S.id_team = ".$this->id."
|
||||||
GROUP BY s.id_team");
|
GROUP BY S.id_team");
|
||||||
|
|
||||||
$db->deconnexion();
|
$db->deconnexion();
|
||||||
|
|
||||||
@ -132,7 +132,7 @@ class Team
|
|||||||
return $this->points;
|
return $this->points;
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_groupIds()
|
function get_group_ids()
|
||||||
{
|
{
|
||||||
$db = new BDD();
|
$db = new BDD();
|
||||||
|
|
||||||
@ -154,42 +154,40 @@ class Team
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_nbResExercisesByTheme($id_theme)
|
function get_nb_res_exercises_by_theme($id_theme)
|
||||||
{
|
{
|
||||||
$db = new BDD();
|
$db = new BDD();
|
||||||
$res = $db->unique_query("SELECT e.id_theme AS theme, count( s.id ) AS solved
|
$res = $db->unique_query("SELECT E.id_theme AS theme, count(S.id) AS solved
|
||||||
FROM solved AS s
|
FROM solved S
|
||||||
RIGHT OUTER JOIN exercices AS e ON e.id = s.id_exercice
|
RIGHT OUTER JOIN exercices E ON E.id = S.id_exercice
|
||||||
AND s.id_team = ".$this->id."
|
AND S.id_team = ".$this->id."
|
||||||
AND e.id_theme = ".$id_theme);
|
AND E.id_theme = ".$id_theme);
|
||||||
|
|
||||||
$db->deconnexion();
|
$db->deconnexion();
|
||||||
|
|
||||||
return $res['solved'];
|
return $res['solved'];
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_solvedExercices($id_theme=-1)
|
function get_solved_exercices($id_theme=-1)
|
||||||
{
|
{
|
||||||
if ($id_theme != -1)
|
if ($id_theme != -1)
|
||||||
{
|
{
|
||||||
$db = new BDD();
|
$db = new BDD();
|
||||||
$ids = $db->query("SELECT id_theme, id_exercice
|
$ids = $db->query("SELECT `id_theme`, `id_exercice`
|
||||||
FROM `solved`
|
FROM solved S
|
||||||
LEFT OUTER JOIN exercices ON `solved`.id_exercice = `exercices`.id
|
LEFT OUTER JOIN exercices E ON S.id_exercice = E.id
|
||||||
WHERE id_team =".$this->id." AND id_theme =".$id_theme);
|
WHERE id_team =".$this->id." AND id_theme =".$id_theme);
|
||||||
$db->deconnexion();
|
$db->deconnexion();
|
||||||
|
|
||||||
$array = array();
|
$array = array();
|
||||||
$i = 0;
|
$i = 0;
|
||||||
if ($ids)
|
if ($ids)
|
||||||
{
|
{
|
||||||
foreach ($ids as $id){
|
foreach ($ids as $id){
|
||||||
$array[] = new Exercice($id['id_exercice']);
|
$array[] = new Exercice($id['id_exercice']);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return $array;
|
|
||||||
|
|
||||||
|
return $array;
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -226,7 +224,7 @@ class Team
|
|||||||
return $teams;
|
return $teams;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function get_nbTeams()
|
public static function get_nb_teams()
|
||||||
{
|
{
|
||||||
$db = new BDD();
|
$db = new BDD();
|
||||||
$res = $db->unique_query("SELECT COUNT(id) as count_teams FROM teams");
|
$res = $db->unique_query("SELECT COUNT(id) as count_teams FROM teams");
|
||||||
@ -234,5 +232,4 @@ class Team
|
|||||||
|
|
||||||
return $res['count_teams'];
|
return $res['count_teams'];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ class Theme
|
|||||||
if (!empty($id))
|
if (!empty($id))
|
||||||
{
|
{
|
||||||
$db = new BDD();
|
$db = new BDD();
|
||||||
$res = $db->unique_query("SELECT id, name
|
$res = $db->unique_query("SELECT `id`, `name`
|
||||||
FROM themes WHERE id=" . intval($id));
|
FROM themes WHERE id=" . intval($id));
|
||||||
|
|
||||||
if (!empty($res))
|
if (!empty($res))
|
||||||
@ -41,8 +41,8 @@ class Theme
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
$db->query("UPDATE themes
|
$db->query("UPDATE themes
|
||||||
SET name = '".$name."'
|
SET name = '".$name."'
|
||||||
WHERE id = ".intval($this->id));
|
WHERE id = ".intval($this->id));
|
||||||
$aff = $db->affected();
|
$aff = $db->affected();
|
||||||
}
|
}
|
||||||
$db->deconnexion();
|
$db->deconnexion();
|
||||||
@ -60,12 +60,12 @@ class Theme
|
|||||||
return $this->id;
|
return $this->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_nbExercices()
|
function get_nb_exercices()
|
||||||
{
|
{
|
||||||
$db = new BDD();
|
$db = new BDD();
|
||||||
$res = $db->unique_query("SELECT count( id ) as nb_exercices FROM exercices
|
$res = $db->unique_query("SELECT count(id) as nb_exercices FROM exercices
|
||||||
WHERE id_theme = ".$this->id."
|
WHERE id_theme = ".$this->id."
|
||||||
GROUP BY id_theme");
|
GROUP BY id_theme");
|
||||||
$db->deconnexion();
|
$db->deconnexion();
|
||||||
|
|
||||||
return $res['nb_exercices'];
|
return $res['nb_exercices'];
|
||||||
@ -81,7 +81,7 @@ class Theme
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_exercicesOrdered()
|
function get_exercices_ordered()
|
||||||
{
|
{
|
||||||
$db = new BDD();
|
$db = new BDD();
|
||||||
$res = $db->query("SELECT E.id, E.require FROM exercices E
|
$res = $db->query("SELECT E.id, E.require FROM exercices E
|
||||||
|
@ -5,6 +5,6 @@ if(!defined('ONYX')) exit;
|
|||||||
$template->assign("teams", Team::get_teams());
|
$template->assign("teams", Team::get_teams());
|
||||||
$template->assign("top", Team::get_top(10));
|
$template->assign("top", Team::get_top(10));
|
||||||
$template->assign("themes", Theme::get_themes());
|
$template->assign("themes", Theme::get_themes());
|
||||||
$template->assign("nbExoMax", Exercice::get_nbExoMax());
|
$template->assign("nbExoMax", Exercice::get_nb_exo_max());
|
||||||
|
|
||||||
return "public/home";
|
return "public/home";
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
if(!defined('ONYX')) exit;
|
if(!defined('ONYX')) exit;
|
||||||
|
|
||||||
$template->assign("themes", Theme::get_themes());
|
$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));
|
$template->assign("my_team", new TEAM($TEAM));
|
||||||
|
|
||||||
|
@ -2,10 +2,7 @@
|
|||||||
|
|
||||||
if(!defined('ONYX')) exit;
|
if(!defined('ONYX')) exit;
|
||||||
|
|
||||||
//$solvedExercices = $TEAM->get_solvedExercices();
|
|
||||||
|
|
||||||
$template->assign("themes", Theme::get_themes());
|
$template->assign("themes", Theme::get_themes());
|
||||||
$template->assign("nbExoMax", Exercice::get_nbExoMax());
|
$template->assign("nbExoMax", Exercice::get_nb_exo_max());
|
||||||
//$template->assign("solvedExercices", $solvedExercices);
|
|
||||||
|
|
||||||
return "teams/summary";
|
return "teams/summary";
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<theme>
|
<theme>
|
||||||
<title>{$theme->get_name()}</title>
|
<title>{$theme->get_name()}</title>
|
||||||
{if $theme->get_exercicesOrdered()}
|
{if $theme->get_exercices_ordered()}
|
||||||
{foreach from=$theme->get_exercicesOrdered() item=e}
|
{foreach from=$theme->get_exercices_ordered() item=e}
|
||||||
<exercice id="{$e->id}" level="{$e->level}"{if $e->require} depends="{$e->require}"{/if}>
|
<exercice id="{$e->id}" level="{$e->level}"{if $e->require} depends="{$e->require}"{/if}>
|
||||||
<title>{$e->get_name()}</title>
|
<title>{$e->get_name()}</title>
|
||||||
<points>{$e->points}</points>
|
<points>{$e->points}</points>
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
<li class="dropdown{if $menu_where == $t->get_name()} active{/if}">
|
<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>
|
<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">
|
<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>
|
<li><a href="/{$SALT_ADMIN}/{$t->get_id()}-{$t->get_name()}/{$e->get_id()}">{$e->get_name()}</a></li>
|
||||||
{/foreach}
|
{/foreach}
|
||||||
</ul>
|
</ul>
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
</td>
|
</td>
|
||||||
<td><a href="/{$SALT_ADMIN}/{$t->id}-{$t->name}">{$t->name}</a></td>
|
<td><a href="/{$SALT_ADMIN}/{$t->id}-{$t->name}">{$t->name}</a></td>
|
||||||
<td><ul>
|
<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>
|
<li><a href="/{$SALT_ADMIN}/{$t->id}-{$t->name}/{$e->id}">{$e->get_name()}</a></li>
|
||||||
{/foreach}
|
{/foreach}
|
||||||
</ul></td>
|
</ul></td>
|
||||||
|
@ -15,13 +15,13 @@
|
|||||||
<th>{$theme->get_name()}</th>
|
<th>{$theme->get_name()}</th>
|
||||||
{$sum=0}
|
{$sum=0}
|
||||||
{$themeID=$theme->get_id()}
|
{$themeID=$theme->get_id()}
|
||||||
{$solvedExercices=$my_team->get_solvedExercices($themeID)}
|
{$solved_exercices=$my_team->get_solved_exercices($themeID)}
|
||||||
{foreach from=$theme->get_exercicesOrdered() item=exo}
|
{foreach from=$theme->get_exercices_ordered() item=exo}
|
||||||
{$pts=0}
|
{$pts=0}
|
||||||
{for $i=0 to $nbExoMax}
|
{for $i=0 to $nbExoMax}
|
||||||
{if !empty($solvedExercices.$i)}
|
{if !empty($solved_exercices.$i)}
|
||||||
{if $solvedExercices.$i->get_id() == $exo->get_id()}
|
{if $solved_exercices.$i->get_id() == $exo->get_id()}
|
||||||
{$pts=$solvedExercices.$i->points}{$sum=$sum + $pts}
|
{$pts=$solved_exercices.$i->points}{$sum=$sum + $pts}
|
||||||
{/if}
|
{/if}
|
||||||
{/if}
|
{/if}
|
||||||
{/for}
|
{/for}
|
||||||
|
@ -41,14 +41,14 @@
|
|||||||
</p>
|
</p>
|
||||||
<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_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>
|
</p>
|
||||||
</aside>
|
</aside>
|
||||||
|
|
||||||
<div class="list-group">
|
<div class="list-group">
|
||||||
{foreach from=$themes item=t key=k}
|
{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()}">
|
<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()}
|
{$t->get_name()}
|
||||||
</a>
|
</a>
|
||||||
{/foreach}
|
{/foreach}
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
<div class="jumbotron">
|
<div class="jumbotron">
|
||||||
<h3 style="font-variant: small-caps">{$cur_theme->get_name()}</h3>
|
<h3 style="font-variant: small-caps">{$cur_theme->get_name()}</h3>
|
||||||
<p>
|
<p>
|
||||||
{foreach from=$cur_theme->get_exercicesOrdered() item=exercice}
|
{foreach from=$cur_theme->get_exercices_ordered() item=exercice}
|
||||||
{if $exercice->has_solved($my_team)}
|
{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>
|
<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)}
|
{elseif $exercice->is_unlocked($my_team)}
|
||||||
|
Loading…
Reference in New Issue
Block a user