diff --git a/onyx/include/common/Team.class.php b/onyx/include/common/Team.class.php index 1bf78e85..4debbf23 100644 --- a/onyx/include/common/Team.class.php +++ b/onyx/include/common/Team.class.php @@ -15,13 +15,11 @@ function cmp_team_pts($i1, $i2) class Team { var $id = null; - var $firstname; - var $lastname; - var $username; - var $company; + var $key_hash; var $auth_level; + var $company; + var $members = null; var $points = null; - var $nb_themes = null; // Constructor function Team ($id=null) @@ -29,15 +27,13 @@ class Team if (!empty($id)) { $db = new BDD(); - $res = $db->unique_query("SELECT id, firstname, lastname, username, company, auth_level - FROM users WHERE id=" . intval($id)); + $res = $db->unique_query("SELECT id, key_hash, company, auth_level + FROM teams WHERE id=" . intval($id)) or die($db->erreur()); if (!empty($res)) { $this->id = $res['id']; - $this->firstname = $res['firstname']; - $this->lastname = $res['lastname']; - $this->username = $res['username']; + $this->key_hash = $res['key_hash']; $this->company = $res['company']; $this->auth_level = $res['auth_level']; } @@ -48,29 +44,25 @@ class Team // Class methods function update() { - $username = $this->username; + $key_hash = $this->key_hash; $auth_level = intval($this->auth_level); - $firstname = $this->firstname; - $lastname = $this->lastname; $company = $this->company; $db = new BDD(); - $db->escape($username); - $db->escape($firstname); - $db->escape($lastname); + $db->escape($key_hash); $db->escape($company); if (empty($this->id)) { - $db->query("INSERT INTO users - VALUES (NULL, '".$username."', 0x0, ".$auth_level.", '".$firstname."', '".$lastname."', '".$company."')"); + $db->query("INSERT INTO teams + VALUES (NULL, '".$key_hash."', ".$auth_level.", '".$company."')"); $this->id = $db->insert_id(); $aff = ($this->id > 0); } else { $db->query("UPDATE users - SET username = '".$username."', auth_level = '".$auth_level."', firstname = '".$firstname."', lastname = '".$lastname."', company = '".$company."' + SET auth_level = ".$auth_level.", key_hash = '".$key_hash."', company = '".$company."' WHERE id = ".intval($this->id)); $aff = $db->affected(); } @@ -83,18 +75,6 @@ class Team return $this->id; } - function get_firstname() { - return $this->firstname; - } - - function get_lastname() { - return $this->lastname; - } - - function get_username() { - return $this->username; - } - function get_company() { return $this->company; } @@ -103,6 +83,25 @@ class Team return $this->auth_level; } + function get_members() + { + if(!isset($this->members)) + { + $db = new BDD(); + + $res = $db->query("SELECT id, firstname, lastname, nickname + FROM team_members + WHERE id_team = " . intval($this->id)); + + $db->deconnexion(); + + if (!empty($res)) + $this->members = $res; + } + + return $this->members; + } + function get_pts() { if(!isset($this->points)) @@ -145,7 +144,7 @@ class Team public static function get_teams() { $db = new BDD(); - $ids = $db->query("SELECT `id` FROM `users`"); + $ids = $db->query("SELECT `id` FROM `teams`"); $db->deconnexion(); $array = array(); @@ -160,9 +159,9 @@ class Team public static function get_top() { $teams = Team::get_teams(); - + usort($teams, "cmp_team_pts"); return $teams; } -} \ No newline at end of file +}