Modify get_top for TOP3 themes

This commit is contained in:
Quentin Grosyeux 2013-12-11 19:18:45 +01:00
parent 812f87c22e
commit b3beb516b0

View File

@ -2,7 +2,7 @@
if(!defined('ONYX')) exit; if(!defined('ONYX')) exit;
function cmp_team_pts($i1, $i2) function cmp_team_pts($i1, $i2, $idTheme)
{ {
if ($i1->get_pts() == $i2->get_pts()){ if ($i1->get_pts() == $i2->get_pts()){
$db = new BDD(); $db = new BDD();
@ -22,7 +22,7 @@ function cmp_team_pts($i1, $i2)
return -1; return -1;
} }
else{ else{
return ($i1->get_pts() < $i2->get_pts()) ? 1 : -1; return ($i1->get_pts($idTheme) < $i2->get_pts($idTheme)) ? 1 : -1;
} }
} }
@ -147,17 +147,29 @@ class Team
return $this->members; return $this->members;
} }
function get_pts() function get_pts($themeID=-1)
{ {
if(!isset($this->points)) if(!isset($this->points))
{ {
$db = new BDD(); $db = new BDD();
$res = null;
$res = $db->unique_query("SELECT E.id, S.id_team, SUM(E.points) as sum_points if ($themeID != -1)
{
$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");
}
else
{
$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." AND E.id_theme = ".$themeID."
GROUP BY S.id_team");
}
$db->deconnexion(); $db->deconnexion();
@ -269,11 +281,11 @@ class Team
return $array; return $array;
} }
public static function get_top($nb=0) public static function get_top($nb=0, $idTheme=-1)
{ {
$teams = Team::get_teams(); $teams = Team::get_teams();
usort($teams, "cmp_team_pts"); usort($teams, "cmp_team_pts", $idTheme);
if ($nb != 0) if ($nb != 0)
$teams = array_slice($teams, 0, $nb); $teams = array_slice($teams, 0, $nb);