Réparation de la recherche
This commit is contained in:
@@ -23,7 +23,7 @@ defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
| a PHP script and you can easily do that on your own.
|
||||
|
|
||||
*/
|
||||
$config['base_url'] = 'https://dwarves.iut-fbleau.fr/~orfao/SAE/SAE_2.02/CodeIgniter-3.1.13/';
|
||||
$config['base_url'] = 'https://dwarves.iut-fbleau.fr/~stiti/SAE_2.02/CodeIgniter-3.1.13/';
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
|
@@ -5,18 +5,14 @@ class Search extends CI_Controller {
|
||||
|
||||
public function __construct(){
|
||||
parent::__construct();
|
||||
$this->load->model('Search_model');
|
||||
$this->load->helper('url');
|
||||
$this->load->helper('html');
|
||||
$this->load->model('Search_model');
|
||||
$this->load->helper(['url', 'html']);
|
||||
}
|
||||
|
||||
public function index(){
|
||||
// Récupérer la requête de recherche depuis la barre de recherche
|
||||
$query = $this->input->get('query');
|
||||
|
||||
// Vérifier que la requête de recherche n'est pas vide
|
||||
if (empty($query)) {
|
||||
// Charger la vue avec un message d'erreur
|
||||
$data['query'] = $query;
|
||||
$data['musiques'] = [];
|
||||
$data['albums'] = [];
|
||||
@@ -24,33 +20,32 @@ class Search extends CI_Controller {
|
||||
$data['artistes'] = [];
|
||||
$data['error'] = "La requête de recherche ne peut pas être vide.";
|
||||
|
||||
$data['title']="Résultats de la recherche";
|
||||
$data['css']="assets/css/search_results";
|
||||
$data['title'] = "Résultats de la recherche";
|
||||
$data['css'] = "assets/css/search_results";
|
||||
|
||||
$this->load->view('layout/header_dark', $data);
|
||||
$this->load->view('search_results',$data);
|
||||
$this->load->view('search_results', $data);
|
||||
$this->load->view('layout/footer_dark');
|
||||
return;
|
||||
}
|
||||
|
||||
// Faire une recherche dans les musiques, les albums, les genres et les artistes
|
||||
$musiques = $this->Search_model->searchMusiques($query);
|
||||
$albums = $this->Search_model->searchAlbums($query);
|
||||
$genres = $this->Search_model->searchGenres($query);
|
||||
$artistes = $this->Search_model->searchArtistes($query);
|
||||
|
||||
// Charger la vue avec les résultats de la recherche
|
||||
$data['query'] = $query;
|
||||
$data['musiques'] = $musiques;
|
||||
$data['albums'] = $albums;
|
||||
$data['genres'] = $genres;
|
||||
$data['artistes'] = $artistes;
|
||||
|
||||
$data['title']="Résultats de la recherche";
|
||||
$data['css']="assets/css/search_results";
|
||||
$data['title'] = "Résultats de la recherche";
|
||||
$data['css'] = "assets/css/search_results";
|
||||
|
||||
$this->load->view('layout/header_dark', $data);
|
||||
$this->load->view('search_results',$data);
|
||||
$this->load->view('search_results', $data);
|
||||
$this->load->view('layout/footer_dark');
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
@@ -22,7 +22,7 @@ class Search_model extends CI_Model {
|
||||
}
|
||||
|
||||
public function searchAlbums($query){
|
||||
$sql = "SELECT album.id, album.name, album.year, artist.name as artistName, genre.name as genreName, cover.jpeg
|
||||
$sql = "SELECT album.id, album.name, album.year, artist.id as artist_id, artist.name as artistName, genre.name as genreName, cover.jpeg
|
||||
FROM album
|
||||
JOIN artist ON album.artistid = artist.id
|
||||
JOIN genre ON album.genreid = genre.id
|
||||
@@ -32,6 +32,7 @@ class Search_model extends CI_Model {
|
||||
$query = $this->db->query($sql, array('%' . $query . '%'));
|
||||
return $query->result();
|
||||
}
|
||||
|
||||
|
||||
public function searchGenres($query){
|
||||
$sql = "SELECT id, name FROM genre WHERE name LIKE ? ORDER BY name ASC";
|
||||
@@ -45,3 +46,4 @@ class Search_model extends CI_Model {
|
||||
return $query->result();
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
@@ -1,72 +1,76 @@
|
||||
<h2 class="search-title">Résultats de la recherche pour "<?php echo htmlspecialchars($query, ENT_QUOTES, 'UTF-8'); ?>"</h2>
|
||||
<h2 class="search-title">Résultats de la recherche pour "<?php echo htmlspecialchars($query, ENT_QUOTES, 'UTF-8'); ?>"</h2>
|
||||
|
||||
<?php if (!empty($error)): ?>
|
||||
<p class="error-message"><?php echo $error; ?></p>
|
||||
<?php endif; ?>
|
||||
<?php if (!empty($error)): ?>
|
||||
<p class="error-message"><?php echo htmlspecialchars($error, ENT_QUOTES, 'UTF-8'); ?></p>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if (!empty($musiques)): ?>
|
||||
<div class="section">
|
||||
<h3 class="section-title">Musiques</h3>
|
||||
<ul class="music-list">
|
||||
<?php foreach($musiques as $musique): ?>
|
||||
<li>
|
||||
<?php echo htmlspecialchars($musique->name, ENT_QUOTES, 'UTF-8'); ?> -
|
||||
<a href="<?php echo site_url('artiste/'.$musique->artist_id); ?>">
|
||||
<?php echo htmlspecialchars($musique->artistName, ENT_QUOTES, 'UTF-8'); ?>
|
||||
</a>
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php if (!empty($musiques)): ?>
|
||||
<div class="section">
|
||||
<h3 class="section-title">Musiques</h3>
|
||||
<ul class="music-list">
|
||||
<?php foreach ($musiques as $musique): ?>
|
||||
<li>
|
||||
<?php echo htmlspecialchars($musique->name, ENT_QUOTES, 'UTF-8'); ?> -
|
||||
<a href="<?php echo site_url('artiste/' . htmlspecialchars($musique->artist_id, ENT_QUOTES, 'UTF-8')); ?>">
|
||||
<?php echo htmlspecialchars($musique->artistName, ENT_QUOTES, 'UTF-8'); ?>
|
||||
</a>
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if (!empty($albums)): ?>
|
||||
<div class="section">
|
||||
<h3 class="section-title">Albums</h3>
|
||||
<ul class="album-list">
|
||||
<?php foreach($albums as $album): ?>
|
||||
<li>
|
||||
<a href="<?php echo site_url('albums/view/'.$album->id); ?>">
|
||||
<?php echo htmlspecialchars($album->name, ENT_QUOTES, 'UTF-8'); ?>
|
||||
</a>
|
||||
-
|
||||
<a href="<?php echo site_url('artiste/'.$musique->artist_id); ?>">
|
||||
<?php echo htmlspecialchars($musique->artistName, ENT_QUOTES, 'UTF-8'); ?>
|
||||
</a>
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php if (!empty($albums)): ?>
|
||||
<div class="section">
|
||||
<h3 class="section-title">Albums</h3>
|
||||
<ul class="album-list">
|
||||
<?php foreach ($albums as $album): ?>
|
||||
<li>
|
||||
<a href="<?php echo site_url('albums/view/' . htmlspecialchars($album->id, ENT_QUOTES, 'UTF-8')); ?>">
|
||||
<?php echo htmlspecialchars($album->name, ENT_QUOTES, 'UTF-8'); ?>
|
||||
</a> -
|
||||
<a href="<?php echo site_url('artiste/' . htmlspecialchars($album->artist_id, ENT_QUOTES, 'UTF-8')); ?>">
|
||||
<?php echo htmlspecialchars($album->artistName, ENT_QUOTES, 'UTF-8'); ?>
|
||||
</a>
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if (!empty($genres)): ?>
|
||||
<div class="section">
|
||||
<h3 class="section-title">Genres</h3>
|
||||
<ul class="genre-list">
|
||||
<?php foreach($genres as $genre): ?>
|
||||
<li><?php echo htmlspecialchars($genre->name, ENT_QUOTES, 'UTF-8'); ?></li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php if (!empty($genres)): ?>
|
||||
<div class="section">
|
||||
<h3 class="section-title">Genres</h3>
|
||||
<ul class="genre-list">
|
||||
<?php foreach ($genres as $genre): ?>
|
||||
<li>
|
||||
<a href="<?php echo site_url('albums?genre_id=' . htmlspecialchars($genre->id, ENT_QUOTES, 'UTF-8')); ?>">
|
||||
<?php echo htmlspecialchars($genre->name, ENT_QUOTES, 'UTF-8'); ?>
|
||||
</a>
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if (!empty($artistes)): ?>
|
||||
<div class="section">
|
||||
<h3 class="section-title">Artistes</h3>
|
||||
<ul class="artist-list">
|
||||
<?php foreach($artistes as $artiste): ?>
|
||||
<li>
|
||||
<a href="<?php echo site_url('artiste/'.$artiste->id); ?>">
|
||||
<?php echo htmlspecialchars($artiste->name, ENT_QUOTES, 'UTF-8'); ?>
|
||||
</a>
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if (empty($musiques) && empty($albums) && empty($genres) && empty($artistes)): ?>
|
||||
<p class="no-results">Aucun résultat trouvé.</p>
|
||||
<?php endif; ?>
|
||||
<?php if (!empty($artistes)): ?>
|
||||
<div class="section">
|
||||
<h3 class="section-title">Artistes</h3>
|
||||
<ul class="artist-list">
|
||||
<?php foreach ($artistes as $artiste): ?>
|
||||
<li>
|
||||
<a href="<?php echo site_url('artiste/' . htmlspecialchars($artiste->id, ENT_QUOTES, 'UTF-8')); ?>">
|
||||
<?php echo htmlspecialchars($artiste->name, ENT_QUOTES, 'UTF-8'); ?>
|
||||
</a>
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if (empty($musiques) && empty($albums) && empty($genres) && empty($artistes)): ?>
|
||||
<p class="no-results">Aucun résultat trouvé.</p>
|
||||
<?php endif; ?>
|
||||
|
||||
</body>
|
||||
|
Reference in New Issue
Block a user