Commit de Louay : Correction de bugs

This commit is contained in:
stiti 2024-05-22 20:59:59 +02:00
parent 6fa5b60331
commit caa8210c75
8 changed files with 167 additions and 113 deletions

View File

@ -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');
}
}
?>

View File

@ -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();
}
}
?>

View File

@ -1,31 +0,0 @@
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="<?php echo base_url('assets/css/album_musiques'); ?>">
<title><?php echo $album->name; ?> - Musiques</title>
</head>
<body>
<div class="album-details">
<h1><?php echo $album->name; ?></h1>
<p><strong>Artiste :</strong> <?php echo $album->artistName; ?></p>
<p><strong>Année :</strong> <?php echo $album->year; ?></p>
<p><strong>Genre :</strong> <?php echo $album->genreName; ?></p>
<img src="data:image/jpeg;base64,<?php echo base64_encode($album->jpeg); ?>" alt="Image d'album">
<?php if (!empty($album->tracks)): ?>
<h2>Musiques</h2>
<ul>
<?php foreach ($album->tracks as $track): ?>
<li>
<strong><?php echo $track->diskNumber . '.' . $track->number; ?>:</strong> <?php echo $track->songName; ?> (<?php echo gmdate("i:s", $track->duration); ?>)
</li>
<?php endforeach; ?>
</ul>
<?php else: ?>
<p>Aucune musique n'est disponible dans cet album...</p>
<?php endif; ?>
</div>
</body>
</html>

View File

@ -1,10 +1,9 @@
<!-- application/views/album_view.php -->
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="<?php echo base_url('assets/css/album_view'); ?>">
<link rel="stylesheet" href="<?php echo base_url('assets/css/album_view.css'); ?>">
<title><?php echo $album->name; ?> - Details</title>
</head>
<body>

View File

@ -9,6 +9,35 @@
</head>
<body>
<h1 class="title">Listes des albums</h1>
<div class="filters">
<form method="GET" action="<?php echo base_url('index.php/albums/index'); ?>">
<label for="genre">Genre:</label>
<select name="genre_id" id="genre">
<option value="">Tous les genres</option>
<?php foreach($genres as $genre): ?>
<option value="<?php echo $genre->id; ?>" <?php echo ($genre->id == $genre_id) ? 'selected' : ''; ?>><?php echo $genre->name; ?></option>
<?php endforeach; ?>
</select>
<label for="artist">Artiste:</label>
<select name="artist_id" id="artist">
<option value="">Tous les artistes</option>
<?php foreach($artists as $artist): ?>
<option value="<?php echo $artist->id; ?>" <?php echo ($artist->id == $artist_id) ? 'selected' : ''; ?>><?php echo $artist->name; ?></option>
<?php endforeach; ?>
</select>
<label for="order_by">Trier par:</label>
<select name="order_by" id="order_by">
<option value="year" <?php echo ($order_by == 'year') ? 'selected' : ''; ?>>Année</option>
<option value="name" <?php echo ($order_by == 'name') ? 'selected' : ''; ?>>Nom</option>
</select>
<button type="submit">Filtrer</button>
</form>
</div>
<section class="list">
<?php foreach($albums as $album): ?>
<div>
@ -24,18 +53,17 @@
</section>
<div class="pagination">
<?php if ($current_page > 1): ?>
<a class="fleche" href="<?php echo base_url('index.php/albums/index/'.($current_page-1)); ?>"><</a>
<?php endif; ?>
<?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>
<?php endif; ?>
<?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>
<?php endfor; ?>
<?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); ?>" <?php echo ($i == $current_page) ? 'class="active"' : ''; ?>><?php echo $i; ?></a>
<?php endfor; ?>
<?php if ($current_page < $total_pages): ?>
<a class="fleche" href="<?php echo base_url('index.php/albums/index/'.($current_page+1)); ?>">></a>
<?php endif; ?>
</div>
<?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>
<?php endif; ?>
</div>
</body>
</html>

View File

@ -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;
}

View File

@ -76,3 +76,4 @@ body {
.artist-list .artist-details a:hover {
text-decoration: underline;
}

View File

@ -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;
}