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 # Aucunes valeurs transmise => ce n'est pas un participant valide.
24 if ($v1 == NULL && $v2 == NULL)
27 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
29 $res = pg_query_params("SELECT id FROM participants WHERE pseudo = $1 AND password = $2", array($v1, sha1($v2)));
31 else # Sinon c'est l'id
32 $res = pg_query_params("SELECT id FROM participants WHERE id
= $1", array($v1));
34 if (pg_result_status($res) == PGSQL_TUPLES_OK
&& pg_num_rows($res) === 1)
36 $this->id
= pg_fetch_object($res)->id
;
37 $this->chargerInfos();
42 * Est-ce que le participant existe ? C-à-d qu'il est inscrit.
44 public function existe()
46 return $this->id
!= 0;
49 public function chargerInfos()
54 $res = pg_query_params("SELECT * FROM participants WHERE id = $1", array($this->id));
56 if (pg_result_status($res) == PGSQL_TUPLES_OK && pg_num_rows($res) === 1)
57 $this->info = pg_fetch_object($res);
63 * Renvoie le nombre de votes restant pour le participant.
65 function nb_vote_restant()
67 $nombre_de_vote = pg_fetch_array(pg_query_params("
68 SELECT
COUNT(*) FROM participants RIGHT JOIN jeux_choisis ON participants
.id
= jeux_choisis
.participant_id
69 WHERE participants
.id
= $1
70 GROUP BY participants
.id
71 ", array($this->id)));
73 return Participant::$NB_VOTES_PAR_PARTICIPANT - $nombre_de_vote[0];
77 * Renvois TRUE si le nombre de participant max est atteint.
79 static function nombre_participant_max_atteint()
81 return Participant::nombre_place_restante() <= 0;
85 * Renvois le nombre de places restantes.
87 static function nombre_place_restante()
90 $res_SQL = pg_query("SELECT
COUNT(*) FROM participants
");
91 $nb_participant = pg_fetch_row($res_SQL);
93 return $config->get('nb_max_participant') - $nb_participant[0];