ajout song d un album a une playlist + correction bug supprimer song playlist

This commit is contained in:
Wilfried BRIGITTE 2024-06-05 21:18:00 +02:00
parent ba57a3adc3
commit 831f05ca6b
5 changed files with 62 additions and 18 deletions

View File

@ -10,8 +10,9 @@ class Albums extends CI_Controller {
public function index(){ public function index(){
$albums = $this->model_music->getAlbums(); $albums = $this->model_music->getAlbums();
$playlists = $this->model_music->getPlaylist();
$this->load->view('layout/header'); $this->load->view('layout/header');
$this->load->view('albums_list', ['albums' => $albums]); $this->load->view('albums_list', ['albums' => $albums, 'playlists' => $playlists]);
$this->load->view('layout/footer'); $this->load->view('layout/footer');
} }
@ -25,5 +26,15 @@ class Albums extends CI_Controller {
$this->load->view('song_album_list', ['songs' => $songs, 'playlists' => $playlists]); $this->load->view('song_album_list', ['songs' => $songs, 'playlists' => $playlists]);
$this->load->view('layout/footer'); $this->load->view('layout/footer');
} }
public function addAllSongsToPlaylist(){
$album_id = $this->input->post('album_id');
$playlistId = $this->input->post('playlist');
$songs = $this->model_music->getSongOfAlbum($album_id);
foreach ($songs as $song) {
$this->model_music->addSongToPlaylist($song->name, $playlistId);
}
redirect('playlist');
}
} }
?> ?>

View File

@ -16,9 +16,20 @@ class artistes extends CI_Controller {
public function view($AlbumsOfArtistId){ public function view($AlbumsOfArtistId){
$AlbumsOfArtists = $this->model_music->getAlbumsOfArtist($AlbumsOfArtistId); $AlbumsOfArtists = $this->model_music->getAlbumsOfArtist($AlbumsOfArtistId);
$playlists = $this->model_music->getPlaylist();
$this->load->view('layout/header'); $this->load->view('layout/header');
$this->load->view('albums_artist_list',['AlbumsOfArtists'=>$AlbumsOfArtists]); $this->load->view('albums_artist_list', ['AlbumsOfArtists' => $AlbumsOfArtists, 'playlists' => $playlists, 'artist_id' => $AlbumsOfArtistId]);
$this->load->view('layout/footer'); $this->load->view('layout/footer');
} }
public function addAllSongsToPlaylist(){
$album_id = $this->input->post('album_id');
$playlistId = $this->input->post('playlist');
$songs = $this->model_music->getSongOfAlbum($album_id);
foreach ($songs as $song) {
$this->model_music->addSongToPlaylist($song->name, $playlistId);
}
redirect('playlist');
}
} }

View File

@ -50,8 +50,9 @@ class Model_music extends CI_Model {
} }
public function delete_Song($playlist_id,$Song_name){ public function delete_Song($playlist_id,$Song_name){
$Song_name = urldecode($Song_name);
$this->db->query( $this->db->query(
"DELETE FROM SongPlaylist Where id = ? AND name LIKE ?", "DELETE FROM SongPlaylist Where id = ? AND name=?",
array($playlist_id, $Song_name) array($playlist_id, $Song_name)
); );
} }

View File

@ -1,4 +1,3 @@
<section class="container"> <section class="container">
<?php <?php
foreach ($AlbumsOfArtists as $AlbumsOfArtist) { foreach ($AlbumsOfArtists as $AlbumsOfArtist) {
@ -10,6 +9,18 @@
echo '<img src="data:image/jpeg;base64,' . base64_encode($AlbumsOfArtist->jpeg) . '" alt="' . $AlbumsOfArtist->name . '" />'; echo '<img src="data:image/jpeg;base64,' . base64_encode($AlbumsOfArtist->jpeg) . '" alt="' . $AlbumsOfArtist->name . '" />';
echo "<footer class='short-text'>$AlbumsOfArtist->year</footer>"; echo "<footer class='short-text'>$AlbumsOfArtist->year</footer>";
// Ajout du formulaire pour ajouter toutes les chansons de l'album à une playlist
echo "<form action='" . base_url('index.php/albums/addAllSongsToPlaylist') . "' method='post'>";
echo "<input type='hidden' name='album_id' value='{$AlbumsOfArtist->id}'>";
echo "<select name='playlist'>";
foreach($playlists as $playlist){
echo "<option value='{$playlist->id}'>{$playlist->name}</option>";
}
echo "</select>";
echo "<button type='submit'>Ajouter toutes les chansons</button>";
echo "</form>";
echo "</article></div>"; echo "</article></div>";
} }
?> ?>

View File

@ -4,11 +4,21 @@
foreach($albums as $album){ foreach($albums as $album){
echo "<div class='album'><article>"; echo "<div class='album'><article>";
echo "<header class='album-title'>"; echo "<header class='album-title'>";
echo anchor("Song/view/{$album->id}", "{$album->name}"); echo anchor("albums/view/{$album->id}", "{$album->name}");
echo "</header>"; echo "</header>";
echo '<img src="data:image/jpeg;base64,' . base64_encode($album->jpeg) . '" alt="' . $album->name . '" />'; echo '<img src="data:image/jpeg;base64,' . base64_encode($album->jpeg) . '" alt="' . $album->name . '" />';
echo "<footer class='short-text'>{$album->year} - {$album->artistName}</footer>"; echo "<footer class='short-text'>{$album->year} - {$album->artistName}</footer>";
echo "<form action='" . base_url('index.php/albums/addAllSongsToPlaylist') . "' method='post'>";
echo "<input type='hidden' name='album_id' value='{$album->id}'>";
echo "<select name='playlist'>";
foreach($playlists as $playlist){
echo "<option value='{$playlist->id}'>{$playlist->name}</option>";
}
echo "</select>";
echo "<button type='submit'>Ajouter toutes les chansons</button>";
echo "</form>";
echo "</article></div>"; echo "</article></div>";
} }
?> ?>
</section> </section>