From 6948cc21abc3da2f88ebe66999adb39456e06504 Mon Sep 17 00:00:00 2001 From: stiti Date: Wed, 22 May 2024 22:05:48 +0200 Subject: [PATCH] Ajout de la musique --- .../application/controllers/Artiste.php | 5 +- .../application/controllers/Musiques.php | 24 ++++-- .../application/models/Cover_model.php | 1 - .../application/models/Model_music.php | 73 +++++++++++++++++-- .../application/views/albums_list.php | 2 +- .../application/views/artiste_details.php | 15 +++- .../application/views/musiques_list.php | 50 +++++++++---- CodeIgniter-3.1.13/assets/css/style.css | 1 - 8 files changed, 138 insertions(+), 33 deletions(-) diff --git a/CodeIgniter-3.1.13/application/controllers/Artiste.php b/CodeIgniter-3.1.13/application/controllers/Artiste.php index df2f05c..db8ac72 100644 --- a/CodeIgniter-3.1.13/application/controllers/Artiste.php +++ b/CodeIgniter-3.1.13/application/controllers/Artiste.php @@ -13,7 +13,8 @@ class Artiste extends CI_Controller { public function index($artiste_id){ // Récupérer les détails de l'artiste $artiste = $this->Model_artist->getArtisteById($artiste_id); - + $mostUsedGenre = $this->Model_music->getMostUsedGenreByArtist($artiste_id); // Correction ici + if($artiste){ // Récupérer tous les albums de l'artiste $albums = $this->Model_music->getAlbumsByArtiste($artiste_id); @@ -21,6 +22,7 @@ class Artiste extends CI_Controller { // Charger la vue avec les détails de l'artiste et ses albums $data['artiste'] = $artiste; $data['albums'] = $albums; + $data['mostUsedGenre'] = $mostUsedGenre; // Passer $mostUsedGenre à la vue $this->load->view('layout/header_not_logged_dark'); $this->load->view('artiste_details', $data); $this->load->view('layout/footer_dark'); @@ -29,6 +31,7 @@ class Artiste extends CI_Controller { show_404(); } } + public function list_artists(){ // Récupérer le paramètre de tri (croissant ou decroissant) diff --git a/CodeIgniter-3.1.13/application/controllers/Musiques.php b/CodeIgniter-3.1.13/application/controllers/Musiques.php index f83f222..cff7cff 100644 --- a/CodeIgniter-3.1.13/application/controllers/Musiques.php +++ b/CodeIgniter-3.1.13/application/controllers/Musiques.php @@ -11,17 +11,29 @@ class Musiques extends CI_Controller { } public function index($page = 1){ - $limit = 30; // Nombre de musiques par page + // Nombre de musiques par page + $limit = 30; + // Calcul de l'offset pour la pagination $offset = ($page - 1) * $limit; - $musiques = $this->Model_music->getMusiques($limit, $offset); + // Récupérer la valeur de tri depuis la requête GET + $sort = $this->input->get('sort'); + + // 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 $total_musiques = $this->Model_music->get_total_musiques(); - $data['total_pages'] = ceil($total_musiques / $limit); // Calcul du nombre total de pages - $data['current_page'] = $page; // Définition de la variable $current_page - + // 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 $data['musiques'] = $musiques; + $data['total_pages'] = $total_pages; + $data['current_page'] = $current_page; + $data['sort'] = $sort; // Passer la valeur de tri à la vue // Charger la vue $this->load->view('layout/header_not_logged_dark'); @@ -29,6 +41,4 @@ class Musiques extends CI_Controller { $this->load->view('layout/footer_dark'); } - } -?> diff --git a/CodeIgniter-3.1.13/application/models/Cover_model.php b/CodeIgniter-3.1.13/application/models/Cover_model.php index 07d3d05..58af711 100644 --- a/CodeIgniter-3.1.13/application/models/Cover_model.php +++ b/CodeIgniter-3.1.13/application/models/Cover_model.php @@ -14,4 +14,3 @@ class Cover_model extends CI_Model { return $result->result_array(); } } -?> \ No newline at end of file diff --git a/CodeIgniter-3.1.13/application/models/Model_music.php b/CodeIgniter-3.1.13/application/models/Model_music.php index ec0293e..580b88c 100644 --- a/CodeIgniter-3.1.13/application/models/Model_music.php +++ b/CodeIgniter-3.1.13/application/models/Model_music.php @@ -97,7 +97,23 @@ class Model_music extends CI_Model { return $album; } - public function getMusiques($limit, $offset) { + public function getMusiques($limit, $offset, $order_by = 'title', $order_direction = 'ASC') { + $order_column = ''; + switch ($order_by) { + case 'artist': + $order_column = 'artist.name'; + break; + case 'album': + $order_column = 'album.name'; + break; + case 'title': + $order_column = 'song.name'; + break; + default: + $order_column = 'song.name'; + break; + } + $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 @@ -105,11 +121,12 @@ class Model_music extends CI_Model { 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_total_musiques(){ $query = $this->db->query("SELECT COUNT(*) as total_musiques FROM song"); @@ -119,14 +136,60 @@ class Model_music extends CI_Model { public function getAlbumsByArtiste($artiste_id){ $query = $this->db->query(" - SELECT album.id, album.name, album.year, artist.name as artistName, genre.name as genreName, cover.jpeg + SELECT album.id, album.name, album.year, artist.name as artistName, genre.name as genreName, cover.jpeg, + track.id as track_id, track.diskNumber, track.number, track.duration, song.name as songName FROM album JOIN artist ON album.artistid = artist.id JOIN genre ON album.genreid = genre.id JOIN cover ON album.coverid = cover.id + JOIN track ON track.albumid = album.id + JOIN song ON track.songid = song.id WHERE artist.id = ? + ORDER BY album.id, track.diskNumber, track.number ", array($artiste_id)); - return $query->result(); + $result = $query->result(); + + // Organiser les résultats par album + $albums = array(); + foreach ($result as $row) { + $album_id = $row->id; + if (!isset($albums[$album_id])) { + $albums[$album_id] = (object)array( + 'id' => $row->id, + 'name' => $row->name, + 'year' => $row->year, + 'artistName' => $row->artistName, + 'genreName' => $row->genreName, + 'jpeg' => $row->jpeg, + 'tracks' => array() // Initialiser un tableau pour les pistes de l'album + ); + } + // Ajouter la piste à l'album correspondant + $albums[$album_id]->tracks[] = (object)array( + 'id' => $row->track_id, + 'diskNumber' => $row->diskNumber, + 'number' => $row->number, + 'duration' => $row->duration, + 'songName' => $row->songName + ); + } + + return array_values($albums); // Réorganiser les albums en utilisant des index numériques + } + + + public function getMostUsedGenreByArtist($artist_id) { + $query = $this->db->query(" + SELECT genre.name as genreName, COUNT(*) as genreCount + FROM album + JOIN genre ON album.genreid = genre.id + WHERE album.artistid = ? + GROUP BY genre.name + ORDER BY genreCount DESC + LIMIT 1 + ", array($artist_id)); + + return $query->row(); } + } -?> diff --git a/CodeIgniter-3.1.13/application/views/albums_list.php b/CodeIgniter-3.1.13/application/views/albums_list.php index dfd45c4..f635965 100644 --- a/CodeIgniter-3.1.13/application/views/albums_list.php +++ b/CodeIgniter-3.1.13/application/views/albums_list.php @@ -3,7 +3,7 @@ - + Albums - Onzeur diff --git a/CodeIgniter-3.1.13/application/views/artiste_details.php b/CodeIgniter-3.1.13/application/views/artiste_details.php index 5c6b210..4fbf358 100644 --- a/CodeIgniter-3.1.13/application/views/artiste_details.php +++ b/CodeIgniter-3.1.13/application/views/artiste_details.php @@ -3,13 +3,13 @@ - + Détails de l'artiste <?php echo $artiste->name; ?>

Détails de l'artiste name; ?>

- +

Genre le plus utilisé : genreName; ?>

Albums de name; ?>

diff --git a/CodeIgniter-3.1.13/application/views/musiques_list.php b/CodeIgniter-3.1.13/application/views/musiques_list.php index c473dbc..233b5ab 100644 --- a/CodeIgniter-3.1.13/application/views/musiques_list.php +++ b/CodeIgniter-3.1.13/application/views/musiques_list.php @@ -2,35 +2,55 @@ - - Liste des Musiques - Onzeur + + + Musiques - Onzeur -

Liste des musiques

- + + - diff --git a/CodeIgniter-3.1.13/assets/css/style.css b/CodeIgniter-3.1.13/assets/css/style.css index b53c19e..7bc1ff3 100644 --- a/CodeIgniter-3.1.13/assets/css/style.css +++ b/CodeIgniter-3.1.13/assets/css/style.css @@ -62,7 +62,6 @@ footer.short-text { /* Styles pour les liens hypertexte */ header.short-text a { color: #fff; /* Blanc pour les liens */ - text-decoration: none; /* Supprimer le soulignement */ } /* Image styles */