7e549e12b64eef94441bb659d2d2a83b06ab231f
[cl7.git] / php / participant.php
1 <?php # coding: utf-8
2
3 /**
4 * Représente un participant.
5 */
6 class Participant
7 {
8 public $info; # Toute les infos du membre sous la forme d'un objet.
9 public $valide; # Savoir si le participant existe.
10
11 static private $NB_VOTES_PAR_PARTICIPANT = 3; # Concerne les votes des jeux joueés.
12
13 /**
14 * Constructeur, peut être appelé sous trois formes différentes :
15 * 1) $v1 = NULL, $v2 = NULL : participant non-valide
16 * 2) $v1 = id, $v2 = NULL : la participant existe et est chargé à partir de son id
17 * 3) $v1 = pseudo, $v2 = password : le participant existe et est chargé à partir de son pseudo et de son password
18 */
19 function Participant($v1=NULL, $v2=NULL)
20 {
21 # Aucunes valeurs transmise => ce n'est pas un participant valide.
22 if ($v1 == NULL && $v2 == NULL)
23 {
24 $this->valide = 0;
25 return;
26 }
27
28 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 = mysql_query("SELECT * FROM participants WHERE pseudo = '" . addslashes($v1) . "' AND password = '" . addslashes($v2) . "'");
30 else # Sinon c'est l'id
31 $res = mysql_query("SELECT * FROM participants WHERE id = " . addslashes($v1));
32
33 if (mysql_error() || mysql_num_rows($res) == 0)
34 {
35 $this->valide = FALSE;
36 }
37 else
38 {
39 $this->info = mysql_fetch_object($res);
40 $this->valide = TRUE;
41 }
42 }
43
44 /**
45 * Renvoie le nombre de votes restant pour le participant.
46 */
47 function nb_vote_restant()
48 {
49 $nombre_de_vote = mysql_fetch_array(mysql_query("
50 SELECT COUNT(*) FROM participants RIGHT JOIN jeux_choisis ON participants.id = jeux_choisis.participant_id
51 WHERE participants.id = " . $this->info->id . "
52 GROUP BY participants.id
53 "));
54
55 return Participant::$NB_VOTES_PAR_PARTICIPANT - $nombre_de_vote[0];
56 }
57
58 /**
59 * Renvois TRUE si le nombre de participant max est atteint.
60 */
61 static function nombre_participant_max_atteint()
62 {
63 global $config;
64 $res_SQL = mysql_query("SELECT COUNT(*) FROM participants");
65 $nb_participant = mysql_fetch_row($res_SQL);
66
67 return $nb_participant[0] >= $config->get('nb_max_participant');
68 }
69
70 /**
71 * Renvois le nombre de places restantes.
72 */
73 static function nombre_place_restante()
74 {
75 global $config;
76 $res_SQL = mysql_query("SELECT COUNT(*) FROM participants");
77 $nb_participant = mysql_fetch_row($res_SQL);
78
79 return $config->get('nb_max_participant') - $nb_participant[0];
80 }
81 }
82
83 ?>