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
|
@ -100,7 +100,7 @@ CREATE TABLE IF NOT EXISTS `teams` (
|
|||
`id` smallint(5) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`key_hash` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
|
||||
`auth_level` tinyint(1) NOT NULL,
|
||||
`company` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
|
||||
`slogan` varchar(64) COLLATE utf8_unicode_ci NOT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;
|
||||
|
||||
|
@ -113,9 +113,10 @@ CREATE TABLE IF NOT EXISTS `teams` (
|
|||
CREATE TABLE IF NOT EXISTS `team_members` (
|
||||
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`id_team` int(10) unsigned NOT NULL,
|
||||
`firstname` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
|
||||
`lastname` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
|
||||
`nickname` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
|
||||
`firstname` varchar(32) COLLATE utf8_unicode_ci NOT NULL,
|
||||
`lastname` varchar(32) COLLATE utf8_unicode_ci NOT NULL,
|
||||
`nickname` varchar(32) COLLATE utf8_unicode_ci NOT NULL,
|
||||
`company` varchar(32) COLLATE utf8_unicode_ci NOT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;
|
||||
|
||||
|
@ -127,6 +128,6 @@ CREATE TABLE IF NOT EXISTS `team_members` (
|
|||
|
||||
CREATE TABLE IF NOT EXISTS `themes` (
|
||||
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
|
||||
`name` varchar(32) COLLATE utf8_unicode_ci NOT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;
|
||||
|
|
|
@ -7,6 +7,7 @@ if (empty($sess->values["connected"]) && !defined("xCSRF"))
|
|||
require_once("functions.php"); //Inclusion des principales fonctions
|
||||
|
||||
require_once("common/Exercice.class.php");
|
||||
require_once("common/Member.class.php");
|
||||
require_once("common/Team.class.php");
|
||||
require_once("common/Theme.class.php");
|
||||
|
||||
|
|
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;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -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;
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
{extends file="layout.tpl"}
|
||||
{block name=content}
|
||||
<h1>
|
||||
{$team->company}
|
||||
{$team->slogan}
|
||||
</h1>
|
||||
<ul>
|
||||
<li><strong>Score :</strong> {$team->get_pts()}</li>
|
||||
<li><strong>Membre{if count($team->get_members()) > 1}s{/if} :</strong>
|
||||
<ul>
|
||||
{foreach from=$team->get_members() item=m}
|
||||
<li><span class="font-variant: small-caps;">{$m.lastname}</span> {$m.firstname}</li>
|
||||
<li><span class="font-variant: small-caps;">{$m->lastname}</span> {$m->firstname}</li>
|
||||
{/foreach}
|
||||
</ul>
|
||||
</li>
|
||||
|
|
Reference in a new issue