Finalisation des vues de consultation et integration des liens entre jeux categories et genres
This commit is contained in:
@@ -8,17 +8,19 @@ class Game extends CI_Controller {
|
||||
redirect('home');
|
||||
}
|
||||
|
||||
// 1. Charger le modèle des jeux
|
||||
$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);
|
||||
|
||||
if (empty($data['game'])) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -8,10 +8,9 @@ class Genre extends CI_Controller {
|
||||
redirect('home');
|
||||
}
|
||||
|
||||
// 1. Charger les modèles nécessaires
|
||||
$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);
|
||||
$data['genre'] = $this->db->get('genre')->row_array();
|
||||
|
||||
@@ -19,10 +18,8 @@ class Genre extends CI_Controller {
|
||||
show_404();
|
||||
}
|
||||
|
||||
// 3. Récupérer tous les jeux liés à ce genre
|
||||
$data['games'] = $this->Game_model->get_by_genre($id);
|
||||
|
||||
// 4. Envoyer les données à la vue
|
||||
$this->load->view('genre_games_list_view', $data);
|
||||
$this->load->view('games_list_view', $data);
|
||||
}
|
||||
}
|
||||
@@ -15,4 +15,20 @@ class Home extends CI_Controller {
|
||||
// 3. Charger la vue en lui passant les données
|
||||
$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();
|
||||
}
|
||||
|
||||
|
||||
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,11 +1,16 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
|
||||
class Game_model extends CI_Model {
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
$this->load->database();
|
||||
public function search_by_title($keyword) {
|
||||
|
||||
$this->db->like('name', $keyword);
|
||||
$query = $this->db->get('game');
|
||||
|
||||
return $query->result();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -68,11 +73,11 @@ class Game_model extends CI_Model {
|
||||
}
|
||||
|
||||
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) {
|
||||
$leJeu = $this->db->get_where('game', array('id' => $id));
|
||||
$leJeu = $this->db->get_where('game', array('gameId' => $id));
|
||||
return $leJeu->row_array();
|
||||
}
|
||||
|
||||
@@ -84,11 +89,21 @@ class Game_model extends CI_Model {
|
||||
'price' => empty($prix) ? NULL : $prix
|
||||
);
|
||||
|
||||
$this->db->where('id', $id);
|
||||
$this->db->where('gameId', $id);
|
||||
return $this->db->update('game', $donnees);
|
||||
}
|
||||
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
/**
|
||||
* Récupère tous les genres de la base de données
|
||||
*/
|
||||
public function get_all() {
|
||||
$query = $this->db->get('genre');
|
||||
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">
|
||||
<head>
|
||||
<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>
|
||||
<body>
|
||||
<a href="<?= site_url('home') ?>">⬅ Retour à l'accueil</a>
|
||||
|
||||
<p><a href="<?php echo site_url('home'); ?>">← Retour à l'accueil</a></p>
|
||||
|
||||
<main style="display: flex; gap: 40px; margin-top: 20px;">
|
||||
|
||||
<section style="max-width: 300px;">
|
||||
<div class="game-detail">
|
||||
<div>
|
||||
<?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: ?>
|
||||
<div style="width: 200px; height: 300px; background: #ccc; display: flex; align-items: center; justify-content: center; text-align: center; border-radius: 8px;">
|
||||
<span>Aucune image<br>disponible</span>
|
||||
<div class="poster" style="background:#eee; padding:50px; text-align:center;">
|
||||
Aucun poster disponible
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
<section>
|
||||
<h1><?php echo html_escape($game['title']); ?></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>
|
||||
<div class="game-info">
|
||||
<h1><?= html_escape($game['name']) ?> (<?= html_escape($game['releaseYear']) ?>)</h1>
|
||||
|
||||
<hr>
|
||||
<p style="font-style: italic; color: #666;">Espace administration (Éditer / Supprimer)</p>
|
||||
</section>
|
||||
<p><strong>Développeur :</strong> <?= !empty($game['developer_name']) ? html_escape($game['developer_name']) : 'Inconnu' ?></p>
|
||||
|
||||
</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>
|
||||
</html>
|
||||
@@ -2,28 +2,31 @@
|
||||
<html lang="fr">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Jeux de la catégorie <?php echo html_escape($category['name']); ?></title>
|
||||
<title>Liste des jeux</title>
|
||||
</head>
|
||||
<body>
|
||||
<a href="<?= site_url('home') ?>">Retour à l'accueil</a>
|
||||
|
||||
<p><a href="<?php echo site_url('home'); ?>">← Retour à l'accueil</a></p>
|
||||
|
||||
<h1>Jeux dans la catégorie : "<?php echo html_escape($category['name']); ?>"</h1>
|
||||
|
||||
<?php if (empty($games)): ?>
|
||||
<p>Aucun jeu trouvé dans cette catégorie pour le moment.</p>
|
||||
<?php if (isset($category)): ?>
|
||||
<h1>Jeux de la catégorie : <?= html_escape($category['name']) ?></h1>
|
||||
<?php elseif (isset($genre)): ?>
|
||||
<h1>Jeux du genre : <?= html_escape($genre['name']) ?></h1>
|
||||
<?php else: ?>
|
||||
<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>
|
||||
<h1>Liste des jeux</h1>
|
||||
<?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>
|
||||
</html>
|
||||
@@ -9,12 +9,20 @@
|
||||
<h1>Bienvenue sur l'application Jeux Vidéo</h1>
|
||||
|
||||
<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>
|
||||
<h2>Nos Catégories</h2>
|
||||
<ul>
|
||||
<?php foreach ($categories as $category): ?>
|
||||
<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']); ?>
|
||||
</a>
|
||||
</li>
|
||||
@@ -27,7 +35,7 @@
|
||||
<ul>
|
||||
<?php foreach ($genres as $genre): ?>
|
||||
<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']); ?>
|
||||
</a>
|
||||
</li>
|
||||
|
||||
@@ -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>
|
||||
Reference in New Issue
Block a user