diff --git a/CodeIgniter-3.1.13/application/controllers/Albums.php b/CodeIgniter-3.1.13/application/controllers/Albums.php index 67abe11..8405b2a 100644 --- a/CodeIgniter-3.1.13/application/controllers/Albums.php +++ b/CodeIgniter-3.1.13/application/controllers/Albums.php @@ -12,12 +12,25 @@ class Albums extends CI_Controller { public function index($page = 1){ $limit = 21; // Nombre d'albums max par page $offset = ($page - 1) * $limit; - $albums = $this->model_music->getAlbums($limit, $offset); - $total_albums = $this->model_music->get_total_albums(); + // Récupérer les paramètres de tri et de filtre + $order_by = $this->input->get('order_by') ? $this->input->get('order_by') : 'year'; + $genre_id = $this->input->get('genre_id'); + $artist_id = $this->input->get('artist_id'); + + $albums = $this->model_music->getAlbums($limit, $offset, $order_by, $genre_id, $artist_id); + $total_albums = $this->model_music->get_total_albums($genre_id, $artist_id); + $data['total_pages'] = ceil($total_albums / $limit); $data['current_page'] = $page; $data['albums'] = $albums; + $data['order_by'] = $order_by; + $data['genre_id'] = $genre_id; + $data['artist_id'] = $artist_id; + + // Récupérer les genres et les artistes pour les filtres + $data['genres'] = $this->model_music->getGenres(); + $data['artists'] = $this->model_music->getArtists(); $this->load->view('layout/header_not_logged_dark'); $this->load->view('albums_list', $data); @@ -32,6 +45,5 @@ class Albums extends CI_Controller { $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 30a05f9..ec0293e 100644 --- a/CodeIgniter-3.1.13/application/models/Model_music.php +++ b/CodeIgniter-3.1.13/application/models/Model_music.php @@ -5,27 +5,74 @@ class Model_music extends CI_Model { $this->load->database(); } - 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" - ); + public function getAlbums($limit, $offset, $order_by = 'year', $genre_id = null, $artist_id = null){ + $sql = "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"; + + if ($genre_id) { + $sql .= " WHERE genre.id = ?"; + $params[] = $genre_id; + } + + if ($artist_id) { + if ($genre_id) { + $sql .= " AND artist.id = ?"; + } else { + $sql .= " WHERE artist.id = ?"; + } + $params[] = $artist_id; + } + + $sql .= " ORDER BY album." . $order_by . " LIMIT ? OFFSET ?"; + $params[] = $limit; + $params[] = $offset; + + $query = $this->db->query($sql, $params); return $query->result(); } - public function get_total_albums(){ - $query = $this->db->query("SELECT COUNT(*) as total_albums FROM album"); + public function get_total_albums($genre_id = null, $artist_id = null){ + $sql = "SELECT COUNT(*) as total_albums FROM album + JOIN genre ON album.genreid = genre.id + JOIN artist ON album.artistid = artist.id"; + + $params = array(); // Initialiser le tableau de paramètres + + if ($genre_id) { + $sql .= " WHERE genre.id = ?"; + $params[] = $genre_id; + } + + if ($artist_id) { + if ($genre_id) { + $sql .= " AND artist.id = ?"; + } else { + $sql .= " WHERE artist.id = ?"; + } + $params[] = $artist_id; + } + + $query = $this->db->query($sql, $params); $result = $query->row(); return $result->total_albums; } + + // Méthodes pour obtenir les genres et les artistes pour les filtres + public function getGenres(){ + $query = $this->db->query("SELECT id, name FROM genre ORDER BY name"); + return $query->result(); + } + + public function getArtists(){ + $query = $this->db->query("SELECT id, name FROM artist ORDER BY name"); + return $query->result(); + } + 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 @@ -35,9 +82,8 @@ class Model_music extends CI_Model { 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 @@ -47,10 +93,10 @@ class Model_music extends CI_Model { ); $album->tracks = $query->result(); } - + return $album; } - + public function getMusiques($limit, $offset) { $query = $this->db->query( "SELECT song.id, song.name, artist.id as artist_id, artist.name as artistName, album.name as album_name, track.albumid as album_id, cover.jpeg as cover @@ -63,14 +109,14 @@ class Model_music extends CI_Model { ); return $query->result(); } - + public function get_total_musiques(){ $query = $this->db->query("SELECT COUNT(*) as total_musiques FROM song"); $result = $query->row(); return $result->total_musiques; } - + public function getAlbumsByArtiste($artiste_id){ $query = $this->db->query(" SELECT album.id, album.name, album.year, artist.name as artistName, genre.name as genreName, cover.jpeg @@ -82,8 +128,5 @@ class Model_music extends CI_Model { ", array($artiste_id)); return $query->result(); } - - - } ?> diff --git a/CodeIgniter-3.1.13/application/views/album_musiques.php b/CodeIgniter-3.1.13/application/views/album_musiques.php deleted file mode 100644 index 0770d25..0000000 --- a/CodeIgniter-3.1.13/application/views/album_musiques.php +++ /dev/null @@ -1,31 +0,0 @@ - - - - - - - <?php echo $album->name; ?> - Musiques - - -
-

name; ?>

-

Artiste : artistName; ?>

-

Année : year; ?>

-

Genre : genreName; ?>

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

Musiques

- - -

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

- -
- - diff --git a/CodeIgniter-3.1.13/application/views/album_view.php b/CodeIgniter-3.1.13/application/views/album_view.php index 710de81..9098954 100644 --- a/CodeIgniter-3.1.13/application/views/album_view.php +++ b/CodeIgniter-3.1.13/application/views/album_view.php @@ -1,10 +1,9 @@ - - + <?php echo $album->name; ?> - Details diff --git a/CodeIgniter-3.1.13/application/views/albums_list.php b/CodeIgniter-3.1.13/application/views/albums_list.php index 99bfae7..dfd45c4 100644 --- a/CodeIgniter-3.1.13/application/views/albums_list.php +++ b/CodeIgniter-3.1.13/application/views/albums_list.php @@ -9,6 +9,35 @@

Listes des albums

+ +
+
+ + + + + + + + + + +
+
+
@@ -24,18 +53,17 @@
+ + > + + diff --git a/CodeIgniter-3.1.13/assets/css/album_view.css b/CodeIgniter-3.1.13/assets/css/album_view.css index 0f22d70..912911a 100644 --- a/CodeIgniter-3.1.13/assets/css/album_view.css +++ b/CodeIgniter-3.1.13/assets/css/album_view.css @@ -5,7 +5,7 @@ body { padding: 0; } -.artist-list-container { +.album-details { max-width: 800px; margin: 20px auto; padding: 20px; @@ -14,57 +14,33 @@ body { box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); } -.artist-list-container h1 { +.album-details h1 { font-size: 2em; margin-bottom: 10px; - text-align: center; - color: #800080; /* Couleur violette */ } -.artist-list { +.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; } -.artist-list li { - display: flex; - align-items: center; +.album-details ul li { padding: 10px 0; border-bottom: 1px solid #ddd; } - -.artist-list li:last-child { - border-bottom: none; -} - -.artist-list img { - width: 50px; - height: 50px; - border-radius: 50%; - margin-right: 15px; -} - -.artist-list .artist-details { - display: flex; - flex-direction: column; -} - -.artist-list .artist-details h2 { - font-size: 1.2em; - margin: 0; -} - -.artist-list .artist-details p { - font-size: 1em; - margin: 5px 0; - color: #666; -} - -.artist-list .artist-details a { - text-decoration: none; - color: #9500ff; -} - -.artist-list .artist-details a:hover { - text-decoration: underline; -} diff --git a/CodeIgniter-3.1.13/assets/css/artists_list.css b/CodeIgniter-3.1.13/assets/css/artists_list.css index f094bad..23c6e55 100644 --- a/CodeIgniter-3.1.13/assets/css/artists_list.css +++ b/CodeIgniter-3.1.13/assets/css/artists_list.css @@ -76,3 +76,4 @@ body { .artist-list .artist-details a:hover { text-decoration: underline; } + diff --git a/CodeIgniter-3.1.13/assets/css/style.css b/CodeIgniter-3.1.13/assets/css/style.css index 5a64ff0..b53c19e 100644 --- a/CodeIgniter-3.1.13/assets/css/style.css +++ b/CodeIgniter-3.1.13/assets/css/style.css @@ -110,3 +110,29 @@ header.short-text a { background-color: #29043e; } +.filters { + text-align: center; + margin-bottom: 20px; +} + +.filters label { + margin-right: 10px; +} + +.filters select { + margin-right: 10px; +} + +.filters button { + background-color: #8c00ff; + color: #fff; + border: none; + padding: 8px 16px; + border-radius: 4px; + cursor: pointer; +} + +.filters button:hover { + background-color: #6a0080; +} +