mirror of
https://grond.iut-fbleau.fr/stiti/SAE_2.02
synced 2024-12-26 17:02:18 +01:00
Commit de louay
This commit is contained in:
parent
9e6ac4de1b
commit
c38d1a0ed4
@ -341,6 +341,24 @@ class Playlists extends CI_Controller {
|
||||
|
||||
redirect('playlists/view/' . $playlist_id);
|
||||
}
|
||||
|
||||
public function add_track_to_playlist($track_id, $playlist_id) {
|
||||
// Vérifier si l'utilisateur est connecté
|
||||
if (!$this->session->userdata('user_id')) {
|
||||
redirect('utilisateur/connexion');
|
||||
}
|
||||
|
||||
// Récupérer le song_id à partir du track_id
|
||||
$song_id = $this->Model_playlist->get_song_id_by_track_id($track_id);
|
||||
|
||||
$data = array(
|
||||
'playlist_id' => $playlist_id,
|
||||
'song_id' => $song_id
|
||||
);
|
||||
$this->Model_playlist->add_song_to_playlist($data);
|
||||
|
||||
redirect('playlists/view/' . $playlist_id);
|
||||
}
|
||||
|
||||
|
||||
public function add_artist($playlist_id) {
|
||||
|
@ -121,6 +121,15 @@ class Model_playlist extends CI_Model {
|
||||
return $this->db->get()->result();
|
||||
}
|
||||
|
||||
public function get_song_id_by_track_id($track_id) {
|
||||
$this->db->select('songId');
|
||||
$this->db->from('track');
|
||||
$this->db->where('id', $track_id);
|
||||
$query = $this->db->get();
|
||||
$result = $query->row_array();
|
||||
return $result['songId'];
|
||||
}
|
||||
|
||||
public function add_album_to_playlist($data) {
|
||||
return $this->db->insert('playlist_album', $data);
|
||||
}
|
||||
|
@ -1,22 +1,21 @@
|
||||
<div class="artist-details">
|
||||
<h1>Détails de l'artiste <?php echo $artiste->name; ?></h1>
|
||||
<p><strong>Genre le plus utilisé par l'artiste :</strong> <?php echo $mostUsedGenre->genreName; ?></p>
|
||||
<h2>Albums de <?php echo $artiste->name; ?></h2>
|
||||
<ul class="albums-list">
|
||||
<?php foreach($albums as $album): ?>
|
||||
<li>
|
||||
<div class="album-details">
|
||||
<div class="artist-details">
|
||||
<h1>Détails de l'artiste <?php echo $artiste->name; ?></h1>
|
||||
<p><strong>Genre le plus utilisé par l'artiste :</strong> <?php echo $mostUsedGenre->genreName; ?></p>
|
||||
<h2>Albums de <?php echo $artiste->name; ?></h2>
|
||||
<ul class="albums-list">
|
||||
<?php foreach($albums as $album): ?>
|
||||
<li>
|
||||
<div class="album-details">
|
||||
<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>Genre :</strong> <?php echo $album->genreName; ?></p>
|
||||
<?php if (!empty($album->jpeg)): ?>
|
||||
<img src="data:image/jpeg;base64,<?php echo base64_encode($album->jpeg); ?>" alt="Couverture de l'album">
|
||||
<?php else: ?>
|
||||
<span class="no-cover">Aucune couverture disponible</span>
|
||||
<?php endif; ?>
|
||||
|
||||
<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>Genre :</strong> <?php echo $album->genreName; ?></p>
|
||||
<?php if (!empty($album->jpeg)): ?>
|
||||
<img src="data:image/jpeg;base64,<?php echo base64_encode($album->jpeg); ?>" alt="Couverture de l'album">
|
||||
<?php else: ?>
|
||||
<span class="no-cover">Aucune couverture disponible</span>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ($this->session->userdata('user_id')): ?>
|
||||
<?php if ($this->session->userdata('user_id')): ?>
|
||||
<!-- Si l'utilisateur est connecté -->
|
||||
<?php if (!empty($user_playlists)): ?>
|
||||
<h3>Ajouter l'album à la playlist :</h3>
|
||||
@ -25,33 +24,44 @@
|
||||
<option value="<?php echo $playlist->id; ?>"><?php echo $playlist->name; ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
<button onclick="addToPlaylist(<?php echo $album->id; ?>)" class="btn-add-to-playlist">Ajouter l'album à la playlist</button>
|
||||
<button onclick="addAllAlbumToPlaylist(<?php echo $album->id; ?>)" class="btn-add-to-playlist">Ajouter tout l'album à la playlist</button>
|
||||
<br>
|
||||
<!-- Boutons pour chaque chanson de l'album -->
|
||||
<h3>Ajouter une chanson à la playlist :</h3>
|
||||
<ul class="songs-list">
|
||||
<?php foreach($album->tracks as $track): ?>
|
||||
<li>
|
||||
<span><strong><?php echo $track->number . '.' . $track->diskNumber; ?></strong></span>
|
||||
<span><?php echo $track->songName; ?></span>
|
||||
<span><strong><?php echo gmdate("i:s", $track->duration); ?></strong></span>
|
||||
<button onclick="addSongToPlaylist(<?php echo $track->id; ?>, <?php echo $album->id; ?>)" class="btn-add-to-playlist">Ajouter à la playlist</button>
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
<?php else: ?>
|
||||
<p class="no-playlist">Vous n'avez pas encore de playlist. Créez-en une pour ajouter cet album !</p>
|
||||
<?php endif; ?>
|
||||
<?php endif; ?>
|
||||
<br>
|
||||
<ul class="songs-list">
|
||||
<?php foreach($album->tracks as $track): ?>
|
||||
<li>
|
||||
<span><strong><?php echo $track->number . '.' . $track->diskNumber; ?></strong></span>
|
||||
<span><?php echo $track->songName; ?></span>
|
||||
<span><strong><?php echo gmdate("i:s", $track->duration); ?></strong></span>
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
</div>
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
function addToPlaylist(albumId) {
|
||||
function addAllAlbumToPlaylist(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;
|
||||
}
|
||||
|
||||
function addSongToPlaylist(trackId, albumId) {
|
||||
// Récupérer l'ID de la playlist sélectionnée pour cet album
|
||||
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_track_to_playlist/'); ?>" + trackId + "/" + playlistId;
|
||||
}
|
||||
</script>
|
Loading…
Reference in New Issue
Block a user