Correct some bugs in Team class.

This commit is contained in:
Quentin Grosyeux 2013-10-22 08:56:38 +02:00
parent 3d5c762d7c
commit a767c4d900

View File

@ -2,6 +2,16 @@
if(!defined('ONYX')) exit;
function cmp_team_pts($i1, $i2)
{
if ($i1->get_pts() == $i2->get_pts()){
return 0;
}
else{
return ($i1->get_pts() < $i2->get_pts()) ? 1 : -1;
}
}
class Team
{
var $id = null;
@ -24,6 +34,7 @@ class Team
if (!empty($res))
{
$this->id = $res['id'];
$this->firstname = $res['firstname'];
$this->lastname = $res['lastname'];
$this->username = $res['username'];
@ -94,15 +105,16 @@ class Team
function get_pts()
{
if(isset($this->points))
if(!isset($this->points))
{
$db = new BDD();
$res = $db->query("SELECT e.id, s.id_user, SUM(e.points) as sum_points
$res = $db->unique_query("SELECT e.id, s.id_user, SUM(e.points) as sum_points
FROM exercices e
LEFT OUTER JOIN solved s ON e.id = s.id_exercice
WHERE s.id_user = " . intval($this->id) . "
WHERE s.id_user = " . $this->id . "
GROUP BY s.id_user");
$db->deconnexion();
if (!empty($res))
@ -110,6 +122,8 @@ class Team
$this->points = $res['sum_points'];
}
}
return $this->points;
}
function get_groupIds()
@ -145,19 +159,9 @@ class Team
// TODO: Not tested, need feeding BDD
public static function get_top()
{
function cmp($i1, $i2)
{
if ($i1->get_pts() == $i2->get_pts()){
return 0;
}
else{
return ($i1->get_pts() < $i2->get_pts) ? -1 : 1;
}
}
$teams = $this->get_teams();
$teams = Team::get_teams();
usort($teams, "cmp");
usort($teams, "cmp_team_pts");
return $teams;
}