From 3bc08d6bd2cbe0477d823efa9f04a2c3df2b63c9 Mon Sep 17 00:00:00 2001 From: stiti Date: Fri, 7 Jun 2024 13:41:17 +0200 Subject: [PATCH] =?UTF-8?q?Commit=20de=20Louay=20:=20Modifications=20pour?= =?UTF-8?q?=20=C3=A9viter=20des=20bugs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/controllers/Albums.php | 19 ++-- .../application/controllers/Musiques.php | 19 ++-- .../application/models/Model_music.php | 26 +++++ .../application/views/albums_list.php | 102 +++++++++--------- 4 files changed, 95 insertions(+), 71 deletions(-) diff --git a/CodeIgniter-3.1.13/application/controllers/Albums.php b/CodeIgniter-3.1.13/application/controllers/Albums.php index 5d3be32..35bf5dc 100644 --- a/CodeIgniter-3.1.13/application/controllers/Albums.php +++ b/CodeIgniter-3.1.13/application/controllers/Albums.php @@ -27,7 +27,7 @@ class Albums extends CI_Controller { $total_pages = ceil($total_albums / $limit); // Vérifier si la page demandée est valide - if ($page < 1 || $page > $total_pages) { + if ($page < 1 || ($total_pages > 0 && $page > $total_pages)) { redirect('errors/error_404'); return; } @@ -36,30 +36,30 @@ class Albums extends CI_Controller { $user_id = $this->session->userdata('user_id'); $data['user_playlists'] = $this->Model_playlist->get_user_playlists($user_id); } - + $data['total_pages'] = $total_pages; $data['current_page'] = $page; $data['albums'] = $albums; $data['order_by'] = $order_by; $data['genre_id'] = $genre_id; $data['artist_id'] = $artist_id; - $data['title']= 'Albums - Onzeur'; - $data['css']='assets/css/style'; + $data['title'] = 'Albums - Onzeur'; + $data['css'] = 'assets/css/style'; // 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_dark', $data); - $this->load->view('albums_list',$data); + $this->load->view('albums_list', $data); $this->load->view('layout/footer_dark'); } public function view($id){ [$album,$tracks] = $this->model_music->get_album_by_id($id); $data['album'] = $album; - $data['title'] = $album->name." - Details"; - $data['css']='assets/css/album_view'; + $data['title'] = $album->name . " - Details"; + $data['css'] = 'assets/css/album_view'; $data['tracks'] = $tracks; if ($this->session->userdata('user_id')) { $user_id = $this->session->userdata('user_id'); @@ -67,8 +67,7 @@ class Albums extends CI_Controller { } $this->load->view('layout/header_dark', $data); - $this->load->view('album_view'); + $this->load->view('album_view', $data); $this->load->view('layout/footer_dark'); } } -?> diff --git a/CodeIgniter-3.1.13/application/controllers/Musiques.php b/CodeIgniter-3.1.13/application/controllers/Musiques.php index 4ebf28d..112534d 100644 --- a/CodeIgniter-3.1.13/application/controllers/Musiques.php +++ b/CodeIgniter-3.1.13/application/controllers/Musiques.php @@ -14,11 +14,6 @@ class Musiques extends CI_Controller { } public function index($page = 1){ - $this->load->model('Model_music'); - $this->load->library('pagination'); - $this->load->helper('url'); - $this->load->helper('html'); - $limit = 30; $offset = ($page - 1) * $limit; $sort = $this->input->get('sort'); @@ -26,24 +21,24 @@ class Musiques extends CI_Controller { $artist_id = $this->input->get('artist_id'); $musiques = $this->Model_music->getMusiques($limit, $offset, $sort, 'ASC', $genre_id, $artist_id); - $total_musiques = $this->Model_music->get_total_musiques(); - $total_pages = ceil($total_musiques / $limit); - + $total_musiques = $this->Model_music->get_total_musiques_filtered($genre_id, $artist_id); // Utiliser la nouvelle méthode ici + $total_pages = ceil($total_musiques / $limit); + // Vérifier si la page demandée est valide if ($page < 1 || $page > $total_pages) { redirect('errors/error_404'); return; } - + $current_page = $page; $genres = $this->Model_music->getGenres(); $artists = $this->Model_music->getArtists(); - + if ($this->session->userdata('user_id')) { $user_id = $this->session->userdata('user_id'); $data['user_playlists'] = $this->Model_playlist->get_user_playlists($user_id); } - + $data['musiques'] = $musiques; $data['total_pages'] = $total_pages; $data['current_page'] = $current_page; @@ -59,6 +54,6 @@ class Musiques extends CI_Controller { $this->load->view('layout/header_dark', $data); $this->load->view('musiques_list', $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 113dd22..8e481c9 100644 --- a/CodeIgniter-3.1.13/application/models/Model_music.php +++ b/CodeIgniter-3.1.13/application/models/Model_music.php @@ -166,6 +166,32 @@ class Model_music extends CI_Model { return $this->db->get()->result(); } + public function get_total_musiques_filtered($genre_id = null, $artist_id = null) { + $where_clause = ''; + $params = array(); + if ($genre_id) { + $where_clause .= " WHERE genre.id = ?"; + $params[] = $genre_id; + } + if ($artist_id) { + $where_clause .= ($where_clause == '') ? ' WHERE' : ' AND'; + $where_clause .= " artist.id = ?"; + $params[] = $artist_id; + } + + $query = $this->db->query(" + SELECT COUNT(*) as total + FROM song + JOIN track ON song.id = track.songid + JOIN album ON track.albumid = album.id + JOIN artist ON album.artistid = artist.id + JOIN genre ON album.genreid = genre.id + $where_clause + ", $params); + + return $query->row()->total; + } + public function get_random_songs($limit, $genre = null, $artist = null) { $this->db->select('song.id, song.name'); $this->db->from('song'); diff --git a/CodeIgniter-3.1.13/application/views/albums_list.php b/CodeIgniter-3.1.13/application/views/albums_list.php index a30e483..5ef1484 100644 --- a/CodeIgniter-3.1.13/application/views/albums_list.php +++ b/CodeIgniter-3.1.13/application/views/albums_list.php @@ -1,35 +1,37 @@ +

Listes des albums

-

Listes des albums

- -
-
- - +
+ + + - - + + - - + + - - -
- -
+ + +
+ +
+ +

Aucun album trouvé pour cette sélection.

+
@@ -40,33 +42,35 @@
year; ?> - artistName; ?> session->userdata('user_id')): ?> -

- +

+ + + - -
+
-
+ + - \ No newline at end of file +