Fix User -> Team
This commit is contained in:
parent
a767c4d900
commit
9c3173c682
1 changed files with 33 additions and 34 deletions
|
@ -15,13 +15,11 @@ function cmp_team_pts($i1, $i2)
|
||||||
class Team
|
class Team
|
||||||
{
|
{
|
||||||
var $id = null;
|
var $id = null;
|
||||||
var $firstname;
|
var $key_hash;
|
||||||
var $lastname;
|
|
||||||
var $username;
|
|
||||||
var $company;
|
|
||||||
var $auth_level;
|
var $auth_level;
|
||||||
|
var $company;
|
||||||
|
var $members = null;
|
||||||
var $points = null;
|
var $points = null;
|
||||||
var $nb_themes = null;
|
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
function Team ($id=null)
|
function Team ($id=null)
|
||||||
|
@ -29,15 +27,13 @@ class Team
|
||||||
if (!empty($id))
|
if (!empty($id))
|
||||||
{
|
{
|
||||||
$db = new BDD();
|
$db = new BDD();
|
||||||
$res = $db->unique_query("SELECT id, firstname, lastname, username, company, auth_level
|
$res = $db->unique_query("SELECT id, key_hash, company, auth_level
|
||||||
FROM users WHERE id=" . intval($id));
|
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->firstname = $res['firstname'];
|
$this->key_hash = $res['key_hash'];
|
||||||
$this->lastname = $res['lastname'];
|
|
||||||
$this->username = $res['username'];
|
|
||||||
$this->company = $res['company'];
|
$this->company = $res['company'];
|
||||||
$this->auth_level = $res['auth_level'];
|
$this->auth_level = $res['auth_level'];
|
||||||
}
|
}
|
||||||
|
@ -48,29 +44,25 @@ class Team
|
||||||
// Class methods
|
// Class methods
|
||||||
function update()
|
function update()
|
||||||
{
|
{
|
||||||
$username = $this->username;
|
$key_hash = $this->key_hash;
|
||||||
$auth_level = intval($this->auth_level);
|
$auth_level = intval($this->auth_level);
|
||||||
$firstname = $this->firstname;
|
|
||||||
$lastname = $this->lastname;
|
|
||||||
$company = $this->company;
|
$company = $this->company;
|
||||||
|
|
||||||
$db = new BDD();
|
$db = new BDD();
|
||||||
$db->escape($username);
|
$db->escape($key_hash);
|
||||||
$db->escape($firstname);
|
|
||||||
$db->escape($lastname);
|
|
||||||
$db->escape($company);
|
$db->escape($company);
|
||||||
|
|
||||||
if (empty($this->id))
|
if (empty($this->id))
|
||||||
{
|
{
|
||||||
$db->query("INSERT INTO users
|
$db->query("INSERT INTO teams
|
||||||
VALUES (NULL, '".$username."', 0x0, ".$auth_level.", '".$firstname."', '".$lastname."', '".$company."')");
|
VALUES (NULL, '".$key_hash."', ".$auth_level.", '".$company."')");
|
||||||
$this->id = $db->insert_id();
|
$this->id = $db->insert_id();
|
||||||
$aff = ($this->id > 0);
|
$aff = ($this->id > 0);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$db->query("UPDATE users
|
$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));
|
WHERE id = ".intval($this->id));
|
||||||
$aff = $db->affected();
|
$aff = $db->affected();
|
||||||
}
|
}
|
||||||
|
@ -83,18 +75,6 @@ class Team
|
||||||
return $this->id;
|
return $this->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_firstname() {
|
|
||||||
return $this->firstname;
|
|
||||||
}
|
|
||||||
|
|
||||||
function get_lastname() {
|
|
||||||
return $this->lastname;
|
|
||||||
}
|
|
||||||
|
|
||||||
function get_username() {
|
|
||||||
return $this->username;
|
|
||||||
}
|
|
||||||
|
|
||||||
function get_company() {
|
function get_company() {
|
||||||
return $this->company;
|
return $this->company;
|
||||||
}
|
}
|
||||||
|
@ -103,6 +83,25 @@ class Team
|
||||||
return $this->auth_level;
|
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()
|
function get_pts()
|
||||||
{
|
{
|
||||||
if(!isset($this->points))
|
if(!isset($this->points))
|
||||||
|
@ -145,7 +144,7 @@ class Team
|
||||||
public static function get_teams()
|
public static function get_teams()
|
||||||
{
|
{
|
||||||
$db = new BDD();
|
$db = new BDD();
|
||||||
$ids = $db->query("SELECT `id` FROM `users`");
|
$ids = $db->query("SELECT `id` FROM `teams`");
|
||||||
$db->deconnexion();
|
$db->deconnexion();
|
||||||
|
|
||||||
$array = array();
|
$array = array();
|
||||||
|
@ -160,9 +159,9 @@ class Team
|
||||||
public static function get_top()
|
public static function get_top()
|
||||||
{
|
{
|
||||||
$teams = Team::get_teams();
|
$teams = Team::get_teams();
|
||||||
|
|
||||||
usort($teams, "cmp_team_pts");
|
usort($teams, "cmp_team_pts");
|
||||||
return $teams;
|
return $teams;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue