diff --git a/CodeIgniter-3.1.13/application/controllers/Musiques.php b/CodeIgniter-3.1.13/application/controllers/Musiques.php index 7af2b13..81ee14c 100644 --- a/CodeIgniter-3.1.13/application/controllers/Musiques.php +++ b/CodeIgniter-3.1.13/application/controllers/Musiques.php @@ -12,37 +12,40 @@ class Musiques extends CI_Controller { } public function index($page = 1){ - // Nombre de musiques par page - $limit = 30; - // Calcul de l'offset pour la pagination + $this->load->model('Model_music'); + $this->load->library('pagination'); + $this->load->helper('url'); + $this->load->helper('html'); + + $limit = 30; $offset = ($page - 1) * $limit; - - // Récupérer la valeur de tri depuis la requête GET $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); - - // Récupérer le nombre total de musiques pour la pagination + $musiques = $this->Model_music->getMusiques($limit, $offset, $sort, 'ASC', $genre_id, $artist_id); $total_musiques = $this->Model_music->get_total_musiques(); - // Calculer le nombre total de pages $total_pages = ceil($total_musiques / $limit); - // Définition de la variable $current_page + $current_page = $page; - - // Données à passer à la vue + $genres = $this->Model_music->getGenres(); + $artists = $this->Model_music->getArtists(); + $data['musiques'] = $musiques; $data['total_pages'] = $total_pages; $data['current_page'] = $current_page; - $data['sort'] = $sort; // Passer la valeur de tri à la vue - - $data['title']="Musiques - Onzeur"; - $data['css']="assets/css/musiques_list"; + $data['sort'] = $sort; + $data['genres'] = $genres; + $data['artists'] = $artists; + $data['genre_id'] = $genre_id; + $data['artist_id'] = $artist_id; + + $data['title'] = "Musiques - Onzeur"; + $data['css'] = "assets/css/musiques_list"; - // Charger la vue $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'); - } + } } diff --git a/CodeIgniter-3.1.13/application/controllers/Playlists.php b/CodeIgniter-3.1.13/application/controllers/Playlists.php index 284a7f7..fdb714c 100644 --- a/CodeIgniter-3.1.13/application/controllers/Playlists.php +++ b/CodeIgniter-3.1.13/application/controllers/Playlists.php @@ -83,8 +83,6 @@ class Playlists extends CI_Controller { } } - - public function update($playlist_id) { // Vérifier si l'utilisateur est connecté $this->verify_playlist_ownership($playlist_id); @@ -113,7 +111,6 @@ class Playlists extends CI_Controller { } } - public function add_song($playlist_id) { $this->verify_playlist_ownership($playlist_id); @@ -143,7 +140,6 @@ class Playlists extends CI_Controller { } } - public function delete($playlist_id) { $this->verify_playlist_ownership($playlist_id); diff --git a/CodeIgniter-3.1.13/application/models/Model_music.php b/CodeIgniter-3.1.13/application/models/Model_music.php index 340f98d..9e6cbf9 100644 --- a/CodeIgniter-3.1.13/application/models/Model_music.php +++ b/CodeIgniter-3.1.13/application/models/Model_music.php @@ -101,7 +101,8 @@ class Model_music extends CI_Model { 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 = ''; switch ($order_by) { case 'artist': @@ -110,27 +111,46 @@ class Model_music extends CI_Model { case 'album': $order_column = 'album.name'; break; - case 'title': - $order_column = 'song.name'; + case 'year': + $order_column = 'album.year'; break; + case 'name': default: $order_column = 'song.name'; break; } + + // Préparer la clause WHERE pour le genre et l'artiste, si nécessaire + $where_clause = ''; + $params = array(); + if ($genre_id) { + $where_clause .= " WHERE genre.id = ?"; + $params[] = $genre_id; + } + if ($artist_id) { + $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); - $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 - ORDER BY $order_column $order_direction - LIMIT $limit OFFSET $offset" - ); return $query->result(); } + public function get_all_songs() { return $this->db->get('song')->result(); diff --git a/CodeIgniter-3.1.13/application/views/musiques_list.php b/CodeIgniter-3.1.13/application/views/musiques_list.php index 6db4a6a..ce0c455 100644 --- a/CodeIgniter-3.1.13/application/views/musiques_list.php +++ b/CodeIgniter-3.1.13/application/views/musiques_list.php @@ -2,16 +2,32 @@