mirror of
https://grond.iut-fbleau.fr/stiti/SAE_2.02
synced 2024-12-27 01:12:18 +01:00
Commit de Louay : Modifications pour éviter des bugs
This commit is contained in:
parent
417b16011f
commit
3bc08d6bd2
@ -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;
|
||||
}
|
||||
@ -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');
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
@ -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,7 +21,7 @@ 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_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
|
||||
|
@ -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');
|
||||
|
@ -1,4 +1,3 @@
|
||||
|
||||
<h1 class="title">Listes des albums</h1>
|
||||
|
||||
<div class="filters">
|
||||
@ -30,6 +29,9 @@
|
||||
</div>
|
||||
|
||||
<section class="list">
|
||||
<?php if (empty($albums)): ?>
|
||||
<p>Aucun album trouvé pour cette sélection.</p>
|
||||
<?php else: ?>
|
||||
<?php foreach($albums as $album): ?>
|
||||
<div>
|
||||
<article>
|
||||
@ -40,7 +42,8 @@
|
||||
<footer class="short-text"><?php echo $album->year; ?> - <?php echo $album->artistName; ?>
|
||||
<?php if ($this->session->userdata('user_id')): ?>
|
||||
<?php if (!empty($user_playlists)): ?>
|
||||
<br><br><select id="playlist_<?php echo $album->id; ?>" class="select-playlist">
|
||||
<br><br>
|
||||
<select id="playlist_<?php echo $album->id; ?>" class="select-playlist">
|
||||
<?php foreach ($user_playlists as $playlist) : ?>
|
||||
<option value="<?php echo $playlist->id; ?>"><?php echo $playlist->name; ?></option>
|
||||
<?php endforeach; ?>
|
||||
@ -52,6 +55,7 @@
|
||||
</article>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
<?php endif; ?>
|
||||
</section>
|
||||
|
||||
<div class="pagination">
|
||||
|
Loading…
Reference in New Issue
Block a user