From a0519979f448dbac5b5a4a34f6215890db7821fa Mon Sep 17 00:00:00 2001 From: Vincent <xefal77@gmail.com> Date: Tue, 4 Jun 2024 22:46:59 +0200 Subject: [PATCH] Test details album --- application/controllers/Albums.php | 16 ++++++++++++++++ application/models/Model_music.php | 23 +++++++++++++++++++++++ application/views/album_details.php | 20 ++++++++++++++++++++ 3 files changed, 59 insertions(+) create mode 100644 application/views/album_details.php diff --git a/application/controllers/Albums.php b/application/controllers/Albums.php index 7360c40..4b1af9c 100644 --- a/application/controllers/Albums.php +++ b/application/controllers/Albums.php @@ -33,4 +33,20 @@ class Albums extends CI_Controller { $this->load->view('albums_list', $data); $this->load->view('layout/footer'); } + + public function details($albumId) { + $albumData = $this->model_music->getAlbumDetails($albumId); + + $is_logged_in = $this->session->userdata('logged_in'); + $data = array( + 'album' => $albumData['album'], + 'songs' => $albumData['songs'], + 'is_logged_in' => $is_logged_in + ); + + $this->load->view('layout/header', $data); + $this->load->view('album_details', $data); + $this->load->view('layout/footer'); + } + } diff --git a/application/models/Model_music.php b/application/models/Model_music.php index 0a2d301..26260be 100644 --- a/application/models/Model_music.php +++ b/application/models/Model_music.php @@ -102,6 +102,29 @@ class Model_music extends CI_Model { return $result->result(); } + public function getAlbumDetails($albumId) { + // Get album info + $this->db->select('album.name as albumName, album.id, year, artist.name as artistName, genre.name as genreName, jpeg'); + $this->db->from('album'); + $this->db->join('artist', 'album.artistid = artist.id'); + $this->db->join('genre', 'genre.id = album.genreid'); + $this->db->join('cover', 'cover.id = album.coverid'); + $this->db->where('album.id', $albumId); + $albumQuery = $this->db->get(); + $albumDetails = $albumQuery->row(); + + // Get album songs + $this->db->select('song.name as trackName, track.id as trackId'); + $this->db->from('track'); + $this->db->join('song', 'track.songId = song.id'); + $this->db->where('track.albumId', $albumId); + $songsQuery = $this->db->get(); + $songs = $songsQuery->result(); + + return array('album' => $albumDetails, 'songs' => $songs); + } + + // Suppression de la deuxième méthode researchtype public function research(){ diff --git a/application/views/album_details.php b/application/views/album_details.php new file mode 100644 index 0000000..6cd0a1f --- /dev/null +++ b/application/views/album_details.php @@ -0,0 +1,20 @@ +<!DOCTYPE html> +<html> +<head> + <title><?= $album->albumName ?> - Details</title> +</head> +<body> + <h1><?= $album->albumName ?></h1> + <p><strong>Artist:</strong> <?= $album->artistName ?></p> + <p><strong>Genre:</strong> <?= $album->genreName ?></p> + <p><strong>Year:</strong> <?= $album->year ?></p> + <img src="<?= base_url('uploads/' . $album->jpeg) ?>" alt="<?= $album->albumName ?> Cover"> + + <h2>Songs</h2> + <ul> + <?php foreach ($songs as $song): ?> + <li><?= $song->trackName ?></li> + <?php endforeach; ?> + </ul> +</body> +</html>