From 4e02203e845aac33baafa158794ec317183685f2 Mon Sep 17 00:00:00 2001 From: stiti Date: Mon, 20 May 2024 22:42:38 +0200 Subject: [PATCH] Commit de Louay : Correction de bug --- .../application/config/routes.php | 1 + .../application/controllers/Artiste.php | 22 +++++++-- .../application/controllers/Musiques.php | 5 +- .../application/models/Model_artist.php | 15 ++++++ .../application/models/Model_music.php | 17 ++++++- .../application/views/album_view.php | 1 + .../application/views/albums_list.php | 2 +- .../application/views/artiste_details.php | 32 +++++++++++++ .../views/layout/header_not_logged_dark.php | 2 +- .../application/views/musiques_list.php | 2 +- .../assets/css/artiste_details.css | 47 +++++++++++++++++++ 11 files changed, 135 insertions(+), 11 deletions(-) create mode 100644 CodeIgniter-3.1.13/application/models/Model_artist.php create mode 100644 CodeIgniter-3.1.13/application/views/artiste_details.php create mode 100644 CodeIgniter-3.1.13/assets/css/artiste_details.css diff --git a/CodeIgniter-3.1.13/application/config/routes.php b/CodeIgniter-3.1.13/application/config/routes.php index 2f107b9..db535f9 100644 --- a/CodeIgniter-3.1.13/application/config/routes.php +++ b/CodeIgniter-3.1.13/application/config/routes.php @@ -54,5 +54,6 @@ $route['404_override'] = ''; $route['translate_uri_dashes'] = FALSE; $route['albums'] = 'albums/index'; $route['musiques'] = 'Musiques/index'; +$route['artiste/(:num)'] = 'artiste/index/$1'; diff --git a/CodeIgniter-3.1.13/application/controllers/Artiste.php b/CodeIgniter-3.1.13/application/controllers/Artiste.php index cf6af3c..cc3d899 100644 --- a/CodeIgniter-3.1.13/application/controllers/Artiste.php +++ b/CodeIgniter-3.1.13/application/controllers/Artiste.php @@ -5,28 +5,40 @@ class Artiste extends CI_Controller { public function __construct(){ parent::__construct(); - $this->load->model('Model_music'); + $this->load->model('Model_artist'); + $this->load->model('Model_music'); // Chargez également le modèle Model_music si vous en avez besoin $this->load->helper('url'); } public function index($artiste_id){ // Récupérer les détails de l'artiste - $artiste = $this->Model_music->getArtisteById($artiste_id); + $artiste = $this->Model_artist->getArtisteById($artiste_id); if($artiste){ // Récupérer tous les albums de l'artiste - $albums = $this->Model_music->getAlbumsByArtiste($artiste_id); + $albums = $this->Model_music->getAlbumsByArtiste($artiste_id); // Utilisez le modèle Model_music ici // Charger la vue avec les détails de l'artiste et ses albums $data['artiste'] = $artiste; $data['albums'] = $albums; $this->load->view('layout/header_not_logged_dark'); - $this->load->view('artiste_details', $data); // Créez cette vue + $this->load->view('artiste_details', $data); $this->load->view('layout/footer_dark'); } else { // Gérer le cas où l'artiste n'est pas trouvé - show_404(); // Affiche une page d'erreur 404 + show_404(); } } + + public function list_artists(){ + // Récupérer la liste des artistes + $artists = $this->Model_artist->getArtists(); + + // Charger la vue avec la liste des artistes + $data['artists'] = $artists; + $this->load->view('layout/header_not_logged_dark'); + $this->load->view('artists_list', $data); + $this->load->view('layout/footer_dark'); + } } ?> diff --git a/CodeIgniter-3.1.13/application/controllers/Musiques.php b/CodeIgniter-3.1.13/application/controllers/Musiques.php index 1074d0e..f83f222 100644 --- a/CodeIgniter-3.1.13/application/controllers/Musiques.php +++ b/CodeIgniter-3.1.13/application/controllers/Musiques.php @@ -11,7 +11,7 @@ class Musiques extends CI_Controller { } public function index($page = 1){ - $limit = 100; // Nombre de musiques par page + $limit = 30; // Nombre de musiques par page $offset = ($page - 1) * $limit; $musiques = $this->Model_music->getMusiques($limit, $offset); @@ -22,12 +22,13 @@ class Musiques extends CI_Controller { // Données à passer à la vue $data['musiques'] = $musiques; - + // Charger la vue $this->load->view('layout/header_not_logged_dark'); $this->load->view('musiques_list', $data); $this->load->view('layout/footer_dark'); } + } ?> diff --git a/CodeIgniter-3.1.13/application/models/Model_artist.php b/CodeIgniter-3.1.13/application/models/Model_artist.php new file mode 100644 index 0000000..78d2887 --- /dev/null +++ b/CodeIgniter-3.1.13/application/models/Model_artist.php @@ -0,0 +1,15 @@ +load->database(); + } + + public function getArtisteById($artiste_id){ + $query = $this->db->query("SELECT * FROM artist WHERE id = ?", array($artiste_id)); + return $query->row(); + } + +} +?> diff --git a/CodeIgniter-3.1.13/application/models/Model_music.php b/CodeIgniter-3.1.13/application/models/Model_music.php index b3b690d..30a05f9 100644 --- a/CodeIgniter-3.1.13/application/models/Model_music.php +++ b/CodeIgniter-3.1.13/application/models/Model_music.php @@ -53,7 +53,7 @@ class Model_music extends CI_Model { public function getMusiques($limit, $offset) { $query = $this->db->query( - "SELECT song.id, song.name, artist.name as artistName, album.name as album_name, track.albumid as album_id, cover.jpeg as cover + "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 @@ -64,11 +64,26 @@ class Model_music extends CI_Model { return $query->result(); } + public function get_total_musiques(){ $query = $this->db->query("SELECT COUNT(*) as total_musiques FROM song"); $result = $query->row(); return $result->total_musiques; } + 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 + FROM album + JOIN artist ON album.artistid = artist.id + JOIN genre ON album.genreid = genre.id + JOIN cover ON album.coverid = cover.id + WHERE artist.id = ? + ", array($artiste_id)); + return $query->result(); + } + + + } ?> diff --git a/CodeIgniter-3.1.13/application/views/album_view.php b/CodeIgniter-3.1.13/application/views/album_view.php index bf52b86..710de81 100644 --- a/CodeIgniter-3.1.13/application/views/album_view.php +++ b/CodeIgniter-3.1.13/application/views/album_view.php @@ -10,6 +10,7 @@

name; ?>

+

Artiste : artistName; ?>

Année : year; ?>

Genre : genreName; ?>

diff --git a/CodeIgniter-3.1.13/application/views/albums_list.php b/CodeIgniter-3.1.13/application/views/albums_list.php index 4f8a75a..99bfae7 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 new file mode 100644 index 0000000..5c6b210 --- /dev/null +++ b/CodeIgniter-3.1.13/application/views/artiste_details.php @@ -0,0 +1,32 @@ + + + + + + + Détails de l'artiste <?php echo $artiste->name; ?> + + +
+

Détails de l'artiste name; ?>

+ +

Albums de name; ?>

+
    + +
  • +
    +

    name; ?>

    +

    Année : year; ?>

    +

    Genre : genreName; ?>

    + jpeg)): ?> + Couverture de l'album + + Aucune couverture disponible + +
    +
  • + +
+
+ + diff --git a/CodeIgniter-3.1.13/application/views/layout/header_not_logged_dark.php b/CodeIgniter-3.1.13/application/views/layout/header_not_logged_dark.php index 41d88fd..5f8cf6d 100644 --- a/CodeIgniter-3.1.13/application/views/layout/header_not_logged_dark.php +++ b/CodeIgniter-3.1.13/application/views/layout/header_not_logged_dark.php @@ -17,7 +17,7 @@