diff --git a/CodeIgniter-3.1.13/application/controllers/Albums.php b/CodeIgniter-3.1.13/application/controllers/Albums.php index be9879e..010d835 100644 --- a/CodeIgniter-3.1.13/application/controllers/Albums.php +++ b/CodeIgniter-3.1.13/application/controllers/Albums.php @@ -8,18 +8,29 @@ class Albums extends CI_Controller { $this->load->model('model_music'); $this->load->helper('url'); } + public function index($page = 1){ $limit = 21; $offset = ($page - 1) * $limit; $albums = $this->model_music->getAlbums($limit, $offset); - + $total_albums = $this->model_music->get_total_albums(); $data['total_pages'] = ceil($total_albums / $limit); $data['current_page'] = $page; $data['albums'] = $albums; - + $this->load->view('layout/header_not_logged_dark'); $this->load->view('albums_list', $data); $this->load->view('layout/footer_dark'); } + + public function view($id){ + $album = $this->model_music->get_album_by_id($id); + $data['album'] = $album; + + $this->load->view('layout/header_not_logged_dark'); + $this->load->view('album_view', $data); + $this->load->view('layout/footer_dark'); + } } +?> diff --git a/CodeIgniter-3.1.13/application/models/Model_music.php b/CodeIgniter-3.1.13/application/models/Model_music.php index 5ca512d..461b4b2 100644 --- a/CodeIgniter-3.1.13/application/models/Model_music.php +++ b/CodeIgniter-3.1.13/application/models/Model_music.php @@ -1,22 +1,22 @@ -load->database(); - } + public function __construct(){ + $this->load->database(); + } - public function getAlbums($limit, $offset){ - $query = $this->db->query( - "SELECT album.name, album.id, 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 - ORDER BY year - LIMIT $limit OFFSET $offset" + public function getAlbums($limit, $offset){ + $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 + ORDER BY album.year + LIMIT $limit OFFSET $offset" ); - return $query->result(); - } + return $query->result(); + } public function get_total_albums(){ $query = $this->db->query("SELECT COUNT(*) as total_albums FROM album"); @@ -24,4 +24,31 @@ class Model_music extends CI_Model { return $result->total_albums; } + public function get_album_by_id($id){ + // Fetch album details + $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 album.id = ?", array($id) + ); + $album = $query->row(); + + if ($album) { + // Fetch album tracks + $query = $this->db->query( + "SELECT track.id, track.diskNumber, track.number, track.duration, song.name as songName + FROM track + JOIN song ON track.songid = song.id + WHERE track.albumid = ? + ORDER BY track.diskNumber, track.number", array($id) + ); + $album->tracks = $query->result(); + } + + return $album; + } } +?> diff --git a/CodeIgniter-3.1.13/application/views/album_view.php b/CodeIgniter-3.1.13/application/views/album_view.php new file mode 100644 index 0000000..0de9660 --- /dev/null +++ b/CodeIgniter-3.1.13/application/views/album_view.php @@ -0,0 +1,32 @@ + + + + + + + + <?php echo $album->name; ?> - Details + + +
+

name; ?>

+

Artiste : artistName; ?>

+

Année : year; ?>

+

Genre : genreName; ?>

+ Image d'album + + tracks)): ?> +

Musiques

+ + +

Aucune musique n'est disponible dans cette album...

+ +
+ + diff --git a/CodeIgniter-3.1.13/application/views/albums_list.php b/CodeIgniter-3.1.13/application/views/albums_list.php index 4b07b32..5875c47 100644 --- a/CodeIgniter-3.1.13/application/views/albums_list.php +++ b/CodeIgniter-3.1.13/application/views/albums_list.php @@ -1,34 +1,41 @@ + + + + + Page d'accueil + +

Listes des albums

+
+ +
+
+
+ id}", $album->name); ?> +
+ <?php echo $album->name; ?> +
year; ?> - artistName; ?>
+
+
+ +
-

Listes des albums

-
-
"; - echo "
"; - echo anchor("albums/view/{$album->id}","{$album->name}"); - echo "
"; - echo ''; - echo " -
"; -} -?> -
+ + + diff --git a/CodeIgniter-3.1.13/assets/css/album_view.css b/CodeIgniter-3.1.13/assets/css/album_view.css new file mode 100644 index 0000000..912911a --- /dev/null +++ b/CodeIgniter-3.1.13/assets/css/album_view.css @@ -0,0 +1,46 @@ +body { + font-family: Arial, sans-serif; + background-color: #f0f0f0; + margin: 0; + padding: 0; +} + +.album-details { + max-width: 800px; + margin: 20px auto; + padding: 20px; + background-color: #ffffff; + border-radius: 8px; + box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); +} + +.album-details h1 { + font-size: 2em; + margin-bottom: 10px; +} + +.album-details p { + font-size: 1.2em; + margin: 5px 0; +} + +.album-details img { + max-width: 100%; + height: auto; + margin: 20px 0; +} + +.album-details h2 { + font-size: 1.5em; + margin-top: 20px; +} + +.album-details ul { + list-style-type: none; + padding: 0; +} + +.album-details ul li { + padding: 10px 0; + border-bottom: 1px solid #ddd; +}