Add get_teams and get_top functions for User class
This commit is contained in:
parent
b69ecd3e70
commit
68dcb996c9
7 changed files with 158 additions and 25 deletions
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
if(!defined('ONYX')) exit;
|
||||
|
||||
class User
|
||||
class Team
|
||||
{
|
||||
var $id = null;
|
||||
var $firstname;
|
||||
|
|
@ -13,7 +13,8 @@ class User
|
|||
var $points = null;
|
||||
var $nb_themes = null;
|
||||
|
||||
function User ($id=null)
|
||||
// Constructor
|
||||
function Team ($id=null)
|
||||
{
|
||||
if (!empty($id))
|
||||
{
|
||||
|
|
@ -33,6 +34,7 @@ class User
|
|||
}
|
||||
}
|
||||
|
||||
// Class methods
|
||||
function update()
|
||||
{
|
||||
$username = $this->username;
|
||||
|
|
@ -110,29 +112,53 @@ class User
|
|||
}
|
||||
}
|
||||
|
||||
function get_groupIds()
|
||||
{
|
||||
$db = new BDD();
|
||||
|
||||
$res = $db->query("SELECT `id` FROM `users`");
|
||||
$db->deconnexion();
|
||||
|
||||
return $res['id'];
|
||||
}
|
||||
|
||||
function authenticate($certificate)
|
||||
{
|
||||
//TODO
|
||||
}
|
||||
|
||||
// Points par theme (theme, user, sum_points)
|
||||
//$res = $db->query("SELECT e.id_theme, 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) . "
|
||||
//GROUP BY s.id_user, e.id_theme");
|
||||
// Static methods
|
||||
public static function get_teams()
|
||||
{
|
||||
$db = new BDD();
|
||||
$ids = $db->query("SELECT `id` FROM `users`");
|
||||
$db->deconnexion();
|
||||
|
||||
$array = array();
|
||||
foreach ($ids as $id){
|
||||
$array[] = new Team($id['id']);
|
||||
}
|
||||
|
||||
//SELECT e.id_theme,
|
||||
// (select e.points from exercices where e.id=???),
|
||||
// (select e.points from exercices where e.id=???),
|
||||
// (select e.points from exercices where e.id=???),
|
||||
// (select e.points from exercices where e.id=???),
|
||||
// (select e.points from exercices where e.id=???)
|
||||
// (select max(e.points) from exercices)
|
||||
//FROM exercices e
|
||||
//LEFT OUTER JOIN solved s ON e.id = s.id_exercice
|
||||
//WHERE s.id_user = " . intval($this->id) . "
|
||||
//GROUP BY s.id_user, e.id_theme");
|
||||
return $array;
|
||||
}
|
||||
|
||||
// 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();
|
||||
|
||||
usort($teams, "cmp");
|
||||
return $teams;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in a new issue