Team.class: handle revoked attribut

This commit is contained in:
Li Chen 2013-11-30 21:30:20 +01:00
parent 9fd960dadb
commit dbcc23a535

View File

@ -35,6 +35,7 @@ class Team
var $slogan; var $slogan;
var $members = array(); var $members = array();
var $points = null; var $points = null;
var $revoked = 0;
// Constructor // Constructor
function Team ($id=null) function Team ($id=null)
@ -42,7 +43,8 @@ class Team
if (!empty($id)) if (!empty($id))
{ {
$db = new BDD(); $db = new BDD();
$res = $db->unique_query("SELECT `id`, `team_name`, `key_hash`, `slogan`, `auth_level` $res = $db->unique_query("SELECT `id`, `team_name`, `key_hash`, `slogan`,
`auth_level`, `revoked`
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))
@ -52,6 +54,7 @@ class Team
$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'];
$this->revoked = $res['revoked'];
} }
$db->deconnexion(); $db->deconnexion();
} }
@ -64,6 +67,7 @@ class Team
$auth_level = intval($this->auth_level); $auth_level = intval($this->auth_level);
$slogan = $this->slogan; $slogan = $this->slogan;
$team_name = $this->team_name; $team_name = $this->team_name;
$revoked = $this->revoked;
$db = new BDD(); $db = new BDD();
$db->escape($key_hash); $db->escape($key_hash);
@ -73,14 +77,17 @@ class Team
if (empty($this->id)) if (empty($this->id))
{ {
$db->query("INSERT INTO teams $db->query("INSERT INTO teams
VALUES (NULL, '".$team_name."', '".$key_hash."', ".$auth_level.", '".$slogan."')"); VALUES (NULL, '".$team_name."', '".$key_hash."', ".$auth_level.", '".
$slogan."', ".$revoked.")");
$this->id = $db->insert_id(); $this->id = $db->insert_id();
$aff = ($this->id > 0); $aff = ($this->id > 0);
} }
else else
{ {
$db->query("UPDATE teams $db->query("UPDATE teams
SET team_name = '".$team_name."', auth_level = ".$auth_level.", key_hash = '".$key_hash."', slogan = '".$slogan."' SET team_name = '".$team_name."', auth_level = ".$auth_level.
", key_hash = '".$key_hash."', slogan = '".
$slogan."', ".intval($revoked)."
WHERE id = ".intval($this->id)); WHERE id = ".intval($this->id));
$aff = $db->affected(); $aff = $db->affected();
} }
@ -118,6 +125,10 @@ class Team
return $this->auth_level; return $this->auth_level;
} }
function get_revoked() {
return $this->revoked;
}
function get_members() function get_members()
{ {
if(count($this->members) == 0) if(count($this->members) == 0)
@ -225,6 +236,16 @@ class Team
} }
// Static methods // Static methods
public static function set_revoked($bool, $name)
{
$db = new BDD();
$db->query("UPDATE teams SET revoked = ".intval($bool)." WHERE team_name = '".$name."'");
$aff = $db->affected();
$db->deconnexion();
return ($aff == 1);
}
public static function get_teams() public static function get_teams()
{ {
$db = new BDD(); $db = new BDD();