From bdec7abeea2082dc91936a2d6e4d93e11a31466e Mon Sep 17 00:00:00 2001 From: Felix-Vimalaratnam Date: Wed, 5 Jun 2024 10:32:50 +0200 Subject: [PATCH] avoir les musique dans album et avoir les album dans artiste --- .../application/controllers/Albums.php | 20 ++++- .../application/models/Model_music.php | 78 +++++++++++++++++-- .../application/views/albums_list.php | 5 +- .../application/views/albums_view.php | 67 ++++++++++++++++ .../application/views/artistes_list.php | 2 +- 5 files changed, 162 insertions(+), 10 deletions(-) create mode 100644 CodeIgniter-3.1.13/application/views/albums_view.php diff --git a/CodeIgniter-3.1.13/application/controllers/Albums.php b/CodeIgniter-3.1.13/application/controllers/Albums.php index b65d6c2..f735525 100644 --- a/CodeIgniter-3.1.13/application/controllers/Albums.php +++ b/CodeIgniter-3.1.13/application/controllers/Albums.php @@ -18,13 +18,29 @@ class Albums extends CI_Controller { } $this->load->view('layout/header'); if ($albums == false){ - $page = preg_split('/[\/]/',$_SERVER['HTTP_REFERER']); - $this->load->view('error',['page'=>$page[count($page)-1]]); + //$page = preg_split('/[\/]/',$_SERVER['HTTP_REFERER']); + //$this->load->view('error',['page'=>$page[count($page)-1]]); $albums = $this->model_music->getAlbums(); } $this->load->view('albums_list',['albums'=>$albums]); $this->load->view('layout/footer'); } + public function viewMusique($id) { + $albums = $this->model_music->getAlbumChoose($id); + if ($albums) { + $this->load->view('layout/header'); + $this->load->view('albums_view', ['albums' => $albums]); + $this->load->view('layout/footer'); + } + } + + public function viewAlbum($Id) { + $albums = $this->model_music->getAlbumsByArtistId($Id); + $this->load->view('layout/header'); + $this->load->view('albums_list', ['albums' => $albums]); + $this->load->view('layout/footer'); + } + } diff --git a/CodeIgniter-3.1.13/application/models/Model_music.php b/CodeIgniter-3.1.13/application/models/Model_music.php index b0aa604..5fcbfc7 100644 --- a/CodeIgniter-3.1.13/application/models/Model_music.php +++ b/CodeIgniter-3.1.13/application/models/Model_music.php @@ -7,7 +7,7 @@ class Model_music extends CI_Model { public function getAlbums(){ $query = $this->db->query( - "SELECT album.name,album.id,year,artist.name as artistName, genre.name as genreName,jpeg + "SELECT album.name,album.id as albumId,year,artist.name as artistName, genre.name as genreName,jpeg FROM album JOIN artist ON album.artistid = artist.id JOIN genre ON genre.id = album.genreid @@ -44,7 +44,7 @@ class Model_music extends CI_Model { public function getSearchAlbums($nom){ $query = $this->db->query( - "SELECT album.name,album.id,year,artist.name as artistName, genre.name as genreName,jpeg + "SELECT album.name,album.id as albumId,year,artist.name as artistName, genre.name as genreName,jpeg FROM album JOIN artist ON album.artistid = artist.id JOIN genre ON genre.id = album.genreid @@ -52,9 +52,9 @@ class Model_music extends CI_Model { WHERE album.name LIKE '$nom' " ); - $query->result(); + //$query->result(); if ($query->num_rows() > 0){ - return $query; + return $query->result(); } return $query = false; } @@ -68,7 +68,7 @@ class Model_music extends CI_Model { ); $query->result(); if ($query->num_rows() > 0){ - return $query; + return $query->result(); } return $query = false; } @@ -87,8 +87,74 @@ class Model_music extends CI_Model { ); $query->result(); if ($query->num_rows() > 0){ - return $query; + return $query->result(); } return $query = false; } + + public function getAlbumChoose($id) { + $this->db->where('id', $id); + $query = $this->db->get('album'); + $album = $query->row(); + + // Recupere la couverture + $this->db->where('id', $album->coverId); + $coverQuery = $this->db->get('cover'); + $cover = $coverQuery->row(); + $album->coverImage = $cover->jpeg; + // Recupere le l'id de la musique a partie de l'album + $this->db->select('songId'); + $this->db->where('albumId', $id); + $songsQuery = $this->db->get('track'); + $songIds = $songsQuery->result(); + + // Récupérer les noms des chansons à partir des songIds + $album->songs = []; + foreach ($songIds as $song) { + $this->db->select('name'); + $this->db->where('id', $song->songId); + $songQuery = $this->db->get('song'); + $songData = $songQuery->row(); + $album->songs[] = $songData->name; + } + + $album->tracks = []; + foreach ($songIds as $song) { + $this->db->select('song.name as songName, track.duration'); + $this->db->from('track'); + $this->db->join('song', 'track.songId = song.id'); + $this->db->where('track.songId', $song->songId); + $trackQuery = $this->db->get(); + $trackData = $trackQuery->row(); + $album->tracks[] = $trackData; + } + + $this->db->where('id', $album->artistId); + $artistQuery = $this->db->get('artist'); + $artist = $artistQuery->row(); + $album->artist = $artist; + + $this->db->where('id', $album->artistId); + $artistQuery = $this->db->get('artist'); + $artist = $artistQuery->row(); + $album->artist = $artist; + + + + return $album; + } + + public function getAlbumsByArtistId($artistId) { + $query = $this->db->query( + "SELECT album.name,album.id as albumId,year,artist.name as artistName, genre.name as genreName,jpeg + FROM album + JOIN artist ON album.artistid = artist.id + JOIN genre ON genre.id = album.genreid + JOIN cover ON cover.id = album.coverid + WHERE album.artistid=$artistId + ORDER BY year + " + ); + return $query->result(); + } } diff --git a/CodeIgniter-3.1.13/application/views/albums_list.php b/CodeIgniter-3.1.13/application/views/albums_list.php index c5cb6d5..4b5eec6 100644 --- a/CodeIgniter-3.1.13/application/views/albums_list.php +++ b/CodeIgniter-3.1.13/application/views/albums_list.php @@ -1,10 +1,13 @@
Albums list
"; echo "
"; - echo anchor("albums/view/{$album->id}","{$album->name}"); + echo anchor("albums/viewMusique/{$album->albumId}","{$album->name}"); echo "
"; echo ''; echo ""; diff --git a/CodeIgniter-3.1.13/application/views/albums_view.php b/CodeIgniter-3.1.13/application/views/albums_view.php new file mode 100644 index 0000000..3983d90 --- /dev/null +++ b/CodeIgniter-3.1.13/application/views/albums_view.php @@ -0,0 +1,67 @@ +
+
+
+ coverImage) . '" style="width: 300px; height: 300px;" />'; + ?> +
+
+

name; ?>

+ + artist->name; ?> +

year; ?>

+ +
+
+ "; + echo ""; + echo "
Titre
"; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + + echo "
Durée
"; + + echo ""; + foreach ($albums->songs as $index => $songName) { + $artistName = $albums->artist->name; + $duration = isset($albums->tracks[$index]->duration) ? convertirSecondesEnMinutes($albums->tracks[$index]->duration) : ''; + echo "{$songName}"; + + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + + echo "{$duration}"; + echo ""; + } + + + + echo ""; + + + + function convertirSecondesEnMinutes($secondes) { + $minutes = floor($secondes / 60); + $secondesRestantes = $secondes % 60; + return sprintf('%02d:%02d', $minutes, $secondesRestantes); + } + ?> +
+
+
\ No newline at end of file diff --git a/CodeIgniter-3.1.13/application/views/artistes_list.php b/CodeIgniter-3.1.13/application/views/artistes_list.php index 6bf56d1..a065e22 100644 --- a/CodeIgniter-3.1.13/application/views/artistes_list.php +++ b/CodeIgniter-3.1.13/application/views/artistes_list.php @@ -4,7 +4,7 @@ foreach($artistes as $artistes){ echo "
"; echo "
"; - echo anchor("artistes/view/{$artistes->id}","{$artistes->name}"); + echo anchor("albums/viewAlbum/{$artistes->id}","{$artistes->name}"); echo "
"; echo "
"; }