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);
|
$total_pages = ceil($total_albums / $limit);
|
||||||
|
|
||||||
// Vérifier si la page demandée est valide
|
// 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');
|
redirect('errors/error_404');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -36,30 +36,30 @@ class Albums extends CI_Controller {
|
|||||||
$user_id = $this->session->userdata('user_id');
|
$user_id = $this->session->userdata('user_id');
|
||||||
$data['user_playlists'] = $this->Model_playlist->get_user_playlists($user_id);
|
$data['user_playlists'] = $this->Model_playlist->get_user_playlists($user_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
$data['total_pages'] = $total_pages;
|
$data['total_pages'] = $total_pages;
|
||||||
$data['current_page'] = $page;
|
$data['current_page'] = $page;
|
||||||
$data['albums'] = $albums;
|
$data['albums'] = $albums;
|
||||||
$data['order_by'] = $order_by;
|
$data['order_by'] = $order_by;
|
||||||
$data['genre_id'] = $genre_id;
|
$data['genre_id'] = $genre_id;
|
||||||
$data['artist_id'] = $artist_id;
|
$data['artist_id'] = $artist_id;
|
||||||
$data['title']= 'Albums - Onzeur';
|
$data['title'] = 'Albums - Onzeur';
|
||||||
$data['css']='assets/css/style';
|
$data['css'] = 'assets/css/style';
|
||||||
|
|
||||||
// Récupérer les genres et les artistes pour les filtres
|
// Récupérer les genres et les artistes pour les filtres
|
||||||
$data['genres'] = $this->model_music->getGenres();
|
$data['genres'] = $this->model_music->getGenres();
|
||||||
$data['artists'] = $this->model_music->getArtists();
|
$data['artists'] = $this->model_music->getArtists();
|
||||||
|
|
||||||
$this->load->view('layout/header_dark', $data);
|
$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');
|
$this->load->view('layout/footer_dark');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function view($id){
|
public function view($id){
|
||||||
[$album,$tracks] = $this->model_music->get_album_by_id($id);
|
[$album,$tracks] = $this->model_music->get_album_by_id($id);
|
||||||
$data['album'] = $album;
|
$data['album'] = $album;
|
||||||
$data['title'] = $album->name." - Details";
|
$data['title'] = $album->name . " - Details";
|
||||||
$data['css']='assets/css/album_view';
|
$data['css'] = 'assets/css/album_view';
|
||||||
$data['tracks'] = $tracks;
|
$data['tracks'] = $tracks;
|
||||||
if ($this->session->userdata('user_id')) {
|
if ($this->session->userdata('user_id')) {
|
||||||
$user_id = $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('layout/header_dark', $data);
|
||||||
$this->load->view('album_view');
|
$this->load->view('album_view', $data);
|
||||||
$this->load->view('layout/footer_dark');
|
$this->load->view('layout/footer_dark');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
?>
|
|
||||||
|
@ -14,11 +14,6 @@ class Musiques extends CI_Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function index($page = 1){
|
public function index($page = 1){
|
||||||
$this->load->model('Model_music');
|
|
||||||
$this->load->library('pagination');
|
|
||||||
$this->load->helper('url');
|
|
||||||
$this->load->helper('html');
|
|
||||||
|
|
||||||
$limit = 30;
|
$limit = 30;
|
||||||
$offset = ($page - 1) * $limit;
|
$offset = ($page - 1) * $limit;
|
||||||
$sort = $this->input->get('sort');
|
$sort = $this->input->get('sort');
|
||||||
@ -26,24 +21,24 @@ class Musiques extends CI_Controller {
|
|||||||
$artist_id = $this->input->get('artist_id');
|
$artist_id = $this->input->get('artist_id');
|
||||||
|
|
||||||
$musiques = $this->Model_music->getMusiques($limit, $offset, $sort, 'ASC', $genre_id, $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);
|
$total_pages = ceil($total_musiques / $limit);
|
||||||
|
|
||||||
// Vérifier si la page demandée est valide
|
// Vérifier si la page demandée est valide
|
||||||
if ($page < 1 || $page > $total_pages) {
|
if ($page < 1 || $page > $total_pages) {
|
||||||
redirect('errors/error_404');
|
redirect('errors/error_404');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$current_page = $page;
|
$current_page = $page;
|
||||||
$genres = $this->Model_music->getGenres();
|
$genres = $this->Model_music->getGenres();
|
||||||
$artists = $this->Model_music->getArtists();
|
$artists = $this->Model_music->getArtists();
|
||||||
|
|
||||||
if ($this->session->userdata('user_id')) {
|
if ($this->session->userdata('user_id')) {
|
||||||
$user_id = $this->session->userdata('user_id');
|
$user_id = $this->session->userdata('user_id');
|
||||||
$data['user_playlists'] = $this->Model_playlist->get_user_playlists($user_id);
|
$data['user_playlists'] = $this->Model_playlist->get_user_playlists($user_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
$data['musiques'] = $musiques;
|
$data['musiques'] = $musiques;
|
||||||
$data['total_pages'] = $total_pages;
|
$data['total_pages'] = $total_pages;
|
||||||
$data['current_page'] = $current_page;
|
$data['current_page'] = $current_page;
|
||||||
@ -59,6 +54,6 @@ class Musiques extends CI_Controller {
|
|||||||
$this->load->view('layout/header_dark', $data);
|
$this->load->view('layout/header_dark', $data);
|
||||||
$this->load->view('musiques_list', $data);
|
$this->load->view('musiques_list', $data);
|
||||||
$this->load->view('layout/footer_dark');
|
$this->load->view('layout/footer_dark');
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -166,6 +166,32 @@ class Model_music extends CI_Model {
|
|||||||
return $this->db->get()->result();
|
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) {
|
public function get_random_songs($limit, $genre = null, $artist = null) {
|
||||||
$this->db->select('song.id, song.name');
|
$this->db->select('song.id, song.name');
|
||||||
$this->db->from('song');
|
$this->db->from('song');
|
||||||
|
@ -1,35 +1,37 @@
|
|||||||
|
<h1 class="title">Listes des albums</h1>
|
||||||
|
|
||||||
<h1 class="title">Listes des albums</h1>
|
<div class="filters">
|
||||||
|
<form method="GET" action="<?php echo base_url('index.php/albums/index'); ?>">
|
||||||
<div class="filters">
|
<label for="genre">Genre:</label>
|
||||||
<form method="GET" action="<?php echo base_url('index.php/albums/index'); ?>">
|
<select name="genre_id" id="genre">
|
||||||
<label for="genre">Genre:</label>
|
<option value="">Tous les genres</option>
|
||||||
<select name="genre_id" id="genre">
|
<?php foreach($genres as $genre): ?>
|
||||||
<option value="">Tous les genres</option>
|
<option value="<?php echo $genre->id; ?>" <?php echo ($genre->id == $genre_id) ? 'selected' : ''; ?>><?php echo $genre->name; ?></option>
|
||||||
<?php foreach($genres as $genre): ?>
|
<?php endforeach; ?>
|
||||||
<option value="<?php echo $genre->id; ?>" <?php echo ($genre->id == $genre_id) ? 'selected' : ''; ?>><?php echo $genre->name; ?></option>
|
</select>
|
||||||
<?php endforeach; ?>
|
|
||||||
</select>
|
|
||||||
|
|
||||||
<label for="artist">Artiste:</label>
|
<label for="artist">Artiste:</label>
|
||||||
<select name="artist_id" id="artist">
|
<select name="artist_id" id="artist">
|
||||||
<option value="">Tous les artistes</option>
|
<option value="">Tous les artistes</option>
|
||||||
<?php foreach($artists as $artist): ?>
|
<?php foreach($artists as $artist): ?>
|
||||||
<option value="<?php echo $artist->id; ?>" <?php echo ($artist->id == $artist_id) ? 'selected' : ''; ?>><?php echo $artist->name; ?></option>
|
<option value="<?php echo $artist->id; ?>" <?php echo ($artist->id == $artist_id) ? 'selected' : ''; ?>><?php echo $artist->name; ?></option>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<label for="order_by">Trier par:</label>
|
<label for="order_by">Trier par:</label>
|
||||||
<select name="order_by" id="order_by">
|
<select name="order_by" id="order_by">
|
||||||
<option value="year" <?php echo ($order_by == 'year') ? 'selected' : ''; ?>>Année</option>
|
<option value="year" <?php echo ($order_by == 'year') ? 'selected' : ''; ?>>Année</option>
|
||||||
<option value="name" <?php echo ($order_by == 'name') ? 'selected' : ''; ?>>Nom</option>
|
<option value="name" <?php echo ($order_by == 'name') ? 'selected' : ''; ?>>Nom</option>
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<button type="submit">Filtrer</button>
|
<button type="submit">Filtrer</button>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<section class="list">
|
<section class="list">
|
||||||
|
<?php if (empty($albums)): ?>
|
||||||
|
<p>Aucun album trouvé pour cette sélection.</p>
|
||||||
|
<?php else: ?>
|
||||||
<?php foreach($albums as $album): ?>
|
<?php foreach($albums as $album): ?>
|
||||||
<div>
|
<div>
|
||||||
<article>
|
<article>
|
||||||
@ -40,33 +42,35 @@
|
|||||||
<footer class="short-text"><?php echo $album->year; ?> - <?php echo $album->artistName; ?>
|
<footer class="short-text"><?php echo $album->year; ?> - <?php echo $album->artistName; ?>
|
||||||
<?php if ($this->session->userdata('user_id')): ?>
|
<?php if ($this->session->userdata('user_id')): ?>
|
||||||
<?php if (!empty($user_playlists)): ?>
|
<?php if (!empty($user_playlists)): ?>
|
||||||
<br><br><select id="playlist_<?php echo $album->id; ?>" class="select-playlist">
|
<br><br>
|
||||||
<?php foreach ($user_playlists as $playlist) : ?>
|
<select id="playlist_<?php echo $album->id; ?>" class="select-playlist">
|
||||||
<option value="<?php echo $playlist->id; ?>"><?php echo $playlist->name; ?></option>
|
<?php foreach ($user_playlists as $playlist) : ?>
|
||||||
<?php endforeach; ?>
|
<option value="<?php echo $playlist->id; ?>"><?php echo $playlist->name; ?></option>
|
||||||
</select>
|
<?php endforeach; ?>
|
||||||
<button onclick="addToPlaylist(<?php echo $album->id; ?>)" class="btn-add-to-playlist">Ajouter l'album à la playlist</button>
|
</select>
|
||||||
|
<button onclick="addToPlaylist(<?php echo $album->id; ?>)" class="btn-add-to-playlist">Ajouter l'album à la playlist</button>
|
||||||
|
<?php endif; ?>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
<?php endif; ?>
|
</footer>
|
||||||
</footer>
|
|
||||||
</article>
|
</article>
|
||||||
</div>
|
</div>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
</section>
|
<?php endif; ?>
|
||||||
|
</section>
|
||||||
|
|
||||||
<div class="pagination">
|
<div class="pagination">
|
||||||
<?php if ($current_page > 1): ?>
|
<?php if ($current_page > 1): ?>
|
||||||
<a class="fleche" href="<?php echo base_url('index.php/albums/index/'.($current_page-1).'?order_by='.$order_by.'&genre_id='.$genre_id.'&artist_id='.$artist_id); ?>"><</a>
|
<a class="fleche" href="<?php echo base_url('index.php/albums/index/'.($current_page-1).'?order_by='.$order_by.'&genre_id='.$genre_id.'&artist_id='.$artist_id); ?>"><</a>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
|
||||||
<?php for ($i = max(1, $current_page - 2); $i <= min($total_pages, $current_page + 2); $i++): ?>
|
<?php for ($i = max(1, $current_page - 2); $i <= min($total_pages, $current_page + 2); $i++): ?>
|
||||||
<a href="<?php echo base_url('index.php/albums/index/'.$i.'?order_by='.$order_by.'&genre_id='.$genre_id.'&artist_id='.$artist_id); ?>" <?php echo ($i == $current_page) ? 'class="active"' : ''; ?>><?php echo $i; ?></a>
|
<a href="<?php echo base_url('index.php/albums/index/'.$i.'?order_by='.$order_by.'&genre_id='.$genre_id.'&artist_id='.$artist_id); ?>" <?php echo ($i == $current_page) ? 'class="active"' : ''; ?>><?php echo $i; ?></a>
|
||||||
<?php endfor; ?>
|
<?php endfor; ?>
|
||||||
|
|
||||||
<?php if ($current_page < $total_pages): ?>
|
<?php if ($current_page < $total_pages): ?>
|
||||||
<a class="fleche" href="<?php echo base_url('index.php/albums/index/'.($current_page+1).'?order_by='.$order_by.'&genre_id='.$genre_id.'&artist_id='.$artist_id); ?>">></a>
|
<a class="fleche" href="<?php echo base_url('index.php/albums/index/'.($current_page+1).'?order_by='.$order_by.'&genre_id='.$genre_id.'&artist_id='.$artist_id); ?>">></a>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
<script>
|
<script>
|
||||||
function addToPlaylist(albumId) {
|
function addToPlaylist(albumId) {
|
||||||
@ -76,4 +80,4 @@
|
|||||||
// Redirection vers la méthode du contrôleur Playlists pour ajouter la chanson à la playlist spécifiée
|
// Redirection vers la méthode du contrôleur Playlists pour ajouter la chanson à la playlist spécifiée
|
||||||
window.location.href = "<?php echo base_url('index.php/playlists/add_album_to_playlist/'); ?>" + albumId + "/" + playlistId;
|
window.location.href = "<?php echo base_url('index.php/playlists/add_album_to_playlist/'); ?>" + albumId + "/" + playlistId;
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
Loading…
Reference in New Issue
Block a user