New class Member, use it in Team ; update DB schema
This commit is contained in:
parent
30a7f65616
commit
b069d8f4ed
5 changed files with 110 additions and 25 deletions
|
|
@ -17,8 +17,8 @@ class Team
|
|||
var $id = null;
|
||||
var $key_hash;
|
||||
var $auth_level;
|
||||
var $company;
|
||||
var $members = null;
|
||||
var $slogan;
|
||||
var $members = array();
|
||||
var $points = null;
|
||||
|
||||
// Constructor
|
||||
|
|
@ -27,14 +27,14 @@ class Team
|
|||
if (!empty($id))
|
||||
{
|
||||
$db = new BDD();
|
||||
$res = $db->unique_query("SELECT id, key_hash, company, auth_level
|
||||
$res = $db->unique_query("SELECT id, key_hash, slogan, auth_level
|
||||
FROM teams WHERE id=" . intval($id)) or die($db->erreur());
|
||||
|
||||
if (!empty($res))
|
||||
{
|
||||
$this->id = $res['id'];
|
||||
$this->key_hash = $res['key_hash'];
|
||||
$this->company = $res['company'];
|
||||
$this->slogan = $res['slogan'];
|
||||
$this->auth_level = $res['auth_level'];
|
||||
}
|
||||
$db->deconnexion();
|
||||
|
|
@ -46,23 +46,23 @@ class Team
|
|||
{
|
||||
$key_hash = $this->key_hash;
|
||||
$auth_level = intval($this->auth_level);
|
||||
$company = $this->company;
|
||||
$slogan = $this->slogan;
|
||||
|
||||
$db = new BDD();
|
||||
$db->escape($key_hash);
|
||||
$db->escape($company);
|
||||
$db->escape($slogan);
|
||||
|
||||
if (empty($this->id))
|
||||
{
|
||||
$db->query("INSERT INTO teams
|
||||
VALUES (NULL, '".$key_hash."', ".$auth_level.", '".$company."')");
|
||||
VALUES (NULL, '".$key_hash."', ".$auth_level.", '".$slogan."')");
|
||||
$this->id = $db->insert_id();
|
||||
$aff = ($this->id > 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
$db->query("UPDATE users
|
||||
SET auth_level = ".$auth_level.", key_hash = '".$key_hash."', company = '".$company."'
|
||||
$db->query("UPDATE teams
|
||||
SET auth_level = ".$auth_level.", key_hash = '".$key_hash."', slogan = '".$slogan."'
|
||||
WHERE id = ".intval($this->id));
|
||||
$aff = $db->affected();
|
||||
}
|
||||
|
|
@ -75,8 +75,8 @@ class Team
|
|||
return $this->id;
|
||||
}
|
||||
|
||||
function get_company() {
|
||||
return $this->company;
|
||||
function get_slogan() {
|
||||
return $this->slogan;
|
||||
}
|
||||
|
||||
function get_auth_level() {
|
||||
|
|
@ -85,18 +85,17 @@ class Team
|
|||
|
||||
function get_members()
|
||||
{
|
||||
if(!isset($this->members))
|
||||
if(count($this->members) == 0)
|
||||
{
|
||||
$db = new BDD();
|
||||
|
||||
$res = $db->query("SELECT id, firstname, lastname, nickname
|
||||
FROM team_members
|
||||
$res = $db->query("SELECT id FROM team_members
|
||||
WHERE id_team = " . intval($this->id));
|
||||
|
||||
$db->deconnexion();
|
||||
|
||||
if (!empty($res))
|
||||
$this->members = $res;
|
||||
foreach($res as $member)
|
||||
$this->members[] = new Member($member["id"], $this);
|
||||
}
|
||||
|
||||
return $this->members;
|
||||
|
|
@ -117,9 +116,9 @@ class Team
|
|||
$db->deconnexion();
|
||||
|
||||
if (!empty($res))
|
||||
{
|
||||
$this->points = $res['sum_points'];
|
||||
}
|
||||
else
|
||||
$this->points = 0;
|
||||
}
|
||||
|
||||
return $this->points;
|
||||
|
|
|
|||
Reference in a new issue