mirror of
https://grond.iut-fbleau.fr/stiti/SAE_2.02
synced 2024-11-12 22:01:41 +01:00
Ajout des ajouts
This commit is contained in:
parent
9dccb394e4
commit
fc4a71158c
@ -6,8 +6,10 @@ class Albums extends CI_Controller {
|
||||
public function __construct(){
|
||||
parent::__construct();
|
||||
$this->load->model('model_music');
|
||||
$this->load->model('Model_playlist');
|
||||
$this->load->helper('url');
|
||||
$this->load->helper('html');
|
||||
$this->load->library('session');
|
||||
}
|
||||
|
||||
public function index($page = 1){
|
||||
@ -22,6 +24,11 @@ class Albums extends CI_Controller {
|
||||
$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);
|
||||
|
||||
if ($this->session->userdata('user_id')) {
|
||||
$user_id = $this->session->userdata('user_id');
|
||||
$data['user_playlists'] = $this->Model_playlist->get_user_playlists($user_id);
|
||||
}
|
||||
|
||||
$data['total_pages'] = ceil($total_albums / $limit);
|
||||
$data['current_page'] = $page;
|
||||
$data['albums'] = $albums;
|
||||
|
@ -6,9 +6,11 @@ class Musiques extends CI_Controller {
|
||||
public function __construct(){
|
||||
parent::__construct();
|
||||
$this->load->model('Model_music');
|
||||
$this->load->model('Model_playlist');
|
||||
$this->load->library('pagination');
|
||||
$this->load->helper('url');
|
||||
$this->load->helper('html');
|
||||
$this->load->library('session');
|
||||
}
|
||||
|
||||
public function index($page = 1){
|
||||
@ -31,6 +33,11 @@ class Musiques extends CI_Controller {
|
||||
$genres = $this->Model_music->getGenres();
|
||||
$artists = $this->Model_music->getArtists();
|
||||
|
||||
if ($this->session->userdata('user_id')) {
|
||||
$user_id = $this->session->userdata('user_id');
|
||||
$data['user_playlists'] = $this->Model_playlist->get_user_playlists($user_id);
|
||||
}
|
||||
|
||||
$data['musiques'] = $musiques;
|
||||
$data['total_pages'] = $total_pages;
|
||||
$data['current_page'] = $current_page;
|
||||
|
@ -258,6 +258,25 @@ class Playlists extends CI_Controller {
|
||||
$this->load->view('layout/footer_dark');
|
||||
}
|
||||
}
|
||||
|
||||
public function add_album_to_playlist($album_id, $playlist_id) {
|
||||
// Vérifiez si l'utilisateur est connecté
|
||||
if (!$this->session->userdata('user_id')) {
|
||||
redirect('utilisateur/connexion');
|
||||
}
|
||||
|
||||
// Ajouter toutes les chansons de l'album à la playlist spécifiée
|
||||
$songs = $this->Model_music->get_songs_by_album($album_id);
|
||||
foreach ($songs as $song) {
|
||||
$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 view($playlist_id) {
|
||||
// Vérifiez si la playlist est accessible à l'utilisateur actuellement connecté
|
||||
@ -295,6 +314,23 @@ class Playlists extends CI_Controller {
|
||||
redirect('erreur/page_non_autorisee');
|
||||
}
|
||||
}
|
||||
|
||||
public function add_music_to_playlist($music_id, $playlist_id) {
|
||||
// Vérifiez si l'utilisateur est connecté
|
||||
if (!$this->session->userdata('user_id')) {
|
||||
redirect('utilisateur/connexion');
|
||||
}
|
||||
|
||||
// Ajoutez la musique à la playlist spécifiée
|
||||
$data = array(
|
||||
'playlist_id' => $playlist_id,
|
||||
'song_id' => $music_id // Utilisez 'song_id' au lieu de 'music_id'
|
||||
);
|
||||
$this->Model_playlist->add_song_to_playlist($data);
|
||||
|
||||
// Redirigez l'utilisateur vers la vue de la playlist
|
||||
redirect('playlists/view/' . $playlist_id);
|
||||
}
|
||||
|
||||
|
||||
public function add_artist($playlist_id) {
|
||||
|
@ -54,6 +54,7 @@ class Model_playlist extends CI_Model {
|
||||
|
||||
return $this->db->insert('playlist_song', $data);
|
||||
}
|
||||
|
||||
|
||||
public function song_exists_in_playlist($playlist_id, $song_id) {
|
||||
$this->db->where('playlist_id', $playlist_id);
|
||||
|
@ -38,6 +38,14 @@
|
||||
</header>
|
||||
<img src="data:image/jpeg;base64,<?php echo base64_encode($album->jpeg); ?>" alt="<?php echo $album->name; ?>">
|
||||
<footer class="short-text"><?php echo $album->year; ?> - <?php echo $album->artistName; ?></footer>
|
||||
<?php if ($this->session->userdata('user_id')): ?>
|
||||
<select id="playlist_<?php echo $album->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="addToPlaylist(<?php echo $album->id; ?>)" class="btn-add-to-playlist">Ajouter l'album à la playlist</button>
|
||||
<?php endif; ?>
|
||||
</article>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
@ -57,3 +65,12 @@
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</body>
|
||||
<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>
|
||||
|
@ -52,6 +52,16 @@
|
||||
<!-- Lien YouTube -->
|
||||
<a href="https://www.youtube.com/results?search_query=<?php echo urlencode($musique->name . ' ' . $musique->artistName); ?>" class="youtube" target="_blank">YouTube</a>
|
||||
</div>
|
||||
|
||||
<?php if ($this->session->userdata('user_id')): ?>
|
||||
<select id="playlist_music_<?php echo $musique->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 $musique->id; ?>)" class="btn-add-to-playlist">Ajouter la musique à la playlist</button>
|
||||
<?php endif; ?>
|
||||
|
||||
</footer>
|
||||
</article>
|
||||
</div>
|
||||
@ -72,3 +82,12 @@
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</body>
|
||||
<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>
|
||||
|
@ -198,3 +198,28 @@ footer.short-text {
|
||||
flex-direction: column;
|
||||
align-items: center; /* Center the items vertically */
|
||||
}
|
||||
|
||||
/* Style pour la liste déroulante */
|
||||
.select-playlist {
|
||||
padding: 8px 15px; /* Rembourrage intérieur */
|
||||
font-size: 16px; /* Taille de la police */
|
||||
border: 1px solid #ccc; /* Bordure */
|
||||
border-radius: 4px; /* Coins arrondis */
|
||||
background-color: #f0f0f0;
|
||||
margin-right: 10px; /* Marge à droite pour l'espace entre la liste déroulante et le bouton */
|
||||
}
|
||||
|
||||
/* Style pour le bouton Ajouter à la playlist */
|
||||
.btn-add-to-playlist {
|
||||
background-color: #6021aa; /* Couleur de fond */
|
||||
color: white; /* Couleur du texte */
|
||||
padding: 10px 20px; /* Rembourrage intérieur */
|
||||
border: none; /* Pas de bordure */
|
||||
border-radius: 4px; /* Coins arrondis */
|
||||
cursor: pointer; /* Curseur pointeur au survol */
|
||||
transition: background-color 0.3s; /* Animation de transition */
|
||||
}
|
||||
|
||||
.btn-add-to-playlist:hover {
|
||||
background-color: #461860; /* Couleur de fond au survol */
|
||||
}
|
||||
|
@ -190,3 +190,35 @@ header.short-text a {
|
||||
color: #fff;
|
||||
transition: background-color 0.3s ease;
|
||||
}
|
||||
|
||||
/* Style pour la liste déroulante */
|
||||
.select-playlist {
|
||||
padding: 8px 15px; /* Rembourrage intérieur */
|
||||
font-size: 16px; /* Taille de la police */
|
||||
border: 1px solid #ccc; /* Bordure */
|
||||
border-radius: 4px; /* Coins arrondis */
|
||||
background-color: #f0f0f0;
|
||||
}
|
||||
|
||||
/* Style pour les options de la liste déroulante */
|
||||
.select-playlist option {
|
||||
padding: 8px 15px; /* Rembourrage intérieur */
|
||||
font-size: 16px; /* Taille de la police */
|
||||
background-color: #fff; /* Couleur de fond */
|
||||
color: #333; /* Couleur du texte */
|
||||
}
|
||||
|
||||
/* Style pour le bouton Ajouter à la playlist */
|
||||
.btn-add-to-playlist {
|
||||
background-color: #6021aa; /* Couleur de fond */
|
||||
color: white; /* Couleur du texte */
|
||||
padding: 10px 20px; /* Rembourrage intérieur */
|
||||
border: none; /* Pas de bordure */
|
||||
border-radius: 4px; /* Coins arrondis */
|
||||
cursor: pointer; /* Curseur pointeur au survol */
|
||||
transition: background-color 0.3s; /* Animation de transition */
|
||||
}
|
||||
|
||||
.btn-add-to-playlist:hover {
|
||||
background-color: #461860; /* Couleur de fond au survol */
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user