Ajout de la musique

This commit is contained in:
stiti 2024-05-22 22:05:48 +02:00
parent caa8210c75
commit 6948cc21ab
8 changed files with 138 additions and 33 deletions

View File

@ -13,7 +13,8 @@ class Artiste extends CI_Controller {
public function index($artiste_id){
// Récupérer les détails de l'artiste
$artiste = $this->Model_artist->getArtisteById($artiste_id);
$mostUsedGenre = $this->Model_music->getMostUsedGenreByArtist($artiste_id); // Correction ici
if($artiste){
// Récupérer tous les albums de l'artiste
$albums = $this->Model_music->getAlbumsByArtiste($artiste_id);
@ -21,6 +22,7 @@ class Artiste extends CI_Controller {
// Charger la vue avec les détails de l'artiste et ses albums
$data['artiste'] = $artiste;
$data['albums'] = $albums;
$data['mostUsedGenre'] = $mostUsedGenre; // Passer $mostUsedGenre à la vue
$this->load->view('layout/header_not_logged_dark');
$this->load->view('artiste_details', $data);
$this->load->view('layout/footer_dark');
@ -29,6 +31,7 @@ class Artiste extends CI_Controller {
show_404();
}
}
public function list_artists(){
// Récupérer le paramètre de tri (croissant ou decroissant)

View File

@ -11,17 +11,29 @@ class Musiques extends CI_Controller {
}
public function index($page = 1){
$limit = 30; // Nombre de musiques par page
// Nombre de musiques par page
$limit = 30;
// Calcul de l'offset pour la pagination
$offset = ($page - 1) * $limit;
$musiques = $this->Model_music->getMusiques($limit, $offset);
// Récupérer la valeur de tri depuis la requête GET
$sort = $this->input->get('sort');
// Récupérer les musiques triées
$musiques = $this->Model_music->getMusiques($limit, $offset, $sort);
// Récupérer le nombre total de musiques pour la pagination
$total_musiques = $this->Model_music->get_total_musiques();
$data['total_pages'] = ceil($total_musiques / $limit); // Calcul du nombre total de pages
$data['current_page'] = $page; // Définition de la variable $current_page
// Calculer le nombre total de pages
$total_pages = ceil($total_musiques / $limit);
// Définition de la variable $current_page
$current_page = $page;
// Données à passer à la vue
$data['musiques'] = $musiques;
$data['total_pages'] = $total_pages;
$data['current_page'] = $current_page;
$data['sort'] = $sort; // Passer la valeur de tri à la vue
// Charger la vue
$this->load->view('layout/header_not_logged_dark');
@ -29,6 +41,4 @@ class Musiques extends CI_Controller {
$this->load->view('layout/footer_dark');
}
}
?>

View File

@ -14,4 +14,3 @@ class Cover_model extends CI_Model {
return $result->result_array();
}
}
?>

View File

@ -97,7 +97,23 @@ class Model_music extends CI_Model {
return $album;
}
public function getMusiques($limit, $offset) {
public function getMusiques($limit, $offset, $order_by = 'title', $order_direction = 'ASC') {
$order_column = '';
switch ($order_by) {
case 'artist':
$order_column = 'artist.name';
break;
case 'album':
$order_column = 'album.name';
break;
case 'title':
$order_column = 'song.name';
break;
default:
$order_column = 'song.name';
break;
}
$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
FROM song
@ -105,11 +121,12 @@ class Model_music extends CI_Model {
JOIN album ON track.albumid = album.id
JOIN artist ON album.artistid = artist.id
JOIN cover ON album.coverid = cover.id
ORDER BY $order_column $order_direction
LIMIT $limit OFFSET $offset"
);
return $query->result();
}
public function get_total_musiques(){
$query = $this->db->query("SELECT COUNT(*) as total_musiques FROM song");
@ -119,14 +136,60 @@ class Model_music extends CI_Model {
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
SELECT album.id, album.name, album.year, artist.name as artistName, genre.name as genreName, cover.jpeg,
track.id as track_id, track.diskNumber, track.number, track.duration, song.name as songName
FROM album
JOIN artist ON album.artistid = artist.id
JOIN genre ON album.genreid = genre.id
JOIN cover ON album.coverid = cover.id
JOIN track ON track.albumid = album.id
JOIN song ON track.songid = song.id
WHERE artist.id = ?
ORDER BY album.id, track.diskNumber, track.number
", array($artiste_id));
return $query->result();
$result = $query->result();
// Organiser les résultats par album
$albums = array();
foreach ($result as $row) {
$album_id = $row->id;
if (!isset($albums[$album_id])) {
$albums[$album_id] = (object)array(
'id' => $row->id,
'name' => $row->name,
'year' => $row->year,
'artistName' => $row->artistName,
'genreName' => $row->genreName,
'jpeg' => $row->jpeg,
'tracks' => array() // Initialiser un tableau pour les pistes de l'album
);
}
// Ajouter la piste à l'album correspondant
$albums[$album_id]->tracks[] = (object)array(
'id' => $row->track_id,
'diskNumber' => $row->diskNumber,
'number' => $row->number,
'duration' => $row->duration,
'songName' => $row->songName
);
}
return array_values($albums); // Réorganiser les albums en utilisant des index numériques
}
public function getMostUsedGenreByArtist($artist_id) {
$query = $this->db->query("
SELECT genre.name as genreName, COUNT(*) as genreCount
FROM album
JOIN genre ON album.genreid = genre.id
WHERE album.artistid = ?
GROUP BY genre.name
ORDER BY genreCount DESC
LIMIT 1
", array($artist_id));
return $query->row();
}
}
?>

View File

@ -3,7 +3,7 @@
<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/style'); ?>">
<link rel="stylesheet" href="<?php echo base_url('assets/css/style.css'); ?>">
<link rel="icon" type="image/x-icon" href="<?php echo base_url('assets/img/Logo_ONZEUR.png'); ?>">
<title>Albums - Onzeur</title>
</head>

View File

@ -3,13 +3,13 @@
<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/artiste_details'); ?>">
<link rel="stylesheet" href="<?php echo base_url('assets/css/artiste_details.css'); ?>">
<title>Détails de l'artiste <?php echo $artiste->name; ?></title>
</head>
<body>
<div class="artist-details">
<h1>Détails de l'artiste <?php echo $artiste->name; ?></h1>
<p><strong>Genre le plus utilisé :</strong> <?php echo $mostUsedGenre->genreName; ?></p>
<h2>Albums de <?php echo $artiste->name; ?></h2>
<ul class="albums-list">
<?php foreach($albums as $album): ?>
@ -23,6 +23,17 @@
<?php else: ?>
<span class="no-cover">Aucune couverture disponible</span>
<?php endif; ?>
<!-- Liste des musiques de l'album -->
<ul class="songs-list">
<?php foreach($album->tracks as $track): ?>
<li>
<span><?php echo $track->number . '.' . $track->diskNumber; ?></span>
<span><?php echo $track->songName; ?></span>
<span><?php echo gmdate("i:s", $track->duration); ?></span>
</li>
<?php endforeach; ?>
</ul>
</div>
</li>
<?php endforeach; ?>

View File

@ -2,35 +2,55 @@
<html lang="fr">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="<?php echo base_url('assets/css/musiques_list'); ?>">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Liste des Musiques - Onzeur</title>
<link rel="stylesheet" href="<?php echo base_url('assets/css/style'); ?>">
<link rel="icon" type="image/x-icon" href="<?php echo base_url('assets/img/Logo_ONZEUR.png'); ?>">
<title>Musiques - Onzeur</title>
</head>
<body>
<h1>Liste des musiques</h1>
<ul>
<h1 class="title">Liste des musiques</h1>
<div class="filters">
<form method="GET" action="<?php echo base_url('index.php/musiques/index'); ?>">
<label for="sort">Trier par:</label>
<select name="sort" id="sort">
<option value="name" <?php echo (isset($sort) && $sort == 'name') ? 'selected' : ''; ?>>Titre</option>
<option value="artist" <?php echo (isset($sort) && $sort == 'artist') ? 'selected' : ''; ?>>Artiste</option>
<option value="album" <?php echo (isset($sort) && $sort == 'album') ? 'selected' : ''; ?>>Album</option>
</select>
<button type="submit">Filtrer</button>
</form>
</div>
<section class="list">
<?php foreach($musiques as $musique): ?>
<li>
<strong>Titre:</strong> <?php echo $musique->name; ?> <br>
<strong>Artiste :</strong> <a href="<?php echo site_url('artiste/'.$musique->artist_id); ?>"><?php echo $musique->artistName; ?></a> <br>
<strong>Album:</strong> <a href="<?php echo base_url('index.php/albums/view/'.$musique->album_id); ?>"><?php echo $musique->album_name; ?></a> <br>
<img src="data:image/jpeg;base64,<?php echo base64_encode($musique->cover); ?>" alt="Couverture d'album"> <br>
</li>
<div>
<article>
<header class="short-text">
<?php echo $musique->name; ?>
</header>
<img src="data:image/jpeg;base64,<?php echo base64_encode($musique->cover); ?>" alt="Couverture de l'album">
<footer class="short-text">
<?php echo $musique->artistName; ?> - <?php echo $musique->album_name; ?>
</footer>
</article>
</div>
<?php endforeach; ?>
</ul>
</section>
<div class="pagination">
<?php if ($current_page > 1): ?>
<a class="fleche" href="<?php echo base_url('index.php/musiques/index/'.($current_page-1)); ?>"><</a>
<a class="fleche" href="<?php echo base_url('index.php/musiques/index/'.($current_page-1).((isset($sort)) ? '?sort='.$sort : '')); ?>"><</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/musiques/index/'.$i); ?>" <?php echo ($i == $current_page) ? 'class="active"' : ''; ?>><?php echo $i; ?></a>
<a href="<?php echo base_url('index.php/musiques/index/'.$i.((isset($sort)) ? '?sort='.$sort : '')); ?>" <?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/musiques/index/'.($current_page+1)); ?>">></a>
<a class="fleche" href="<?php echo base_url('index.php/musiques/index/'.($current_page+1).((isset($sort)) ? '?sort='.$sort : '')); ?>">></a>
<?php endif; ?>
</div>
</body>
</html>

View File

@ -62,7 +62,6 @@ footer.short-text {
/* Styles pour les liens hypertexte */
header.short-text a {
color: #fff; /* Blanc pour les liens */
text-decoration: none; /* Supprimer le soulignement */
}
/* Image styles */