test filtre 2/?
This commit is contained in:
parent
ea2e857196
commit
4b5b72f2c0
application
@ -9,13 +9,14 @@ class Albums extends CI_Controller {
|
||||
$this->load->library('session');
|
||||
}
|
||||
|
||||
|
||||
public function index(){
|
||||
$genre = $this->input->get('genre');
|
||||
$order = $this->input->get('order');
|
||||
$genre = $this->input->get('genre');
|
||||
$artist = $this->input->get('artist');
|
||||
$query = $this->input->get('query');
|
||||
|
||||
$albums = $this->model_music->getAlbums($genre, $order, $artist);
|
||||
|
||||
$genres = $this->model_music->researchtype();
|
||||
$artists = $this->model_music->nameArtist();
|
||||
|
||||
@ -26,11 +27,10 @@ class Albums extends CI_Controller {
|
||||
'genres' => $genres,
|
||||
'artistes' => $artists
|
||||
);
|
||||
|
||||
$this->load->view('layout/header', $data);
|
||||
$this->load->view('layout/getter', $data);
|
||||
$this->load->view('albums_list', $data);
|
||||
$this->load->view('layout/footer');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -5,14 +5,13 @@ class Model_music extends CI_Model {
|
||||
$this->load->database();
|
||||
}
|
||||
|
||||
public function getAlbums($genre = '', $order = '', $artist = '') {
|
||||
public function getAlbums($genre = '', $order = 'asc', $artist = '') {
|
||||
$this->db->select('album.name, album.id, year, artist.name as artistName, genre.name as genreName, jpeg');
|
||||
$this->db->from('album');
|
||||
$this->db->join('artist', 'album.artistid = artist.id');
|
||||
$this->db->join('genre', 'genre.id = album.genreid');
|
||||
$this->db->join('cover', 'cover.id = album.coverid');
|
||||
|
||||
|
||||
if(!empty($genre)){
|
||||
$this->db->where('genre.name', $genre);
|
||||
}
|
||||
@ -21,13 +20,24 @@ class Model_music extends CI_Model {
|
||||
$this->db->where('artist.name', $artist);
|
||||
}
|
||||
|
||||
|
||||
|
||||
if($order == 'asc' || $order == 'desc'){
|
||||
$this->db->order_by('album.name', $order);
|
||||
}
|
||||
|
||||
$query = $this->db->get();
|
||||
return $query->result();
|
||||
}
|
||||
|
||||
public function researchtype(){
|
||||
$this->db->select('name');
|
||||
$this->db->from('genre');
|
||||
$query = $this->db->get();
|
||||
return $query->result();
|
||||
}
|
||||
|
||||
public function nameArtist(){
|
||||
$this->db->select('name');
|
||||
$this->db->from('artist');
|
||||
$query = $this->db->get();
|
||||
return $query->result();
|
||||
}
|
||||
|
@ -1,35 +1,44 @@
|
||||
<button onclick="toggleFilters()">Filtrer</button>
|
||||
|
||||
<div id="filters" style="display: none;">
|
||||
<div>
|
||||
<!-- Champ de recherche -->
|
||||
<form method="GET" action="">
|
||||
<input type="text" name="query" placeholder="Rechercher..." value="<?= isset($_GET['query']) ? $_GET['query'] : '' ?>">
|
||||
<button type="submit">Rechercher</button>
|
||||
</form>
|
||||
|
||||
<!-- Bouton pour afficher/masquer les filtres -->
|
||||
<button type="button" onclick="toggleFilters()">Filtrer</button>
|
||||
|
||||
<!-- Div contenant les filtres, cachée par défaut -->
|
||||
<div id="filters" style="display: none;">
|
||||
<form method="GET" action="">
|
||||
<select name="artist" id="artist" onchange="submitForm()>
|
||||
<!-- Filtre par artiste -->
|
||||
<select name="artist" id="artist" onchange="this.form.submit()">
|
||||
<option value=''>Tous</option>
|
||||
<?php foreach($artistes as $artiste): ?>
|
||||
<option value="<?= $artiste->name ?>" <?= isset($_GET['artist']) && $_GET['artist'] == $artiste->name ? 'selected' : '' ?>><?= $artiste->name ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
|
||||
<select name="genre" id="genre" onchange="submitForm()>
|
||||
<!-- Filtre par genre -->
|
||||
<select name="genre" id="genre" onchange="this.form.submit()">
|
||||
<option value=''>Tous</option>
|
||||
<?php foreach($genres as $genre): ?>
|
||||
<option value="<?= $genre->name ?>" <?= isset($_GET['genre']) && $_GET['genre'] == $genre->name ? 'selected' : '' ?>><?= $genre->name ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
|
||||
<select name="order" id="order" onchange="submitForm()">
|
||||
<!-- Filtre par ordre -->
|
||||
<select name="order" id="order" onchange="this.form.submit()">
|
||||
<option value="">Ordre :</option>
|
||||
<option value="asc" <?= isset($_GET['order']) && $_GET['order'] == 'asc' ? 'selected' : '' ?>>Croissant</option>
|
||||
<option value="desc" <?= isset($_GET['order']) && $_GET['order'] == 'desc' ? 'selected' : '' ?>>Decroissant</option>
|
||||
<option value="desc" <?= isset($_GET['order']) && $_GET['order'] == 'desc' ? 'selected' : '' ?>>Décroissant</option>
|
||||
</select>
|
||||
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// Fonction pour afficher/masquer les filtres
|
||||
function toggleFilters() {
|
||||
var filters = document.getElementById('filters');
|
||||
if (filters.style.display === 'none') {
|
||||
@ -38,8 +47,4 @@
|
||||
filters.style.display = 'none';
|
||||
}
|
||||
}
|
||||
|
||||
function submitForm() {
|
||||
document.getElementById('filters').submit();
|
||||
}
|
||||
</script>
|
Loading…
x
Reference in New Issue
Block a user