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
84
onyx/include/common/Member.class.php
Normal file
84
onyx/include/common/Member.class.php
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
<?php
|
||||
|
||||
if(!defined('ONYX')) exit;
|
||||
|
||||
class Member
|
||||
{
|
||||
var $id = null;
|
||||
var $team = null;
|
||||
var $firstname;
|
||||
var $lastname;
|
||||
var $nickname;
|
||||
var $company;
|
||||
|
||||
function Member($id=null, $team=null)
|
||||
{
|
||||
if (!empty($id))
|
||||
{
|
||||
$db = new BDD();
|
||||
$res = $db->unique_query("SELECT id, id_team, firstname, lastname, nickname, company
|
||||
FROM team_members WHERE id=" . intval($id)) or die($db->erreur());
|
||||
$db->deconnexion();
|
||||
|
||||
if (!empty($res))
|
||||
{
|
||||
$this->id = $res['id'];
|
||||
if (empty($team))
|
||||
$this->team = $res['id_team'];
|
||||
else
|
||||
$this->team = $team;
|
||||
$this->firstname = $res['firstname'];
|
||||
$this->lastname = $res['lastname'];
|
||||
$this->nickname = $res['nickname'];
|
||||
$this->company = $res['company'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function update()
|
||||
{
|
||||
$firstname = $this->firstname;
|
||||
$lastname = $this->lastname;
|
||||
$nickname = $this->nickname;
|
||||
$company = $this->company;
|
||||
|
||||
if (gettype($this->team) != "object")
|
||||
$id_team = intval($this->team);
|
||||
else
|
||||
$id_team = $this->team->id;
|
||||
|
||||
$db = new BDD();
|
||||
$db->escape($firstname);
|
||||
$db->escape($lastname);
|
||||
$db->escape($nickname);
|
||||
$db->escape($company);
|
||||
|
||||
if (empty($this->id))
|
||||
{
|
||||
$db->query("INSERT INTO team_members
|
||||
VALUES (NULL, ".intval($id_team).", '".$firstname."', '".$lastname."', '".$nickname."', '".$company."')");
|
||||
$this->id = $db->insert_id();
|
||||
$aff = ($this->id > 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
$db->query("UPDATE team_members
|
||||
SET id_team = ".intval($id_team).", firstname = '$firstname', lastname = '$lastname', nickname = '$lastname', company = '$company'
|
||||
WHERE id = ".intval($this->id));
|
||||
$aff = $db->affected();
|
||||
}
|
||||
$db->deconnexion();
|
||||
|
||||
return ($aff == 1);
|
||||
}
|
||||
|
||||
function get_team()
|
||||
{
|
||||
if (gettype($this->team) != "object")
|
||||
$this->team = new Team(intval($this->team));
|
||||
|
||||
return $this->team;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in a new issue