diff --git a/application/controllers/Artistes.php b/application/controllers/Artistes.php index 63fa972..1c2841c 100644 --- a/application/controllers/Artistes.php +++ b/application/controllers/Artistes.php @@ -29,5 +29,20 @@ class Artistes extends CI_Controller { $this->load->view('artists_list', $data); $this->load->view('layout/footer'); } + + public function view($artistId) { + $artistData = $this->model_music->getArtistDetails($artistId); + + $is_logged_in = $this->session->userdata('logged_in'); + $data = array( + 'artist' => $artistData['artist'], + 'albums' => $artistData['albums'], + 'is_logged_in' => $is_logged_in + ); + + $this->load->view('layout/header', $data); + $this->load->view('artist_details', $data); + $this->load->view('layout/footer'); + } } diff --git a/application/models/Model_music.php b/application/models/Model_music.php index fcf61ba..38c8158 100644 --- a/application/models/Model_music.php +++ b/application/models/Model_music.php @@ -123,6 +123,26 @@ class Model_music extends CI_Model { return array('album' => $albumDetails, 'songs' => $songs); } + public function getArtistDetails($artistId) { + // Get artist info + $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->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->from('album'); + $this->db->where('album.artistid', $artistId); + $albumsQuery = $this->db->get(); + $albums = $albumsQuery->result(); + + return array('artist' => $artistDetails, 'albums' => $albums); + } + diff --git a/application/views/artist_details.php b/application/views/artist_details.php new file mode 100644 index 0000000..13babdf --- /dev/null +++ b/application/views/artist_details.php @@ -0,0 +1,18 @@ +<!DOCTYPE html> +<html> +<head> + <title><?= $artist->artistName ?> - Details</title> +</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"> + + <h2>Albums</h2> + <ul> + <?php foreach ($albums as $album): ?> + <li><?= anchor("albums/view/{$album->albumId}", $album->albumName) ?> (<?= $album->year ?>)</li> + <?php endforeach; ?> + </ul> +</body> +</html>