ADD premier commit
[cl7.git] / class_participant.php
1 <?php
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;
12
13 /**
14 * Constructeur, peut être appelé sous trois formes différentes.
15 */
16 function Participant($v1=NULL, $v2=NULL)
17 {
18 # aucunes valeurs transmise => ce n'est pas un participant valide
19 if ($v1 == NULL && $v2 == NULL)
20 {
21 $this->valide = 0;
22 return;
23 }
24
25 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
26 $res = mysql_query("SELECT * FROM participants WHERE pseudo = '" . addslashes($v1) . "' AND password = '" . addslashes($v2) . "'");
27 else # Sinon c'est l'id
28 $res = mysql_query("SELECT * FROM participants WHERE id = " . addslashes($v1));
29
30 if (mysql_num_rows($res) == 0)
31 {
32 $this->valide = FALSE;
33 }
34 else
35 {
36 $this->info = mysql_fetch_object($res);
37 $this->valide = TRUE;
38 }
39 }
40
41 /**
42 * Renvoie le nombre de votes restant pour le participant.
43 */
44 function nb_vote_restant()
45 {
46 $nombre_de_vote = mysql_fetch_array(mysql_query("
47 SELECT COUNT(*) FROM participants RIGHT JOIN jeux_choisis ON participants.id = jeux_choisis.participant_id
48 WHERE participants.id = " . $this->info->id . "
49 GROUP BY participants.id
50 "));
51
52 return Participant::$NB_VOTES_PAR_PARTICIPANT - $nombre_de_vote[0];
53 }
54
55 /**
56 * Renvois TRUE si le nombre de participant max est atteint.
57 */
58 static function nombre_participant_max_atteint()
59 {
60 global $NB_MAX_PARTICIPANT;
61 $res_SQL = mysql_query("SELECT COUNT(*) FROM participants");
62 $nb_participant = mysql_fetch_row($res_SQL);
63
64 return $nb_participant[0] >= $NB_MAX_PARTICIPANT;
65 }
66
67 /**
68 * Renvois le nombre de places restantes.
69 */
70 static function nombre_place_restante()
71 {
72 global $NB_MAX_PARTICIPANT;
73 $res_SQL = mysql_query("SELECT COUNT(*) FROM participants");
74 $nb_participant = mysql_fetch_row($res_SQL);
75
76 return $NB_MAX_PARTICIPANT - $nb_participant[0];
77 }
78 }
79
80 ?>