mirror of
https://grond.iut-fbleau.fr/stiti/SAE_2.02
synced 2024-12-27 17:22:17 +01:00
Modifications des tris dans musique
This commit is contained in:
parent
6f6d5ecacb
commit
a00bb1852e
@ -12,36 +12,39 @@ class Musiques extends CI_Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function index($page = 1){
|
public function index($page = 1){
|
||||||
// Nombre de musiques par page
|
$this->load->model('Model_music');
|
||||||
|
$this->load->library('pagination');
|
||||||
|
$this->load->helper('url');
|
||||||
|
$this->load->helper('html');
|
||||||
|
|
||||||
$limit = 30;
|
$limit = 30;
|
||||||
// Calcul de l'offset pour la pagination
|
|
||||||
$offset = ($page - 1) * $limit;
|
$offset = ($page - 1) * $limit;
|
||||||
|
|
||||||
// Récupérer la valeur de tri depuis la requête GET
|
|
||||||
$sort = $this->input->get('sort');
|
$sort = $this->input->get('sort');
|
||||||
|
$genre_id = $this->input->get('genre_id');
|
||||||
|
$artist_id = $this->input->get('artist_id');
|
||||||
|
|
||||||
// Récupérer les musiques triées
|
$musiques = $this->Model_music->getMusiques($limit, $offset, $sort, 'ASC', $genre_id, $artist_id);
|
||||||
$musiques = $this->Model_music->getMusiques($limit, $offset, $sort);
|
|
||||||
|
|
||||||
// Récupérer le nombre total de musiques pour la pagination
|
|
||||||
$total_musiques = $this->Model_music->get_total_musiques();
|
$total_musiques = $this->Model_music->get_total_musiques();
|
||||||
// Calculer le nombre total de pages
|
|
||||||
$total_pages = ceil($total_musiques / $limit);
|
$total_pages = ceil($total_musiques / $limit);
|
||||||
// Définition de la variable $current_page
|
|
||||||
$current_page = $page;
|
|
||||||
|
|
||||||
// Données à passer à la vue
|
$current_page = $page;
|
||||||
|
$genres = $this->Model_music->getGenres();
|
||||||
|
$artists = $this->Model_music->getArtists();
|
||||||
|
|
||||||
$data['musiques'] = $musiques;
|
$data['musiques'] = $musiques;
|
||||||
$data['total_pages'] = $total_pages;
|
$data['total_pages'] = $total_pages;
|
||||||
$data['current_page'] = $current_page;
|
$data['current_page'] = $current_page;
|
||||||
$data['sort'] = $sort; // Passer la valeur de tri à la vue
|
$data['sort'] = $sort;
|
||||||
|
$data['genres'] = $genres;
|
||||||
|
$data['artists'] = $artists;
|
||||||
|
$data['genre_id'] = $genre_id;
|
||||||
|
$data['artist_id'] = $artist_id;
|
||||||
|
|
||||||
$data['title']="Musiques - Onzeur";
|
$data['title'] = "Musiques - Onzeur";
|
||||||
$data['css']="assets/css/musiques_list";
|
$data['css'] = "assets/css/musiques_list";
|
||||||
|
|
||||||
// Charger la vue
|
|
||||||
$this->load->view('layout/header_dark', $data);
|
$this->load->view('layout/header_dark', $data);
|
||||||
$this->load->view('musiques_list',$data);
|
$this->load->view('musiques_list', $data);
|
||||||
$this->load->view('layout/footer_dark');
|
$this->load->view('layout/footer_dark');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,8 +83,6 @@ class Playlists extends CI_Controller {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public function update($playlist_id) {
|
public function update($playlist_id) {
|
||||||
// Vérifier si l'utilisateur est connecté
|
// Vérifier si l'utilisateur est connecté
|
||||||
$this->verify_playlist_ownership($playlist_id);
|
$this->verify_playlist_ownership($playlist_id);
|
||||||
@ -113,7 +111,6 @@ class Playlists extends CI_Controller {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function add_song($playlist_id) {
|
public function add_song($playlist_id) {
|
||||||
$this->verify_playlist_ownership($playlist_id);
|
$this->verify_playlist_ownership($playlist_id);
|
||||||
|
|
||||||
@ -143,7 +140,6 @@ class Playlists extends CI_Controller {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function delete($playlist_id) {
|
public function delete($playlist_id) {
|
||||||
$this->verify_playlist_ownership($playlist_id);
|
$this->verify_playlist_ownership($playlist_id);
|
||||||
|
|
||||||
|
@ -101,7 +101,8 @@ class Model_music extends CI_Model {
|
|||||||
return $album;
|
return $album;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getMusiques($limit, $offset, $order_by = 'title', $order_direction = 'ASC') {
|
public function getMusiques($limit, $offset, $order_by = 'name', $order_direction = 'ASC', $genre_id = null, $artist_id = null) {
|
||||||
|
// Préparer la colonne de tri en fonction du paramètre $order_by
|
||||||
$order_column = '';
|
$order_column = '';
|
||||||
switch ($order_by) {
|
switch ($order_by) {
|
||||||
case 'artist':
|
case 'artist':
|
||||||
@ -110,28 +111,47 @@ class Model_music extends CI_Model {
|
|||||||
case 'album':
|
case 'album':
|
||||||
$order_column = 'album.name';
|
$order_column = 'album.name';
|
||||||
break;
|
break;
|
||||||
case 'title':
|
case 'year':
|
||||||
$order_column = 'song.name';
|
$order_column = 'album.year';
|
||||||
break;
|
break;
|
||||||
|
case 'name':
|
||||||
default:
|
default:
|
||||||
$order_column = 'song.name';
|
$order_column = 'song.name';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
$query = $this->db->query(
|
// Préparer la clause WHERE pour le genre et l'artiste, si nécessaire
|
||||||
"SELECT song.id, song.name, artist.id as artist_id, artist.name as artistName, album.name as album_name, track.albumid as album_id, cover.jpeg as cover
|
$where_clause = '';
|
||||||
FROM song
|
$params = array();
|
||||||
JOIN track ON song.id = track.songid
|
if ($genre_id) {
|
||||||
JOIN album ON track.albumid = album.id
|
$where_clause .= " WHERE genre.id = ?";
|
||||||
JOIN artist ON album.artistid = artist.id
|
$params[] = $genre_id;
|
||||||
JOIN cover ON album.coverid = cover.id
|
}
|
||||||
ORDER BY $order_column $order_direction
|
if ($artist_id) {
|
||||||
LIMIT $limit OFFSET $offset"
|
$where_clause .= ($where_clause == '') ? ' WHERE' : ' AND';
|
||||||
);
|
$where_clause .= " artist.id = ?";
|
||||||
|
$params[] = $artist_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exécuter la requête avec la clause WHERE et l'ordre de tri spécifié
|
||||||
|
$query = $this->db->query("
|
||||||
|
SELECT song.id, song.name, artist.id as artist_id, artist.name as artistName, album.name as album_name, track.albumid as album_id, cover.jpeg as cover
|
||||||
|
FROM song
|
||||||
|
JOIN track ON song.id = track.songid
|
||||||
|
JOIN album ON track.albumid = album.id
|
||||||
|
JOIN artist ON album.artistid = artist.id
|
||||||
|
JOIN cover ON album.coverid = cover.id
|
||||||
|
JOIN genre ON album.genreid = genre.id
|
||||||
|
$where_clause
|
||||||
|
ORDER BY $order_column $order_direction
|
||||||
|
LIMIT $limit OFFSET $offset
|
||||||
|
", $params);
|
||||||
|
|
||||||
return $query->result();
|
return $query->result();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public function get_all_songs() {
|
public function get_all_songs() {
|
||||||
return $this->db->get('song')->result();
|
return $this->db->get('song')->result();
|
||||||
}
|
}
|
||||||
|
@ -2,17 +2,33 @@
|
|||||||
|
|
||||||
<div class="filters">
|
<div class="filters">
|
||||||
<form method="GET" action="<?php echo base_url('index.php/musiques/index'); ?>">
|
<form method="GET" action="<?php echo base_url('index.php/musiques/index'); ?>">
|
||||||
|
<label for="genre">Genre:</label>
|
||||||
|
<select name="genre_id" id="genre">
|
||||||
|
<option value="">Tous les genres</option>
|
||||||
|
<?php foreach($genres as $genre): ?>
|
||||||
|
<option value="<?php echo $genre->id; ?>" <?php echo ($genre->id == $genre_id) ? 'selected' : ''; ?>><?php echo $genre->name; ?></option>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<label for="artist">Artiste:</label>
|
||||||
|
<select name="artist_id" id="artist">
|
||||||
|
<option value="">Tous les artistes</option>
|
||||||
|
<?php foreach($artists as $artist): ?>
|
||||||
|
<option value="<?php echo $artist->id; ?>" <?php echo ($artist->id == $artist_id) ? 'selected' : ''; ?>><?php echo $artist->name; ?></option>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</select>
|
||||||
|
|
||||||
<label for="sort">Trier par:</label>
|
<label for="sort">Trier par:</label>
|
||||||
<select name="sort" id="sort">
|
<select name="sort" id="sort">
|
||||||
<option value="name" <?php echo (isset($sort) && $sort == 'name') ? 'selected' : ''; ?>>Titre</option>
|
<option value="name" <?php echo ($sort == 'name') ? 'selected' : ''; ?>>Nom</option>
|
||||||
<option value="artist" <?php echo (isset($sort) && $sort == 'artist') ? 'selected' : ''; ?>>Artiste</option>
|
<option value="year" <?php echo ($sort == 'year') ? 'selected' : ''; ?>>Année</option>
|
||||||
<option value="album" <?php echo (isset($sort) && $sort == 'album') ? 'selected' : ''; ?>>Album</option>
|
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<button type="submit">Filtrer</button>
|
<button type="submit">Filtrer</button>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<section class="list">
|
<section class="list">
|
||||||
<?php foreach($musiques as $musique): ?>
|
<?php foreach($musiques as $musique): ?>
|
||||||
<div>
|
<div>
|
||||||
|
@ -53,7 +53,6 @@
|
|||||||
</div>
|
</div>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
|
||||||
|
|
||||||
<?php if (!empty($artistes)): ?>
|
<?php if (!empty($artistes)): ?>
|
||||||
<div class="section">
|
<div class="section">
|
||||||
<h3 class="section-title">Artistes</h3>
|
<h3 class="section-title">Artistes</h3>
|
||||||
|
Loading…
Reference in New Issue
Block a user