Finalisation des vues de consultation et integration des liens entre jeux categories et genres #6

Merged
Tajeddine Slimani merged 2 commits from suite_sae into main 2026-06-10 16:50:03 +02:00
10 changed files with 185 additions and 65 deletions
@@ -8,17 +8,19 @@ class Game extends CI_Controller {
redirect('home'); redirect('home');
} }
// 1. Charger le modèle des jeux
$this->load->model('Game_model'); $this->load->model('Game_model');
$this->load->model('Category_model');
$this->load->model('Genre_model');
// 2. Récupérer les données du jeu cible
$data['game'] = $this->Game_model->get_by_id($id); $data['game'] = $this->Game_model->get_by_id($id);
if (empty($data['game'])) { if (empty($data['game'])) {
show_404(); show_404();
} }
// 3. Charger la vue de détail en lui poussant les données $data['categories'] = $this->Category_model->get_by_game($id);
$data['genres'] = $this->Genre_model->get_by_game($id);
$this->load->view('game_detail_view', $data); $this->load->view('game_detail_view', $data);
} }
} }
@@ -8,10 +8,9 @@ class Genre extends CI_Controller {
redirect('home'); redirect('home');
} }
// 1. Charger les modèles nécessaires
$this->load->model('Game_model'); $this->load->model('Game_model');
$this->load->model('Genre_model');
// 2. Récupérer les informations du genre pour afficher son nom
$this->db->where('genreId', $id); $this->db->where('genreId', $id);
$data['genre'] = $this->db->get('genre')->row_array(); $data['genre'] = $this->db->get('genre')->row_array();
@@ -19,10 +18,8 @@ class Genre extends CI_Controller {
show_404(); show_404();
} }
// 3. Récupérer tous les jeux liés à ce genre
$data['games'] = $this->Game_model->get_by_genre($id); $data['games'] = $this->Game_model->get_by_genre($id);
// 4. Envoyer les données à la vue $this->load->view('games_list_view', $data);
$this->load->view('genre_games_list_view', $data);
} }
} }
@@ -15,4 +15,20 @@ class Home extends CI_Controller {
// 3. Charger la vue en lui passant les données // 3. Charger la vue en lui passant les données
$this->load->view('home_view', $data); $this->load->view('home_view', $data);
} }
public function search() {
$keyword = $this->input->get('keyword', TRUE);
if (empty($keyword)) {
redirect('home');
}
$this->load->model('Game_model');
$data['games'] = $this->Game_model->search_by_title($keyword);
$data['search_keyword'] = $keyword;
$this->load->view('search_results_view', $data);
}
} }
@@ -16,4 +16,19 @@ class Category_model extends CI_Model {
return $query->result_array(); return $query->result_array();
} }
public function get_by_game($game_id) {
$this->db->select('category.*');
$this->db->from('category');
$this->db->join('game_category', 'game_category.categoryId = category.categoryId');
$this->db->where('game_category.gameId', $game_id);
$query = $this->db->get();
return $query->result_array();
}
} }
@@ -1,12 +1,17 @@
<?php <?php
defined('BASEPATH') OR exit('No direct script access allowed'); defined('BASEPATH') OR exit('No direct script access allowed');
class Game_model extends CI_Model { class Game_model extends CI_Model {
public function __construct() { public function search_by_title($keyword) {
parent::__construct();
$this->load->database(); $this->db->like('name', $keyword);
$query = $this->db->get('game');
return $query->result();
} }
}
/** /**
* Récupère les jeux appartenant à une catégorie spécifique * Récupère les jeux appartenant à une catégorie spécifique
@@ -68,11 +73,11 @@ class Game_model extends CI_Model {
} }
public function supprimer_jeu($id) { public function supprimer_jeu($id) {
return $this->db->delete('game', array('id' => $id)); return $this->db->delete('game', array('gameId' => $id));
} }
public function get_jeu($id) { public function get_jeu($id) {
$leJeu = $this->db->get_where('game', array('id' => $id)); $leJeu = $this->db->get_where('game', array('gameId' => $id));
return $leJeu->row_array(); return $leJeu->row_array();
} }
@@ -84,7 +89,7 @@ class Game_model extends CI_Model {
'price' => empty($prix) ? NULL : $prix 'price' => empty($prix) ? NULL : $prix
); );
$this->db->where('id', $id); $this->db->where('gameId', $id);
return $this->db->update('game', $donnees); return $this->db->update('game', $donnees);
} }
@@ -103,6 +108,16 @@ class Game_model extends CI_Model {
} }
public function search_by_title($keyword) {
$this->db->select('*');
$this->db->from('game');
$this->db->like('title', $keyword);
$query = $this->db->get();
return $query->result_array();
}
} }
@@ -8,11 +8,20 @@ class Genre_model extends CI_Model {
$this->load->database(); $this->load->database();
} }
/**
* Récupère tous les genres de la base de données
*/
public function get_all() { public function get_all() {
$query = $this->db->get('genre'); $query = $this->db->get('genre');
return $query->result_array(); return $query->result_array();
} }
public function get_by_game($game_id) {
$this->db->select('genre.*');
$this->db->from('genre');
$this->db->join('game_genre', 'game_genre.genreId = genre.genreId');
$this->db->where('game_genre.gameId', $game_id);
$query = $this->db->get();
return $query->result_array();
}
} }
@@ -2,38 +2,63 @@
<html lang="fr"> <html lang="fr">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<title><?php echo html_escape($game['title']); ?> - Détails</title> <title>Détails du jeu - <?= html_escape($game['name']) ?></title>
<style>
.game-detail { display: flex; gap: 20px; margin-top: 20px; }
.game-info { max-width: 600px; }
.poster { max-width: 300px; border-radius: 8px; box-shadow: 0 4px 8px rgba(0,0,0,0.1); }
</style>
</head> </head>
<body> <body>
<a href="<?= site_url('home') ?>">⬅ Retour à l'accueil</a>
<p><a href="<?php echo site_url('home'); ?>">← Retour à l'accueil</a></p> <div class="game-detail">
<div>
<main style="display: flex; gap: 40px; margin-top: 20px;">
<section style="max-width: 300px;">
<?php if (!empty($game['poster_url'])): ?> <?php if (!empty($game['poster_url'])): ?>
<img src="<?php echo html_escape($game['poster_url']); ?>" alt="Jaquette de <?php echo html_escape($game['title']); ?>" style="width: 100%; height: auto; border-radius: 8px;"> <img src="<?= base_url('assets/uploads/' . html_escape($game['poster_url'])) ?>" alt="Poster de <?= html_escape($game['name']) ?>" class="poster">
<?php else: ?> <?php else: ?>
<div style="width: 200px; height: 300px; background: #ccc; display: flex; align-items: center; justify-content: center; text-align: center; border-radius: 8px;"> <div class="poster" style="background:#eee; padding:50px; text-align:center;">
<span>Aucune image<br>disponible</span> Aucun poster disponible
</div> </div>
<?php endif; ?> <?php endif; ?>
</section> </div>
<section> <div class="game-info">
<h1><?php echo html_escape($game['title']); ?></h1> <h1><?= html_escape($game['name']) ?> (<?= html_escape($game['releaseYear']) ?>)</h1>
<ul>
<li><strong>Année de sortie :</strong> <?php echo html_escape($game['year']); ?></li>
<li><strong>Développeur :</strong>
<?php echo !empty($game['developer_name']) ? html_escape($game['developer_name']) : 'Inconnu'; ?>
</li>
</ul>
<hr> <p><strong>Développeur :</strong> <?= !empty($game['developer_name']) ? html_escape($game['developer_name']) : 'Inconnu' ?></p>
<p style="font-style: italic; color: #666;">Espace administration (Éditer / Supprimer)</p>
</section>
</main> <p><strong>Prix :</strong> <?= !empty($game['price']) ? html_escape($game['price']) . ' €' : 'Non renseigné' ?></p>
<h3>Description :</h3>
<p><?= nl2br(html_escape($game['shortDescription'])) ?></p>
<h3>Catégories associées :</h3>
<p>
<?php if (!empty($categories)): ?>
<?php foreach ($categories as $cat): ?>
<a href="<?= site_url('category/view/' . $cat['categoryId']) ?>" style="margin-right: 10px; background: #e0e0e0; padding: 5px 10px; border-radius: 3px; text-decoration: none; color: #333;">
<?= html_escape($cat['name']) ?>
</a>
<?php endforeach; ?>
<?php else: ?>
Aucune catégorie pour ce jeu.
<?php endif; ?>
</p>
<h3>Genres associés :</h3>
<p>
<?php if (!empty($genres)): ?>
<?php foreach ($genres as $gen): ?>
<a href="<?= site_url('genre/view/' . $gen['genreId']) ?>" style="margin-right: 10px; background: #d0e0fc; padding: 5px 10px; border-radius: 3px; text-decoration: none; color: #1a4ba8;">
<?= html_escape($gen['name']) ?>
</a>
<?php endforeach; ?>
<?php else: ?>
Aucun genre pour ce jeu.
<?php endif; ?>
</p>
</div> </div>
</body> </body>
</html> </html>
@@ -2,28 +2,31 @@
<html lang="fr"> <html lang="fr">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>Jeux de la catégorie <?php echo html_escape($category['name']); ?></title> <title>Liste des jeux</title>
</head> </head>
<body> <body>
<a href="<?= site_url('home') ?>">Retour à l'accueil</a>
<p><a href="<?php echo site_url('home'); ?>">← Retour à l'accueil</a></p> <?php if (isset($category)): ?>
<h1>Jeux de la catégorie : <?= html_escape($category['name']) ?></h1>
<h1>Jeux dans la catégorie : "<?php echo html_escape($category['name']); ?>"</h1> <?php elseif (isset($genre)): ?>
<h1>Jeux du genre : <?= html_escape($genre['name']) ?></h1>
<?php if (empty($games)): ?>
<p>Aucun jeu trouvé dans cette catégorie pour le moment.</p>
<?php else: ?> <?php else: ?>
<ul> <h1>Liste des jeux</h1>
<?php foreach ($games as $game): ?>
<li>
<a href="<?php echo site_url('game/detail/' . $game['gameId']); ?>">
<strong><?php echo html_escape($game['title']); ?></strong>
</a>
(<?php echo html_escape($game['year']); ?>)
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?> <?php endif; ?>
<ul>
<?php if (!empty($games)): ?>
<?php foreach ($games as $game): ?>
<li>
<a href="<?= site_url('game/detail/' . $game['gameId']) ?>">
<?= html_escape($game['name']) ?> (<?= html_escape($game['releaseYear']) ?>)
</a>
</li>
<?php endforeach; ?>
<?php else: ?>
<p>Aucun jeu trouvé pour cette sélection.</p>
<?php endif; ?>
</ul>
</body> </body>
</html> </html>
@@ -9,14 +9,22 @@
<h1>Bienvenue sur l'application Jeux Vidéo</h1> <h1>Bienvenue sur l'application Jeux Vidéo</h1>
<main style="display: flex; gap: 50px;"> <main style="display: flex; gap: 50px;">
<section style="margin-bottom: 30px; background: #f4f4f4; padding: 15px; border-radius: 5px;">
<h2>Rechercher un jeu vidéo</h2>
<form action="<?php echo site_url('home/search'); ?>" method="GET">
<input type="text" name="keyword" placeholder="Ex: Zelda, Mario..." required style="padding: 8px; width: 250px;">
<button type="submit" style="padding: 8px 15px;">Rechercher</button>
</form>
</section>
<section> <section>
<h2>Nos Catégories</h2> <h2>Nos Catégories</h2>
<ul> <ul>
<?php foreach ($categories as $category): ?> <?php foreach ($categories as $category): ?>
<li> <li>
<a href="<?php echo site_url('category/view/' . $category['id']); ?>"> <a href="<?php echo site_url('category/view/' . $category['categoryId']); ?>">
<?php echo html_escape($category['name']); ?> <?php echo html_escape($category['name']); ?>
</a> </a>
</li> </li>
<?php endforeach; ?> <?php endforeach; ?>
</ul> </ul>
@@ -27,12 +35,12 @@
<ul> <ul>
<?php foreach ($genres as $genre): ?> <?php foreach ($genres as $genre): ?>
<li> <li>
<a href="<?php echo site_url('genre/view/' . $genre['id']); ?>"> <a href="<?php echo site_url('genre/view/' . $genre['genreId']); ?>">
<?php echo html_escape($genre['name']); ?> <?php echo html_escape($genre['name']); ?>
</a> </a>
</li> </li>
<?php endforeach; ?> <?php endforeach; ?>
</ul> </ul>
</section> </section>
</main> </main>
@@ -0,0 +1,30 @@
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<title>Résultats de recherche pour "<?php echo html_escape($search_keyword); ?>"</title>
</head>
<body>
<p><a href="<?php echo site_url('home'); ?>">← Retour à l'accueil</a></p>
<h1>Résultats pour : "<?php echo html_escape($search_keyword); ?>"</h1>
<?php if (empty($games)): ?>
<p>Aucun jeu vidéo ne correspond à votre recherche.</p>
<?php else: ?>
<p><strong><?php echo count($games); ?></strong> jeu(x) trouvé(s) :</p>
<ul>
<?php foreach ($games as $game): ?>
<li>
<a href="<?php echo site_url('game/detail/' . $game['gameId']); ?>">
<strong><?php echo html_escape($game['title']); ?></strong>
</a>
(<?php echo html_escape($game['year']); ?>)
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</body>
</html>