Modify get_top for TOP3 themes
This commit is contained in:
parent
812f87c22e
commit
b3beb516b0
@ -2,7 +2,7 @@
|
||||
|
||||
if(!defined('ONYX')) exit;
|
||||
|
||||
function cmp_team_pts($i1, $i2)
|
||||
function cmp_team_pts($i1, $i2, $idTheme)
|
||||
{
|
||||
if ($i1->get_pts() == $i2->get_pts()){
|
||||
$db = new BDD();
|
||||
@ -22,7 +22,7 @@ function cmp_team_pts($i1, $i2)
|
||||
return -1;
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
function get_pts()
|
||||
function get_pts($themeID=-1)
|
||||
{
|
||||
if(!isset($this->points))
|
||||
{
|
||||
$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
|
||||
LEFT OUTER JOIN solved S ON E.id = S.id_exercice
|
||||
WHERE S.id_team = ".$this->id."
|
||||
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();
|
||||
|
||||
@ -269,11 +281,11 @@ class Team
|
||||
return $array;
|
||||
}
|
||||
|
||||
public static function get_top($nb=0)
|
||||
public static function get_top($nb=0, $idTheme=-1)
|
||||
{
|
||||
$teams = Team::get_teams();
|
||||
|
||||
usort($teams, "cmp_team_pts");
|
||||
usort($teams, "cmp_team_pts", $idTheme);
|
||||
|
||||
if ($nb != 0)
|
||||
$teams = array_slice($teams, 0, $nb);
|
||||
|
Loading…
Reference in New Issue
Block a user