Add new PHP functions to retrieve game details and display them in the view

This commit is contained in:
2024-04-18 14:06:38 +02:00
parent 1ee5c9e7e4
commit 44809197cb
4 changed files with 120 additions and 2 deletions

View File

@@ -0,0 +1,62 @@
<?php
function get_triplet_cartes(int $idplateau)
{
return get_infos_requete("SELECT(
SELECT
COUNT(e.idcarte)
FROM
est_compose e
JOIN carte c USING (idcarte)
JOIN plateau p USING (idplateau)
JOIN partie pa USING (idplateau)
WHERE
idplateau = $idplateau
AND c.niveau LIKE 'verte'
) as nb_verte,
(
SELECT
COUNT(e.idcarte)
FROM
est_compose e
JOIN carte c USING (idcarte)
JOIN plateau p USING (idplateau)
JOIN partie pa USING (idplateau)
WHERE
idplateau = $idplateau
AND c.niveau LIKE 'orange'
) as nb_orange,
(
SELECT
COUNT(e.idcarte)
FROM
est_compose e
JOIN carte c USING (idcarte)
JOIN plateau p USING (idplateau)
JOIN partie pa USING (idplateau)
WHERE
idplateau = $idplateau
AND c.niveau LIKE 'noire'
) as nb_noire")['instances'][0];
}
function get_nb_joueurs(int $idpartie)
{
return get_infos_requete("SELECT COUNT(j.idjoueur) as nb FROM joueur j JOIN joue jo USING(idjoueur) JOIN partie p USING(idpartie) WHERE p.idpartie = $idpartie")['instances'][0];
}
function get_rang(int $idpartie)
{
return get_infos_requete("SELECT jo. pseudo, j.rang FROM partie p JOIN joue j USING(idpartie) JOIN joueur jo USING(idjoueur) WHERE idpartie = $idpartie ORDER BY j.rang LIMIT 3")['instances'];
}
function get_pseudos(int $idpartie)
{
return get_infos_requete("SELECT j.pseudo FROM joueur j JOIN joue jo USING(idjoueur) JOIN partie p USING(idpartie) WHERE p.idpartie = $idpartie")['instances'];
}
function get_plateau_id(int $idpartie) : int
{
return get_infos_requete("SELECT idplateau FROM partie WHERE idpartie = $idpartie")['instances'][0]['idplateau'];
}
?>

View File

@@ -95,6 +95,13 @@ footer {
text-align: center; text-align: center;
} }
.panneau_details_2 {
justify-content: center;
width: 100%;
overflow-y: auto;
text-align: center;
}
.panneau_details>div { .panneau_details>div {
margin-right: 2%; margin-right: 2%;
} }

View File

@@ -1,4 +1,48 @@
<div class="panneau_details"> <?php
function afficherTriplets(int $idplateau)
{
$triplets = get_triplet_cartes($idplateau);
echo '<div id="triplets">';
echo '</br>';
echo '<p>Cartes:</p>';
echo '<p>Cartes vertes: ' . $triplets['nb_verte'] . '</p>';
echo '<p>Cartes oranges: ' . $triplets['nb_orange'] . '</p>';
echo '<p>Cartes noires: ' . $triplets['nb_noire'] . '</p>';
echo '</div>';
}
function afficherRangPseudo(int $idpartie)
{
$rang = get_rang($idpartie);
$pseudo = get_pseudos($idpartie);
echo '<div id="rangPseudo">';
echo '</br>';
echo '<p>Joueurs:</p>';
foreach ($pseudo as $p){
echo '<p>Pseudo: ' . $p['pseudo'] . '</p>';
}
echo '</br>';
echo '<p>Classement:</p>';
foreach ($rang as $r){
echo '<p>Pseudo: ' . $r['pseudo'] . '</p>';
echo '<p>Rang: ' . $r['rang'] . '</p>';
}
echo '</div>';
}
function afficherPseudo(int $idpartie)
{
$pseudo = get_pseudos($idpartie);
echo '<div id="pseudo">';
foreach ($pseudo as $p){
echo '<p>Pseudo: ' . $p['pseudo'] . '</p>';
}
echo '</div>';
}
?>
<div class="panneau_details_2">
<h2>Affichage de la partie</h2> <h2>Affichage de la partie</h2>
@@ -14,6 +58,11 @@
} }
} }
echo '</div>'; echo '</div>';
echo afficherTriplets(get_plateau_id($_GET['idpartie']));
echo afficherRangPseudo($_GET['idpartie']);
?> ?>
</tbody> </tbody>
</table> </table>

View File

@@ -32,7 +32,7 @@
$donnees = ['idpartie', 'date_partie', 'horaire']; $donnees = ['idpartie', 'date_partie', 'horaire'];
$parties = $parties['instances'][(int) $_POST["selectparty"] - 1]; $parties = $parties['instances'][(int) $_POST["selectparty"] - 1];
$url = 'vues/details_vue.php?'; $url = 'index.php?page=details&';
foreach ($donnees as $donnee) { foreach ($donnees as $donnee) {
$url .= $donnee . '=' . $parties[$donnee] . '&'; $url .= $donnee . '=' . $parties[$donnee] . '&';
} }