X-Git-Url: http://git.euphorik.ch/?a=blobdiff_plain;f=php%2Fpages%2Fjeux_joues.php;h=9c531ec13003c440b8c249d1ce524d4ecb7c183f;hb=912c54815fb34d93de674af2bcf3acc85ce7421d;hp=135f57d224f2618c6fe106776792dd8403e821bd;hpb=c1d939c263d7748af8a126f4fba72972c263561d;p=cl7.git diff --git a/php/pages/jeux_joues.php b/php/pages/jeux_joues.php index 135f57d..9c531ec 100644 --- a/php/pages/jeux_joues.php +++ b/php/pages/jeux_joues.php @@ -2,40 +2,57 @@ include_once("php/traitement_pre_affichage.php"); -if (!$le_participant->valide) +if (!$participant->existe()) { echo '

Remarque : Il faut être inscrit pour pouvoir voter.

'; +} +else if ($config->get("inscription_terminees")) +{ + echo '

Remarque : Les inscriptions sont terminées, il n\'est plus possible de voter.

'; } - + +$vote_possible = !$config->get("inscription_terminees") && $participant->existe(); echo '

- ', ($le_participant->valide ? '' : ''), ''; - -$jeux_query = mysql_query(" - SELECT jeux.id, jeux.nom, jeux_choisis.participant_id, COUNT(*) + IF(participant_id is not null, 1, 0) - 1 AS nb_vote - FROM jeux LEFT JOIN jeux_choisis ON jeux.id = jeux_choisis.jeu_id - GROUP BY jeux.id - ORDER BY nb_vote DESC, nom + ', ($vote_possible ? '' : ''), ''; + +# /!\ Attention, requête un poil tricky : +# On souhait avoir une liste des jeux joués avec pour chaque tuple : +# - l'id du jeu et son nom +# - Un tableau des participants ayant voté pour ce jeu +# De plus il faut que le résultat soit trié par le nombre de vote +$jeux_query = pg_query(" + SELECT + jeux.id, + jeux.nom, + array_agg(jeux_choisis.participant_id) AS participants, + (COUNT(*) + (CASE WHEN bool_and(jeux_choisis.participant_id is null) THEN -1 ELSE 0 END)) as nb_vote + FROM + jeux + LEFT JOIN jeux_choisis ON jeux.id = jeux_choisis.jeu_id + GROUP BY jeux.id, jeux.nom + ORDER BY nb_vote DESC, jeux.nom "); -while ($jeu = mysql_fetch_object($jeux_query)) -{ +while ($jeu = pg_fetch_object($jeux_query)) +{ + $a_vote = FALSE; + # est-ce que le participant courant à voté pour ce jeu ? - if ($le_participant->valide) - { - $a_vote = mysql_fetch_row(mysql_query(" - SELECT COUNT(*) FROM jeux_choisis - WHERE participant_id = ".$le_participant->info->id." AND jeu_id = ".$jeu->id - )); $a_vote = $a_vote[0]; + if ($vote_possible) + { + $participants = split(",", ereg_replace("[{-}]", "", $jeu->participants)); + for($i = 0; $i < count($participants); $i++) + $participants[$i] = (int)$participants[$i]; + + $a_vote = in_array($participant->info->id, $participants); } - else - $a_vote = FALSE; echo '', - $le_participant->valide ? '' : '', + $vote_possible ? '' : '', '', ''; } @@ -43,7 +60,7 @@ while ($jeu = mysql_fetch_object($jeux_query)) echo '
VotesJeux
VotesJeux
' . $jeu->nb_vote . '' . traitement_pre_affichage($jeu->nom) . '
'; -if ($le_participant->valide) +if ($vote_possible) echo '

Autre :

'; @@ -51,7 +68,7 @@ if ($le_participant->valide) echo '
'; # affichage du nombre de vote restant -if ($le_participant->valide) - echo '

Nombre de votes restant : ' . $le_participant->nb_vote_restant() . '

'; +if ($vote_possible) + echo '

Nombre de votes restant : ' . $participant->nb_vote_restant() . '

'; ?> \ No newline at end of file