Merge Team.class

This commit is contained in:
Quentin Grosyeux 2013-10-26 19:20:24 +02:00
commit 7a2902f6d4

View file

@ -15,6 +15,7 @@ function cmp_team_pts($i1, $i2)
class Team
{
var $id = null;
var $team_name;
var $key_hash;
var $auth_level;
var $slogan;
@ -27,12 +28,13 @@ class Team
if (!empty($id))
{
$db = new BDD();
$res = $db->unique_query("SELECT id, 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());
if (!empty($res))
{
$this->id = $res['id'];
$this->team_name = $res['team_name'];
$this->key_hash = $res['key_hash'];
$this->slogan = $res['slogan'];
$this->auth_level = $res['auth_level'];
@ -47,10 +49,13 @@ class Team
$key_hash = $this->key_hash;
$auth_level = intval($this->auth_level);
$slogan = $this->slogan;
$company = $this->company;
$team_name = $this->team_name;
$db = new BDD();
$db->escape($key_hash);
$db->escape($slogan);
$db->escape($team_name);
if (empty($this->id))
{
@ -62,7 +67,7 @@ class Team
else
{
$db->query("UPDATE teams
SET auth_level = ".$auth_level.", key_hash = '".$key_hash."', slogan = '".$slogan."'
SET team_name = '".$team_name."', auth_level = ".$auth_level.", key_hash = '".$key_hash."', company = '".$slogan."'
WHERE id = ".intval($this->id));
$aff = $db->affected();
}
@ -79,6 +84,10 @@ class Team
return $this->slogan;
}
function get_name() {
return $this->team_name;
}
function get_auth_level() {
return $this->auth_level;
}
@ -134,6 +143,18 @@ class Team
return $res['id'];
}
function get_rank()
{
$teams = Team::get_top();
for ($i = 0; $i < 10; $i++){
$tid = $teams[$i]->get_id();
if ($tid == $this->id)
return $i;
}
return 0;
}
function authenticate($certificate)
{
//TODO
@ -154,7 +175,6 @@ class Team
return $array;
}
// TODO: Not tested, need feeding BDD
public static function get_top()
{
$teams = Team::get_teams();
@ -163,4 +183,13 @@ class Team
return $teams;
}
public static function get_nbTeams()
{
$db = new BDD();
$res = $db->unique_query("SELECT COUNT(id) as count_teams FROM teams");
$db->deconnexion();
return $res['count_teams'];
}
}