authentifier($v1, $v2); } /** * Est-ce que le participant existe ? C-à-d qu'il est inscrit. */ public function existe() { return $this->id != 0; } private function authentifier($v1=NULL, $v2=NULL) { # Aucunes valeurs transmise => ce n'est pas un participant valide. if ($v1 == NULL && $v2 == NULL) return; 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 { $res = pg_query_params("SELECT id FROM participants WHERE pseudo = $1 AND password = $2", array($v1, sha1($v2))); } else # Sinon c'est l'id $res = pg_query_params("SELECT id FROM participants WHERE id = $1", array($v1)); if (pg_result_status($res) == PGSQL_TUPLES_OK && pg_num_rows($res) === 1) { $this->id = pg_fetch_object($res)->id; $this->chargerInfos(); } } public function chargerInfos($v1=NULL, $v2=NULL) { $this->authentifier($v1, $v2); if (!$this->existe()) return; $res = pg_query_params("SELECT * FROM participants WHERE id = $1", array($this->id)); if (pg_result_status($res) == PGSQL_TUPLES_OK && pg_num_rows($res) === 1) $this->info = pg_fetch_object($res); else $this->id = 0; } /** * Renvoie le nombre de votes restant pour le participant. */ function nb_vote_restant() { $nombre_de_vote = pg_fetch_array(pg_query_params(" SELECT COUNT(*) FROM participants RIGHT JOIN jeux_choisis ON participants.id = jeux_choisis.participant_id WHERE participants.id = $1 GROUP BY participants.id ", array($this->id))); return Participant::$NB_VOTES_PAR_PARTICIPANT - $nombre_de_vote[0]; } /** * Renvois TRUE si le nombre de participant max est atteint. */ static function nombre_participant_max_atteint() { return Participant::nombre_place_restante() <= 0; } /** * Renvois le nombre de places restantes. */ static function nombre_place_restante() { global $config; $res_SQL = pg_query("SELECT COUNT(*) FROM participants"); $nb_participant = pg_fetch_row($res_SQL); return $config->get('nb_max_participant') - $nb_participant[0]; } } ?>