mirror of
https://grond.iut-fbleau.fr/stiti/SAE_2.02
synced 2024-11-12 22:01:41 +01:00
Commit de louay
This commit is contained in:
parent
1c75469b90
commit
46674a1b05
@ -59,6 +59,38 @@ class Musiques extends CI_Controller {
|
||||
$this->load->view('layout/header_dark', $data);
|
||||
$this->load->view('musiques_list', $data);
|
||||
$this->load->view('layout/footer_dark');
|
||||
}
|
||||
}
|
||||
|
||||
public function view($song_id) {
|
||||
// Récupérer les détails de la musique
|
||||
$song = $this->Model_music->get_music_details($song_id);
|
||||
if (empty($song)) {
|
||||
show_404(); // Afficher une erreur 404 si la musique n'est pas trouvée
|
||||
return;
|
||||
}
|
||||
|
||||
// Récupérer les playlists de l'utilisateur s'il est connecté
|
||||
$user_playlists = array();
|
||||
if ($this->session->userdata('user_id')) {
|
||||
$user_id = $this->session->userdata('user_id');
|
||||
$user_playlists = $this->Model_playlist->get_user_playlists($user_id);
|
||||
}
|
||||
|
||||
// Assurez-vous que $song contient l'ID du genre avant de le passer à la vue
|
||||
$genre_id = isset($song->genre_id) ? $song->genre_id : null;
|
||||
|
||||
// Récupérer des musiques recommandées du même genre ou du même artiste
|
||||
$recommended_songs = $this->Model_music->get_recommended_songs($genre_id, $song->artist_id);
|
||||
|
||||
// Charger la vue avec les données récupérées
|
||||
$data['song'] = $song;
|
||||
$data['user_playlists'] = $user_playlists;
|
||||
$data['recommended_songs'] = $recommended_songs;
|
||||
$data['title'] = "Détails de la musique - Onzeur";
|
||||
$data['css'] = "assets/css/music_details.css";
|
||||
|
||||
$this->load->view('layout/header_dark', $data);
|
||||
$this->load->view('music_details', $data);
|
||||
$this->load->view('layout/footer_dark');
|
||||
}
|
||||
}
|
||||
|
@ -299,5 +299,53 @@ class Model_music extends CI_Model {
|
||||
$this->db->join('album', 'track.albumid = album.id');
|
||||
$this->db->where('album.artistid', $artist_id);
|
||||
return $this->db->get()->result();
|
||||
}
|
||||
|
||||
public function get_music_details($song_id) {
|
||||
// Requête pour récupérer les détails de la chanson
|
||||
$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_base64, track.duration
|
||||
FROM song
|
||||
JOIN track ON song.id = track.songid
|
||||
JOIN album ON track.albumid = album.id
|
||||
JOIN artist ON album.artistid = artist.id
|
||||
JOIN cover ON album.coverid = cover.id
|
||||
WHERE song.id = ?", array($song_id)
|
||||
);
|
||||
|
||||
return $query->row(); // Renvoie le résultat unique sous forme d'objet
|
||||
}
|
||||
|
||||
public function get_recommended_songs($genre_id, $artist_id, $limit = 3) {
|
||||
$where_clause = '';
|
||||
$params = array();
|
||||
|
||||
if ($genre_id) {
|
||||
$where_clause .= " WHERE genre.id = ?";
|
||||
$params[] = $genre_id;
|
||||
} elseif ($artist_id) {
|
||||
$where_clause .= " WHERE artist.id = ?";
|
||||
$params[] = $artist_id;
|
||||
}
|
||||
|
||||
// Requête pour récupérer des musiques recommandées en fonction du genre ou de l'artiste
|
||||
$query = $this->db->query("
|
||||
SELECT song.id, song.name, artist.id as artist_id, artist.name as artistName, album.id as album_id, album.name as album_name, cover.jpeg as cover_base64
|
||||
FROM song
|
||||
JOIN track ON song.id = track.songid
|
||||
JOIN album ON track.albumid = album.id
|
||||
JOIN artist ON album.artistid = artist.id
|
||||
JOIN cover ON album.coverid = cover.id
|
||||
JOIN genre ON album.genreid = genre.id
|
||||
$where_clause
|
||||
ORDER BY RAND()
|
||||
LIMIT $limit
|
||||
", $params);
|
||||
|
||||
|
||||
return $query->result();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
51
CodeIgniter-3.1.13/application/views/music_details.php
Normal file
51
CodeIgniter-3.1.13/application/views/music_details.php
Normal file
@ -0,0 +1,51 @@
|
||||
<div class="music-details">
|
||||
<?php if (!empty($song)) : ?>
|
||||
<h1><?php echo $song->name; ?></h1>
|
||||
<p><strong>Artiste :</strong> <a href="<?php echo site_url('artiste/index/' . $song->artist_id); ?>"><?php echo $song->artistName; ?></a></p>
|
||||
<p><strong>Album :</strong> <a href="<?php echo site_url('albums/view/' . $song->album_id); ?>"><?php echo $song->album_name; ?></a></p>
|
||||
<?php if (!empty($song->cover_base64)) : ?>
|
||||
<img src="data:image/jpeg;base64,<?php echo base64_encode($song->cover_base64); ?>" alt="Couverture de l'album">
|
||||
<?php endif; ?>
|
||||
<p><strong>Durée :</strong> <?php echo gmdate("i:s", $song->duration); ?></p>
|
||||
|
||||
<?php if ($this->session->userdata('user_id')): ?>
|
||||
<?php if (!empty($user_playlists)): ?>
|
||||
<select id="playlist_music_<?php echo $song->id; ?>" class="select-playlist">
|
||||
<?php foreach ($user_playlists as $playlist) : ?>
|
||||
<option value="<?php echo $playlist->id; ?>"><?php echo $playlist->name; ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
<button onclick="addToPlaylistMusic(<?php echo $song->id; ?>)" class="btn-add-to-playlist">Ajouter la musique à la playlist</button>
|
||||
<?php else: ?>
|
||||
<p>Vous n'avez pas encore de playlist. Créez-en une pour ajouter cette chanson !</p>
|
||||
<?php endif; ?>
|
||||
<?php endif; ?>
|
||||
<?php else: ?>
|
||||
<p>Aucune information sur la musique n'a été trouvée.</p>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if (!empty($recommended_songs)) : ?>
|
||||
<h2>Musiques recommandées</h2>
|
||||
<div class="recommended-songs">
|
||||
<?php foreach ($recommended_songs as $recommended_song) : ?>
|
||||
<div class="recommended-song">
|
||||
<a href="<?php echo site_url('music/details/' . $recommended_song->id); ?>">
|
||||
<img src="data:image/jpeg;base64,<?php echo base64_encode($recommended_song->cover_base64); ?>" alt="Cover">
|
||||
</a>
|
||||
<h3 class="titre"><a href="<?php echo site_url('musiques/view/' . $recommended_song->id); ?>"> <?php echo $recommended_song->name; ?></a></h3>
|
||||
<p><a href="<?php echo site_url('artiste/index/' . $recommended_song->artist_id); ?>"><?php echo $recommended_song->artistName; ?></a> - <a href="<?php echo site_url('albums/view/' . $recommended_song->album_id); ?>"><?php echo $recommended_song->album_name; ?></a></p>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
function addToPlaylistMusic(musiqueId) {
|
||||
// Récupérer l'ID de la playlist sélectionnée
|
||||
var playlistId = document.getElementById('playlist_music_' + musiqueId).value;
|
||||
|
||||
// Redirection vers la méthode du contrôleur Playlists pour ajouter la musique à la playlist spécifiée
|
||||
window.location.href = "<?php echo base_url('index.php/playlists/add_music_to_playlist/'); ?>" + musiqueId + "/" + playlistId;
|
||||
}
|
||||
</script>
|
89
CodeIgniter-3.1.13/assets/css/music_details.css
Normal file
89
CodeIgniter-3.1.13/assets/css/music_details.css
Normal file
@ -0,0 +1,89 @@
|
||||
/* Style général */
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
background-color: #f7f7f7;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.music-details {
|
||||
background-color: #fff;
|
||||
border-radius: 10px;
|
||||
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
|
||||
padding: 20px;
|
||||
margin: 20px auto;
|
||||
max-width: 600px;
|
||||
}
|
||||
|
||||
h1, h3 {
|
||||
margin: 0;
|
||||
color: #4a154b; /* Violet foncé */
|
||||
}
|
||||
|
||||
strong {
|
||||
color: #6a336a; /* Violet moyen */
|
||||
}
|
||||
|
||||
a {
|
||||
color: #880088; /* Violet */
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
a:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
p {
|
||||
margin: 5px 0;
|
||||
}
|
||||
|
||||
img {
|
||||
max-width: 100%;
|
||||
height: auto;
|
||||
border-radius: 5px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.select-playlist, .btn-add-to-playlist {
|
||||
padding: 5px 10px;
|
||||
border: none;
|
||||
border-radius: 5px;
|
||||
background-color: #880088; /* Violet */
|
||||
color: #fff;
|
||||
cursor: pointer;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.select-playlist {
|
||||
margin-right: 10px;
|
||||
}
|
||||
|
||||
.btn-add-to-playlist {
|
||||
transition: background-color 0.3s ease;
|
||||
}
|
||||
|
||||
.btn-add-to-playlist:hover {
|
||||
background-color: #660066; /* Violet foncé au survol */
|
||||
}
|
||||
|
||||
/* Section recommandée */
|
||||
.recommended-songs {
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
.recommended-song {
|
||||
border-bottom: 1px solid #ddd;
|
||||
padding: 10px 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.recommended-song img {
|
||||
width: 80px;
|
||||
height: 80px;
|
||||
margin-right: 10px;
|
||||
border-radius: 5px;
|
||||
}
|
||||
|
||||
.titre{
|
||||
margin-right: 10px;
|
||||
}
|
Loading…
Reference in New Issue
Block a user