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