diff --git a/application/controllers/Artistes.php b/application/controllers/Artistes.php index 1c2841c..ddd24d0 100644 --- a/application/controllers/Artistes.php +++ b/application/controllers/Artistes.php @@ -6,7 +6,7 @@ class Artistes extends CI_Controller { public function __construct(){ parent::__construct(); $this->load->model('model_music'); - $this->load->library('session'); // La session est déjà chargée via autoload.php, mais par précaution. + $this->load->library('session'); } public function index(){ @@ -14,7 +14,7 @@ class Artistes extends CI_Controller { $order = $this->input->get('order'); $query = $this->input->get('query'); - $artists = $this->model_music->getArtists($genre, $order, $query); // Pass $query + $artists = $this->model_music->getArtists($genre, $order, $query); $genres = $this->model_music->researchtype(); $is_logged_in = $this->session->userdata('logged_in'); diff --git a/application/controllers/Music.php b/application/controllers/Music.php index c2cc852..929bdb0 100644 --- a/application/controllers/Music.php +++ b/application/controllers/Music.php @@ -13,8 +13,7 @@ class Music extends CI_Controller { $genre = $this->input->get('genre'); $order = $this->input->get('order'); $artist = $this->input->get('artist'); - $query = $this->input->get('query'); - + $query = $this->input->get('query'); $musics = $this->model_music->getMusics($genre, $order, $artist, $query); $genres = $this->model_music->researchtype(); @@ -33,4 +32,19 @@ class Music extends CI_Controller { $this->load->view('musiques_list', $data); $this->load->view('layout/footer'); } + + public function song($songId) { + $songData = $this->model_music->getSongDetails($songId); + + $is_logged_in = $this->session->userdata('logged_in'); + $data = array( + 'song' => $songData, + 'is_logged_in' => $is_logged_in + ); + + $this->load->view('layout/header', $data); + $this->load->view('song_details', $data); + $this->load->view('layout/footer'); + } } + diff --git a/application/models/Model_music.php b/application/models/Model_music.php index 38c8158..af2caf9 100644 --- a/application/models/Model_music.php +++ b/application/models/Model_music.php @@ -128,13 +128,13 @@ class Model_music extends CI_Model { $this->db->select('artist.name as artistName, artist.id, genre.name as genreName, artist.jpeg'); $this->db->from('artist'); $this->db->join('album', 'album.artistid = artist.id'); - $this->db->join('genre', 'genre.id = album.genreid'); + $this->db->join('genre', 'genre.id = album.genreid', 'left'); $this->db->where('artist.id', $artistId); $artistQuery = $this->db->get(); $artistDetails = $artistQuery->row(); // Get artist's albums - $this->db->select('album.name as albumName, album.id as albumId, album.year'); + $this->db->select('album.id as albumId, album.name as albumName, album.year'); $this->db->from('album'); $this->db->where('album.artistid', $artistId); $albumsQuery = $this->db->get(); @@ -143,6 +143,20 @@ class Model_music extends CI_Model { return array('artist' => $artistDetails, 'albums' => $albums); } + public function getSongDetails($songId) { + // Get song details + $this->db->select('song.name as songName, track.id as trackId, album.name as albumName, album.year, artist.name as artistName, genre.name as genreName, cover.jpeg'); + $this->db->from('track'); + $this->db->join('song', 'track.songId = song.id'); + $this->db->join('album', 'track.albumId = album.id'); + $this->db->join('artist', 'album.artistid = artist.id'); + $this->db->join('genre', 'album.genreid = genre.id'); + $this->db->join('cover', 'album.coverid = cover.id'); + $this->db->where('track.id', $songId); + $songQuery = $this->db->get(); + return $songQuery->row(); + } + diff --git a/application/views/album_details.php b/application/views/album_details.php index 8057138..da28dc9 100644 --- a/application/views/album_details.php +++ b/application/views/album_details.php @@ -13,7 +13,7 @@ <h2>Songs</h2> <ul> <?php foreach ($songs as $song): ?> - <li><?= $song->trackName ?></li> + <li><?= anchor("music/song/{$song->trackId}", $song->trackName) ?></li> <?php endforeach; ?> </ul> </body> diff --git a/application/views/artist_details.php b/application/views/artist_details.php index 13babdf..6492d5f 100644 --- a/application/views/artist_details.php +++ b/application/views/artist_details.php @@ -5,8 +5,12 @@ </head> <body> <h1><?= $artist->artistName ?></h1> - <p><strong>Genre:</strong> <?= $artist->genreName ?></p> - <img src="data:image/jpeg;base64,<?= base64_encode($artist->jpeg) ?>" alt="<?= $artist->artistName ?> Photo"> + <?php if (!empty($artist->genreName)): ?> + <p><strong>Genre:</strong> <?= $artist->genreName ?></p> + <?php endif; ?> + <?php if (!empty($artist->jpeg)): ?> + <img src="data:image/jpeg;base64,<?= base64_encode($artist->jpeg) ?>" alt="<?= $artist->artistName ?> Photo"> + <?php endif; ?> <h2>Albums</h2> <ul> diff --git a/application/views/song_details.php b/application/views/song_details.php new file mode 100644 index 0000000..f030f00 --- /dev/null +++ b/application/views/song_details.php @@ -0,0 +1,13 @@ +<!DOCTYPE html> +<html> +<head> + <title><?= $song->songName ?> - Details</title> +</head> +<body> + <h1><?= $song->songName ?></h1> + <p><strong>Album:</strong> <?= anchor("albums/view/{$song->trackId}", $song->albumName) ?> (<?= $song->year ?>)</p> + <p><strong>Artist:</strong> <?= $song->artistName ?></p> + <p><strong>Genre:</strong> <?= $song->genreName ?></p> + <img src="data:image/jpeg;base64,<?= base64_encode($song->jpeg) ?>" alt="<?= $song->albumName ?> Cover"> +</body> +</html>