This commit is contained in:
stiti 2024-06-06 12:07:45 +02:00
parent fc16b575ed
commit 9693d4be20
4 changed files with 50 additions and 27 deletions

View File

@ -48,16 +48,19 @@ class Albums extends CI_Controller {
} }
public function view($id){ public function view($id){
$album = $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;
if ($this->session->userdata('user_id')) {
$user_id = $this->session->userdata('user_id');
$data['user_playlists'] = $this->Model_playlist->get_user_playlists($user_id);
}
$this->load->view('layout/header_dark', $data); $this->load->view('layout/header_dark', $data);
$this->load->view('album_view'); $this->load->view('album_view');
$this->load->view('layout/footer_dark'); $this->load->view('layout/footer_dark');
} }
} }
?> ?>

View File

@ -95,10 +95,10 @@ class Model_music extends CI_Model {
WHERE track.albumid = ? WHERE track.albumid = ?
ORDER BY track.diskNumber, track.number", array($id) ORDER BY track.diskNumber, track.number", array($id)
); );
$album->tracks = $query->result(); $tracks = $query->result();
} }
return $album; return [$album,$tracks];
} }
public function getMusiques($limit, $offset, $order_by = 'name', $order_direction = 'ASC', $genre_id = null, $artist_id = null) { public function getMusiques($limit, $offset, $order_by = 'name', $order_direction = 'ASC', $genre_id = null, $artist_id = null) {

View File

@ -1,22 +1,44 @@
<div class="album-details">
<h1><?php echo $album->name; ?></h1>
<p><strong>Artiste :</strong> <a href="<?php echo site_url('artiste/index/' . $album->artistId); ?>"><?php echo $album->artistName; ?></a></p>
<p><strong>Année :</strong> <?php echo $album->year; ?></p>
<p><strong>Genre :</strong> <a href="<?php echo base_url('index.php/musiques/index?genre_id='.$album->genreId); ?>"><?php echo $album->genreName; ?></a></p>
<img src="data:image/jpeg;base64,<?php echo base64_encode($album->jpeg); ?>" alt="Image d'album">
<div class="album-details"> <?php if ($this->session->userdata('user_id')): ?>
<h1><?php echo $album->name; ?></h1> <!-- Si l'utilisateur est connecté -->
<p><strong>Artiste :</strong> <a href="<?php echo site_url('artiste/index/' . $album->artistId); ?>"><?php echo $album->artistName; ?></a></p> <?php if (!empty($user_playlists)): ?>
<p><strong>Année :</strong> <?php echo $album->year; ?></p> <h2>Ajouter à la playlist :</h2>
<p><strong>Genre :</strong> <a href="<?php echo base_url('index.php/musiques/index?genre_id='.$album->genreId); ?>"><?php echo $album->genreName; ?></a></p> <select id="playlist_<?php echo $album->id; ?>" class="select-playlist">
<img src="data:image/jpeg;base64,<?php echo base64_encode($album->jpeg); ?>" alt="Image d'album"> <?php foreach ($user_playlists as $playlist) : ?>
<option value="<?php echo $playlist->id; ?>"><?php echo $playlist->name; ?></option>
<?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; ?> <?php endforeach; ?>
</ul> </select>
<button onclick="addToPlaylist(<?php echo $album->id; ?>)" class="btn-add-to-playlist">Ajouter à la playlist</button>
<?php else: ?> <?php else: ?>
<p>Aucune musique n'est disponible dans cette album...</p> <p>Vous n'avez pas encore de playlist. Créez-en une pour ajouter cet album !</p>
<?php endif; ?> <?php endif; ?>
</div> <?php endif; ?>
</body>
<?php if (!empty($tracks)): ?>
<h2>Musiques</h2>
<ul>
<?php foreach ($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>
<script>
function addToPlaylist(albumId) {
// Récupérer l'ID de la playlist sélectionnée
var playlistId = document.getElementById('playlist_' + albumId).value;
// 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;
}
</script>

View File

@ -1,13 +1,13 @@
<div class="artist-details"> <div class="artist-details">
<h1>Détails de l'artiste <?php echo $artiste->name; ?></h1> <h1>Détails de l'artiste <?php echo $artiste->name; ?></h1>
<p><strong>Genre le plus utilisé :</strong> <?php echo $mostUsedGenre->genreName; ?></p> <p><strong>Genre le plus utilisé par l'artiste :</strong> <?php echo $mostUsedGenre->genreName; ?></p>
<h2>Albums de <?php echo $artiste->name; ?></h2> <h2>Albums de <?php echo $artiste->name; ?></h2>
<ul class="albums-list"> <ul class="albums-list">
<?php foreach($albums as $album): ?> <?php foreach($albums as $album): ?>
<li> <li>
<div class="album-details"> <div class="album-details">
<h3><?php echo $album->name; ?></h3> <h2><a href="<?php echo site_url('albums/view/' . $album->id); ?>"><?php echo $album->name; ?></a></h2>
<p><strong>Année :</strong> <?php echo $album->year; ?></p> <p><strong>Année :</strong> <?php echo $album->year; ?></p>
<p><strong>Genre :</strong> <?php echo $album->genreName; ?></p> <p><strong>Genre :</strong> <?php echo $album->genreName; ?></p>
<?php if (!empty($album->jpeg)): ?> <?php if (!empty($album->jpeg)): ?>
@ -15,7 +15,6 @@
<?php else: ?> <?php else: ?>
<span class="no-cover">Aucune couverture disponible</span> <span class="no-cover">Aucune couverture disponible</span>
<?php endif; ?> <?php endif; ?>
<!-- Liste des musiques de l'album -->
<ul class="songs-list"> <ul class="songs-list">
<?php foreach($album->tracks as $track): ?> <?php foreach($album->tracks as $track): ?>
<li> <li>
@ -24,7 +23,6 @@
<span><strong><?php echo gmdate("i:s", $track->duration); ?></strong></span> <span><strong><?php echo gmdate("i:s", $track->duration); ?></strong></span>
</li> </li>
<?php endforeach; ?> <?php endforeach; ?>
</ul> </ul>
</div> </div>
</li> </li>