mirror of
https://grond.iut-fbleau.fr/stiti/SAE_2.02
synced 2024-12-27 01:12:18 +01:00
Réparation de la recherche
This commit is contained in:
parent
e390e7b393
commit
6f6d5ecacb
@ -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.
|
| 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(){
|
public function __construct(){
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
$this->load->model('Search_model');
|
$this->load->model('Search_model');
|
||||||
$this->load->helper('url');
|
$this->load->helper(['url', 'html']);
|
||||||
$this->load->helper('html');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function index(){
|
public function index(){
|
||||||
// Récupérer la requête de recherche depuis la barre de recherche
|
|
||||||
$query = $this->input->get('query');
|
$query = $this->input->get('query');
|
||||||
|
|
||||||
// Vérifier que la requête de recherche n'est pas vide
|
|
||||||
if (empty($query)) {
|
if (empty($query)) {
|
||||||
// Charger la vue avec un message d'erreur
|
|
||||||
$data['query'] = $query;
|
$data['query'] = $query;
|
||||||
$data['musiques'] = [];
|
$data['musiques'] = [];
|
||||||
$data['albums'] = [];
|
$data['albums'] = [];
|
||||||
@ -24,33 +20,32 @@ class Search extends CI_Controller {
|
|||||||
$data['artistes'] = [];
|
$data['artistes'] = [];
|
||||||
$data['error'] = "La requête de recherche ne peut pas être vide.";
|
$data['error'] = "La requête de recherche ne peut pas être vide.";
|
||||||
|
|
||||||
$data['title']="Résultats de la recherche";
|
$data['title'] = "Résultats de la recherche";
|
||||||
$data['css']="assets/css/search_results";
|
$data['css'] = "assets/css/search_results";
|
||||||
|
|
||||||
$this->load->view('layout/header_dark', $data);
|
$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');
|
$this->load->view('layout/footer_dark');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Faire une recherche dans les musiques, les albums, les genres et les artistes
|
|
||||||
$musiques = $this->Search_model->searchMusiques($query);
|
$musiques = $this->Search_model->searchMusiques($query);
|
||||||
$albums = $this->Search_model->searchAlbums($query);
|
$albums = $this->Search_model->searchAlbums($query);
|
||||||
$genres = $this->Search_model->searchGenres($query);
|
$genres = $this->Search_model->searchGenres($query);
|
||||||
$artistes = $this->Search_model->searchArtistes($query);
|
$artistes = $this->Search_model->searchArtistes($query);
|
||||||
|
|
||||||
// Charger la vue avec les résultats de la recherche
|
|
||||||
$data['query'] = $query;
|
$data['query'] = $query;
|
||||||
$data['musiques'] = $musiques;
|
$data['musiques'] = $musiques;
|
||||||
$data['albums'] = $albums;
|
$data['albums'] = $albums;
|
||||||
$data['genres'] = $genres;
|
$data['genres'] = $genres;
|
||||||
$data['artistes'] = $artistes;
|
$data['artistes'] = $artistes;
|
||||||
|
|
||||||
$data['title']="Résultats de la recherche";
|
$data['title'] = "Résultats de la recherche";
|
||||||
$data['css']="assets/css/search_results";
|
$data['css'] = "assets/css/search_results";
|
||||||
|
|
||||||
$this->load->view('layout/header_dark', $data);
|
$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');
|
$this->load->view('layout/footer_dark');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
?>
|
||||||
|
@ -22,7 +22,7 @@ class Search_model extends CI_Model {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function searchAlbums($query){
|
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
|
FROM album
|
||||||
JOIN artist ON album.artistid = artist.id
|
JOIN artist ON album.artistid = artist.id
|
||||||
JOIN genre ON album.genreid = genre.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 . '%'));
|
$query = $this->db->query($sql, array('%' . $query . '%'));
|
||||||
return $query->result();
|
return $query->result();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function searchGenres($query){
|
public function searchGenres($query){
|
||||||
$sql = "SELECT id, name FROM genre WHERE name LIKE ? ORDER BY name ASC";
|
$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();
|
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)): ?>
|
<?php if (!empty($error)): ?>
|
||||||
<p class="error-message"><?php echo $error; ?></p>
|
<p class="error-message"><?php echo htmlspecialchars($error, ENT_QUOTES, 'UTF-8'); ?></p>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
|
||||||
<?php if (!empty($musiques)): ?>
|
<?php if (!empty($musiques)): ?>
|
||||||
<div class="section">
|
<div class="section">
|
||||||
<h3 class="section-title">Musiques</h3>
|
<h3 class="section-title">Musiques</h3>
|
||||||
<ul class="music-list">
|
<ul class="music-list">
|
||||||
<?php foreach($musiques as $musique): ?>
|
<?php foreach ($musiques as $musique): ?>
|
||||||
<li>
|
<li>
|
||||||
<?php echo htmlspecialchars($musique->name, ENT_QUOTES, 'UTF-8'); ?> -
|
<?php echo htmlspecialchars($musique->name, ENT_QUOTES, 'UTF-8'); ?> -
|
||||||
<a href="<?php echo site_url('artiste/'.$musique->artist_id); ?>">
|
<a href="<?php echo site_url('artiste/' . htmlspecialchars($musique->artist_id, ENT_QUOTES, 'UTF-8')); ?>">
|
||||||
<?php echo htmlspecialchars($musique->artistName, ENT_QUOTES, 'UTF-8'); ?>
|
<?php echo htmlspecialchars($musique->artistName, ENT_QUOTES, 'UTF-8'); ?>
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
|
||||||
<?php if (!empty($albums)): ?>
|
<?php if (!empty($albums)): ?>
|
||||||
<div class="section">
|
<div class="section">
|
||||||
<h3 class="section-title">Albums</h3>
|
<h3 class="section-title">Albums</h3>
|
||||||
<ul class="album-list">
|
<ul class="album-list">
|
||||||
<?php foreach($albums as $album): ?>
|
<?php foreach ($albums as $album): ?>
|
||||||
<li>
|
<li>
|
||||||
<a href="<?php echo site_url('albums/view/'.$album->id); ?>">
|
<a href="<?php echo site_url('albums/view/' . htmlspecialchars($album->id, ENT_QUOTES, 'UTF-8')); ?>">
|
||||||
<?php echo htmlspecialchars($album->name, ENT_QUOTES, 'UTF-8'); ?>
|
<?php echo htmlspecialchars($album->name, ENT_QUOTES, 'UTF-8'); ?>
|
||||||
</a>
|
</a> -
|
||||||
-
|
<a href="<?php echo site_url('artiste/' . htmlspecialchars($album->artist_id, ENT_QUOTES, 'UTF-8')); ?>">
|
||||||
<a href="<?php echo site_url('artiste/'.$musique->artist_id); ?>">
|
<?php echo htmlspecialchars($album->artistName, ENT_QUOTES, 'UTF-8'); ?>
|
||||||
<?php echo htmlspecialchars($musique->artistName, ENT_QUOTES, 'UTF-8'); ?>
|
</a>
|
||||||
</a>
|
</li>
|
||||||
</li>
|
<?php endforeach; ?>
|
||||||
<?php endforeach; ?>
|
</ul>
|
||||||
</ul>
|
</div>
|
||||||
</div>
|
<?php endif; ?>
|
||||||
<?php endif; ?>
|
|
||||||
|
|
||||||
<?php if (!empty($genres)): ?>
|
<?php if (!empty($genres)): ?>
|
||||||
<div class="section">
|
<div class="section">
|
||||||
<h3 class="section-title">Genres</h3>
|
<h3 class="section-title">Genres</h3>
|
||||||
<ul class="genre-list">
|
<ul class="genre-list">
|
||||||
<?php foreach($genres as $genre): ?>
|
<?php foreach ($genres as $genre): ?>
|
||||||
<li><?php echo htmlspecialchars($genre->name, ENT_QUOTES, 'UTF-8'); ?></li>
|
<li>
|
||||||
<?php endforeach; ?>
|
<a href="<?php echo site_url('albums?genre_id=' . htmlspecialchars($genre->id, ENT_QUOTES, 'UTF-8')); ?>">
|
||||||
</ul>
|
<?php echo htmlspecialchars($genre->name, ENT_QUOTES, 'UTF-8'); ?>
|
||||||
</div>
|
</a>
|
||||||
<?php endif; ?>
|
</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)): ?>
|
<?php if (!empty($artistes)): ?>
|
||||||
<p class="no-results">Aucun résultat trouvé.</p>
|
<div class="section">
|
||||||
<?php endif; ?>
|
<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>
|
</body>
|
||||||
|
@ -5,60 +5,147 @@ body {
|
|||||||
background-color: #f8f8f8;
|
background-color: #f8f8f8;
|
||||||
}
|
}
|
||||||
|
|
||||||
.search-title {
|
.container {
|
||||||
color: #6a0dad;
|
max-width: 1200px;
|
||||||
|
margin: 0 auto;
|
||||||
|
padding: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.title {
|
||||||
|
color: #6a0dad;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
margin-top: 20px;
|
margin-top: 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.error-message {
|
|
||||||
color: red;
|
|
||||||
margin-top: 5px;
|
|
||||||
font-size: 25px;
|
|
||||||
text-align: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
.section {
|
.section {
|
||||||
margin-bottom: 30px;
|
margin-bottom: 40px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.section-title {
|
.section-title {
|
||||||
color: #6a0dad;
|
color: #6a0dad;
|
||||||
font-size: 1.5em;
|
font-size: 1.8em;
|
||||||
|
border-bottom: 2px solid #6a0dad;
|
||||||
|
padding-bottom: 10px;
|
||||||
|
margin-bottom: 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
ul {
|
.music-list, .album-list, .genre-list, .artist-list {
|
||||||
|
list-style-type: none;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
ul li {
|
.music-list li, .album-list li, .genre-list li, .artist-list li {
|
||||||
|
background-color: #fff;
|
||||||
|
border-radius: 8px;
|
||||||
|
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
||||||
margin-bottom: 10px;
|
margin-bottom: 10px;
|
||||||
|
padding: 15px;
|
||||||
|
transition: transform 0.3s ease;
|
||||||
}
|
}
|
||||||
|
|
||||||
ul li a {
|
.music-list li:hover, .album-list li:hover, .genre-list li:hover, .artist-list li:hover {
|
||||||
|
transform: translateY(-5px);
|
||||||
|
}
|
||||||
|
|
||||||
|
.music-list li a, .album-list li a, .artist-list li a, .genre-list li a {
|
||||||
color: #6a0dad;
|
color: #6a0dad;
|
||||||
text-decoration: none;
|
|
||||||
transition: color 0.3s ease;
|
transition: color 0.3s ease;
|
||||||
}
|
}
|
||||||
|
|
||||||
ul li a:hover {
|
.music-list li a:hover, .album-list li a:hover, .artist-list li a:hover, .genre-list li a:hover {
|
||||||
color: #4a0772;
|
color: #4a0772;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.error-message {
|
||||||
|
color: red;
|
||||||
|
text-align: center;
|
||||||
|
margin: 20px 0;
|
||||||
|
}
|
||||||
|
|
||||||
.no-results {
|
.no-results {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
color: #777; /* Grey */
|
font-size: 1.2em;
|
||||||
|
color: #888;
|
||||||
|
}
|
||||||
|
|
||||||
|
.music-links {
|
||||||
|
margin-top: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.music-links a {
|
||||||
|
display: inline-block;
|
||||||
|
margin-right: 10px;
|
||||||
|
padding: 5px 10px;
|
||||||
|
border-radius: 5px;
|
||||||
|
color: #fff;
|
||||||
|
text-decoration: none;
|
||||||
|
transition: background-color 0.3s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.music-links a.spotify {
|
||||||
|
background-color: #1DB954;
|
||||||
|
}
|
||||||
|
|
||||||
|
.music-links a.deezer {
|
||||||
|
background-color: #6E44FF;
|
||||||
|
}
|
||||||
|
|
||||||
|
.music-links a.youtube {
|
||||||
|
background-color: #FF0000;
|
||||||
|
}
|
||||||
|
|
||||||
|
.music-links a.spotify:hover, .music-links a.deezer:hover, .music-links a.youtube:hover {
|
||||||
|
color: black;
|
||||||
|
background-color: rgba(255, 255, 255, 0.8);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Responsive styles */
|
|
||||||
@media screen and (max-width: 768px) {
|
@media screen and (max-width: 768px) {
|
||||||
ul li {
|
.music-list li, .album-list li, .genre-list li, .artist-list li {
|
||||||
width: 45%;
|
width: 45%;
|
||||||
|
margin: 10px 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@media screen and (max-width: 576px) {
|
@media screen and (max-width: 576px) {
|
||||||
ul li {
|
.music-list li, .album-list li, .genre-list li, .artist-list li {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.filters button {
|
||||||
|
background-color: #8c00ff;
|
||||||
|
color: #fff;
|
||||||
|
border: none;
|
||||||
|
padding: 8px 16px;
|
||||||
|
border-radius: 4px;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.filters button:hover {
|
||||||
|
background-color: #6a0080;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pagination {
|
||||||
|
text-align: center;
|
||||||
|
margin-top: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pagination a {
|
||||||
|
display: inline-block;
|
||||||
|
padding: 8px 16px;
|
||||||
|
margin: 0 4px;
|
||||||
|
background-color: #6a0dad;
|
||||||
|
color: #fff;
|
||||||
|
border-radius: 4px;
|
||||||
|
text-decoration: none;
|
||||||
|
transition: background-color 0.3s ease;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pagination a:hover {
|
||||||
|
background-color: #4a0772;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pagination .active {
|
||||||
|
background-color: #29043e;
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user