Merge remote-tracking branch 'upstream/main' into correction-tp4

This commit is contained in:
JARNOUEN DE VILLARTAY Ulysse (SAFRAN AIRCRAFT ENGINES)
2026-04-15 16:49:35 +02:00
22 changed files with 682 additions and 214 deletions
+3
View File
@@ -8,3 +8,6 @@ color:#2E8B57;
.Loss{
color:#FF6347;
}
.Draw{
color:#DAA520;
}
+29 -14
View File
@@ -1,20 +1,35 @@
<?php
$images = ["rock.png","paper.png","scissors.png"];
$isPlaying = true;
$ROCK = 0;
$PAPER = 1;
$SCISSORS = 2;
$playerChoice = 0;
$computerChoice = 1;
$images = ["rock.png", "paper.png", "scissors.png"];
$rules = [
$ROCK => [$ROCK => "Draw", $PAPER => "Loss", $SCISSORS => "Win"],
$PAPER => [$ROCK => "Win", $PAPER => "Draw", $SCISSORS => "Loss"],
$SCISSORS => [$ROCK => "Loss", $PAPER => "Win", $SCISSORS => "Draw"],
];
$message = "Win";
$class = "Win";
$playerChoice = filter_input(
INPUT_GET,
'choice',
FILTER_VALIDATE_INT,
['options' => ['min_range' => 0, 'max_range' => 2]]
);
$imagePlayer = $images[$playerChoice];
$imageComputer = $images[$computerChoice];
$isPlaying = ($playerChoice !== null && $playerChoice !== false);
include './views/header.php';
if ($isPlaying){
include './views/game.php';
include './views/message.php';
if ($isPlaying) {
$computerChoice = mt_rand(0, 2);
$message = $rules[$playerChoice][$computerChoice];
$class = $message;
$imagePlayer = $images[$playerChoice];
$imageComputer = $images[$computerChoice];
}
include './views/footer.php';
?>
include_once './views/header.php';
if ($isPlaying) {
include_once './views/game.php';
include_once './views/message.php';
}
include_once './views/footer.php';
+25 -1
View File
@@ -2,7 +2,31 @@
include_once './securite.php';
include_once './modeles/modeleFilms.php';
$films = getFilms();
$currentPage = filter_input(
INPUT_GET,
'page',
FILTER_VALIDATE_INT,
['options' => ['min_range' => 1]]
);
if ($currentPage === null || $currentPage === false) {
$currentPage = 1;
}
$perPage = 10;
$data = getFilms($currentPage, $perPage);
$films = $data['films'];
$errorMessage = $data['error'];
$totalFilms = $data['total'];
$totalPages = max(1, (int) ceil($totalFilms / $perPage));
if ($currentPage > $totalPages && $totalFilms > 0) {
$currentPage = $totalPages;
$data = getFilms($currentPage, $perPage);
$films = $data['films'];
$errorMessage = $data['error'];
$totalFilms = $data['total'];
}
//
// On charge les fichiers de vue une fois les données prêtes.
+58 -15
View File
@@ -1,28 +1,71 @@
<?php
include_once __DIR__ . '/connexion.php';
function getFilms()
function getConnection()
{
static $conn = null;
if ($conn === null) {
$host = getenv('DB_HOST') ?: 'https://dwarves.iut-fbleau.fr';
$login = getenv('DB_USER') ?: getenv('USER') ?: getenv('USERNAME') ?: 'root';
$password = getenv('DB_PASSWORD') ?: $login;
$database = getenv('DB_NAME') ?: $login;
$conn = mysqli_connect($host, $login, $password, $database);
if ($conn !== false) {
mysqli_set_charset($conn, 'utf8mb4');
}
}
return $conn;
}
function getFilms($page = 1, $perPage = 10)
{
$conn = getConnection();
$sql = "
SELECT Film.idFilm, Film.titre, Film.annee, Genre.code AS genre, Artiste.nom, Artiste.prenom
FROM Film
JOIN Genre ON Genre.code = Film.genre
JOIN Artiste ON Artiste.idArtiste = Film.idMes
ORDER BY Film.titre ASC
";
if ($conn === false) {
return [
'films' => [],
'total' => 0,
'error' => 'Connexion MySQL impossible.',
];
}
$page = max(1, (int) $page);
$perPage = max(1, (int) $perPage);
$offset = ($page - 1) * $perPage;
$sql = "SELECT SQL_CALC_FOUND_ROWS
F.idFilm,
F.titre,
F.annee,
G.code AS genre,
A.prenom,
A.nom
FROM Film AS F
INNER JOIN Artiste AS A ON F.idMes = A.idArtiste
INNER JOIN Genre AS G ON F.genre = G.code
ORDER BY F.titre ASC
LIMIT {$offset}, {$perPage}";
$result = mysqli_query($conn, $sql);
if ($result === false) {
die('Erreur SQL lors de la récupération des films : ' . mysqli_error($conn));
return [
'films' => [],
'total' => 0,
'error' => 'Exécution de la requête impossible.',
];
}
$films = array();
while ($film = mysqli_fetch_assoc($result)) {
$films[] = $film;
}
$films = mysqli_fetch_all($result, MYSQLI_ASSOC);
mysqli_free_result($result);
$totalResult = mysqli_query($conn, 'SELECT FOUND_ROWS() AS total');
$totalRow = $totalResult ? mysqli_fetch_assoc($totalResult) : ['total' => 0];
$total = isset($totalRow['total']) ? (int) $totalRow['total'] : 0;
return $films;
return [
'films' => $films,
'total' => $total,
'error' => null,
];
}
+54 -22
View File
@@ -1,32 +1,64 @@
<!--
Variables de la vue
$films : les films de la page
<!--
Variables de la vue
$films : les films de la page
-->
<h2>Films</h2>
<?php if (!empty($errorMessage)) { ?>
<article><?php echo htmlspecialchars($errorMessage, ENT_QUOTES, 'UTF-8'); ?></article>
<?php } ?>
<table>
<thead>
<tr>
<th>Titre</th>
<th>Année</th>
<th>Genre</th>
<th>Réalisateur</th>
</tr>
</thead>
<tbody>
<thead>
<tr>
<th>Titre</th>
<th>Année</th>
<th>Genre</th>
<th>Réalisateur</th>
</tr>
</thead>
<tbody>
<?php
foreach($films as $film){
echo "
<tr>
<td><a href='#'>{$film['titre']}</a></td>
<td>{$film['annee']}</td>
<td>{$film['genre']}</td>
<td>{$film['prenom']} {$film['nom']}</td>
</tr>";
foreach ($films as $film) {
$titre = htmlspecialchars($film['titre'], ENT_QUOTES, 'UTF-8');
$annee = htmlspecialchars((string) $film['annee'], ENT_QUOTES, 'UTF-8');
$genre = htmlspecialchars($film['genre'], ENT_QUOTES, 'UTF-8');
$realisateur = htmlspecialchars($film['prenom'] . ' ' . $film['nom'], ENT_QUOTES, 'UTF-8');
echo "
<tr>
<td><a href='#'>{$titre}</a></td>
<td>{$annee}</td>
<td>{$genre}</td>
<td>{$realisateur}</td>
</tr>";
}
?>
</tbody>
</tbody>
</table>
<?php if ($totalPages > 1) { ?>
<nav>
<ul>
<li>
<?php if ($currentPage > 1) { ?>
<a href="?page=<?php echo $currentPage - 1; ?>">Précédent</a>
<?php } else { ?>
<span>Précédent</span>
<?php } ?>
</li>
</ul>
<ul>
<li>Page <?php echo $currentPage; ?> / <?php echo $totalPages; ?></li>
</ul>
<ul>
<li>
<?php if ($currentPage < $totalPages) { ?>
<a href="?page=<?php echo $currentPage + 1; ?>">Suivant</a>
<?php } else { ?>
<span>Suivant</span>
<?php } ?>
</li>
</ul>
</nav>
<?php } ?>