4 * Représente un participant.
8 public $info; # Toute les infos du membre sous la forme d'un objet.
12 static private $NB_VOTES_PAR_PARTICIPANT = 3; # Concerne les votes des jeux joueés.
15 * Constructeur, peut être appelé sous trois formes différentes :
16 * 1) $v1 = NULL, $v2 = NULL : participant non-valide
17 * 2) $v1 = id, $v2 = NULL : la participant existe et est chargé à partir de son id
18 * 3) $v1 = pseudo, $v2 = password : le participant existe et est chargé à partir de son pseudo et de son password
19 * Le mot de passe est donné en clair.
21 public function Participant($v1=NULL, $v2=NULL)
23 $this->authentifier($v1, $v2);
27 * Est-ce que le participant existe ? C-à-d qu'il est inscrit.
29 public function existe()
31 return $this->id
!= 0;
34 private function authentifier($v1=NULL, $v2=NULL)
36 # Aucunes valeurs transmise => ce n'est pas un participant valide.
37 if ($v1 == NULL && $v2 == NULL)
40 if (is_string($v1) && is_string($v2)) # Aucun des arguments n'est vide alors c'est le pseudo et le password qui ont été transmis
42 $res = pg_query_params("SELECT id FROM participants WHERE pseudo = $1 AND password = $2", array($v1, sha1($v2)));
44 else # Sinon c'est l'id
45 $res = pg_query_params("SELECT id FROM participants WHERE id
= $1", array($v1));
47 if (pg_result_status($res) == PGSQL_TUPLES_OK
&& pg_num_rows($res) === 1)
49 $this->id
= pg_fetch_object($res)->id
;
50 $this->chargerInfos();
54 public function chargerInfos($v1=NULL, $v2=NULL)
56 $this->authentifier($v1, $v2);
61 $res = pg_query_params("SELECT * FROM participants WHERE id = $1", array($this->id));
63 if (pg_result_status($res) == PGSQL_TUPLES_OK && pg_num_rows($res) === 1)
64 $this->info = pg_fetch_object($res);
70 * Renvoie le nombre de votes restant pour le participant.
72 function nb_vote_restant()
74 $nombre_de_vote = pg_fetch_array(pg_query_params("
75 SELECT
COUNT(*) FROM participants RIGHT JOIN jeux_choisis ON participants
.id
= jeux_choisis
.participant_id
76 WHERE participants
.id
= $1
77 GROUP BY participants
.id
78 ", array($this->id)));
80 return Participant::$NB_VOTES_PAR_PARTICIPANT - $nombre_de_vote[0];
84 * Renvois TRUE si le nombre de participant max est atteint.
86 static function nombre_participant_max_atteint()
88 return Participant::nombre_place_restante() <= 0;
92 * Renvois le nombre de places restantes.
94 static function nombre_place_restante()
97 $res_SQL = pg_query("SELECT
COUNT(*) FROM participants
");
98 $nb_participant = pg_fetch_row($res_SQL);
100 return $config->get('nb_max_participant') - $nb_participant[0];