possibilité de supprimer une chansons d'une playlist
This commit is contained in:
@@ -52,7 +52,33 @@ class Chansons extends CI_Controller {
|
|||||||
}else{
|
}else{
|
||||||
$playlistId = $this->input->post('playlist_id');
|
$playlistId = $this->input->post('playlist_id');
|
||||||
$this->model_music->AddSongtoPlaylist($playlistId,$id);
|
$this->model_music->AddSongtoPlaylist($playlistId,$id);
|
||||||
|
redirect('chansons');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function deleteSongtoPlaylist($id){
|
||||||
|
$playlists = $this->model_music->getPlaylistIdSong($id);
|
||||||
|
|
||||||
|
$this->form_validation->set_rules('playlist_id', 'playlist_id', 'required');
|
||||||
|
|
||||||
|
if ($this->form_validation->run() == FALSE){
|
||||||
|
$this->load->view('layout/header');
|
||||||
|
$this->load->view('deleteSongtoplaylist', ["playlists" => $playlists]);
|
||||||
|
$this->load->view('layout/footer');
|
||||||
|
}else{
|
||||||
|
$playlistId = $this->input->post('playlist_id');
|
||||||
|
$this->model_music->DeleteSongtoPlaylist($playlistId,$id);
|
||||||
|
redirect('chansons');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function view($id){
|
||||||
|
$chansons = $this->model_music->get_song_playlist($id);
|
||||||
|
$data['chansons'] = $chansons;
|
||||||
|
|
||||||
|
$this->load->view('layout/header');
|
||||||
|
$this->load->view('chansons_list',$data);
|
||||||
|
$this->load->view('layout/footer');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -237,7 +237,7 @@ class Model_music extends CI_Model {
|
|||||||
|
|
||||||
$album->tracks = [];
|
$album->tracks = [];
|
||||||
foreach ($songIds as $song) {
|
foreach ($songIds as $song) {
|
||||||
$this->db->select('song.name as songName, track.duration');
|
$this->db->select('song.name as songName, track.duration, track.Id as trackId');
|
||||||
$this->db->from('track');
|
$this->db->from('track');
|
||||||
$this->db->join('song', 'track.songId = song.id');
|
$this->db->join('song', 'track.songId = song.id');
|
||||||
$this->db->where('track.songId', $song->songId);
|
$this->db->where('track.songId', $song->songId);
|
||||||
@@ -313,6 +313,18 @@ class Model_music extends CI_Model {
|
|||||||
return $query = false;
|
return $query = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getPlaylistIdSong($id){
|
||||||
|
$query = $this->db->query(
|
||||||
|
"SELECT Playlist.name, Playlist.playlistid
|
||||||
|
FROM Playlist
|
||||||
|
JOIN PlaylistSong ON Playlist.playlistid = PlaylistSong.playlistid
|
||||||
|
WHERE PlaylistSong.trackId = $id
|
||||||
|
ORDER BY Playlist.name
|
||||||
|
"
|
||||||
|
);
|
||||||
|
return $query->result();
|
||||||
|
}
|
||||||
|
|
||||||
public function addPlayliste($playlist){
|
public function addPlayliste($playlist){
|
||||||
$this->db->insert("Playlist",$playlist);
|
$this->db->insert("Playlist",$playlist);
|
||||||
return $this->db->insert_id();
|
return $this->db->insert_id();
|
||||||
@@ -324,4 +336,40 @@ class Model_music extends CI_Model {
|
|||||||
"trackId"=> $trackId);
|
"trackId"=> $trackId);
|
||||||
$this->db->insert("PlaylistSong",$tupple);
|
$this->db->insert("PlaylistSong",$tupple);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function DeleteSongtoPlaylist($idplaylist, $trackId){
|
||||||
|
$tupple = array(
|
||||||
|
"playlistId"=> $idplaylist,
|
||||||
|
"trackId"=> $trackId);
|
||||||
|
$this->db->delete("PlaylistSong",$tupple);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_song_playlist($id){
|
||||||
|
$this->db->select('track.id as trackId, song.name,song.id,album.year,album.name as albumName, artist.name as artistName, genre.name as genreName');
|
||||||
|
$this->db->from('Playlist');
|
||||||
|
$this->db->join('PlaylistSong', 'PlaylistSong.playlistid = Playlist.playlistid');
|
||||||
|
$this->db->join('track', 'PlaylistSong.trackid = track.id');
|
||||||
|
$this->db->join('song', 'track.songId = song.id');
|
||||||
|
$this->db->join('album', 'album.id = track.albumId');
|
||||||
|
$this->db->join('artist', 'album.artistId = artist.Id');
|
||||||
|
$this->db->join('genre', 'genre.id = album.genreid');
|
||||||
|
$query = $this->db->get();
|
||||||
|
return $query->result();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function SongInPlaylist($id){
|
||||||
|
$query = $this->db->query(
|
||||||
|
"SELECT PlaylistSong.trackId, Playlist.playlistId
|
||||||
|
FROM Playlist
|
||||||
|
JOIN PlaylistSong ON Playlist.playlistid = PlaylistSong.playlistid
|
||||||
|
WHERE PlaylistSong.trackid = $id
|
||||||
|
ORDER BY Playlist.name
|
||||||
|
"
|
||||||
|
);
|
||||||
|
$query->result();
|
||||||
|
if ($query->num_rows() > 0){
|
||||||
|
return $query = true;
|
||||||
|
}
|
||||||
|
return $query = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
<div class="playlist-option">
|
<div class="playlist-option">
|
||||||
<label>
|
<label>
|
||||||
<input type="radio" name="playlist_id" value="<?= $playlist->playlistid ?>">
|
<input type="radio" name="playlist_id" value="<?= $playlist->playlistid ?>">
|
||||||
<?= htmlspecialchars($playlist->name) ?>
|
<?= $playlist->name ?>
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
|
|||||||
@@ -35,12 +35,22 @@
|
|||||||
$artistName = $albums->artist->name;
|
$artistName = $albums->artist->name;
|
||||||
$duration = isset($albums->tracks[$index]->duration) ? convertirSecondesEnMinutes($albums->tracks[$index]->duration) : '';
|
$duration = isset($albums->tracks[$index]->duration) ? convertirSecondesEnMinutes($albums->tracks[$index]->duration) : '';
|
||||||
echo "<td>{$songName}</td>";
|
echo "<td>{$songName}</td>";
|
||||||
|
|
||||||
echo "<th></th>";
|
echo "<th></th>";
|
||||||
echo "<th></th>";
|
echo "<th></th>";
|
||||||
echo "<th></th>";
|
echo "<th></th>";
|
||||||
echo "<th></th>";
|
echo "<th></th>";
|
||||||
echo "<th></th>";
|
echo "<th></th>";
|
||||||
|
if ($this->session->userdata('logged_in')){
|
||||||
|
if($this->model_music->SongInPlaylist($albums->tracks[$index]->trackId)){
|
||||||
|
echo "<td>";
|
||||||
|
echo anchor("chansons/deleteSongtoPlaylist/{$albums->tracks[$index]->trackId}","<i class='fa-solid fa-trash'></i>");
|
||||||
|
echo "</td>";
|
||||||
|
}
|
||||||
|
echo "<td>";
|
||||||
|
echo anchor("chansons/addSongtoPlaylist/{$albums->tracks[$index]->trackId}","<i class='fa fa-plus'></i>");
|
||||||
|
echo "</td>";
|
||||||
|
}
|
||||||
echo "<th></th>";
|
echo "<th></th>";
|
||||||
echo "<th></th>";
|
echo "<th></th>";
|
||||||
echo "<th></th>";
|
echo "<th></th>";
|
||||||
|
|||||||
@@ -148,7 +148,10 @@ foreach($chansons as $chanson){
|
|||||||
echo "<header class='short-text'>";
|
echo "<header class='short-text'>";
|
||||||
echo anchor("chansons/view/{$chanson->id}","{$chanson->name}");
|
echo anchor("chansons/view/{$chanson->id}","{$chanson->name}");
|
||||||
if($this->session->userdata('logged_in')){
|
if($this->session->userdata('logged_in')){
|
||||||
echo anchor("chansons/addSongtoPlaylist/{$chanson->trackId}","<i class='fa fa-plus'></i>");
|
if($this->model_music->SongInPlaylist($chanson->trackId)){
|
||||||
|
echo anchor("chansons/deleteSongtoPlaylist/{$chanson->trackId}","<i class='fa-solid fa-trash'></i>");
|
||||||
|
}
|
||||||
|
echo anchor("chansons/addSongtoPlaylist/{$chanson->trackId}","<i class='fa fa-plus'></i>");
|
||||||
}
|
}
|
||||||
echo "</header>";
|
echo "</header>";
|
||||||
echo "<nav class='short-text'>Nom album: {$chanson->albumName}</nav>";
|
echo "<nav class='short-text'>Nom album: {$chanson->albumName}</nav>";
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
<title>Supprimer une chanson à une playlist</title>
|
||||||
|
|
||||||
|
<div class="trie">
|
||||||
|
<h5>Playlists</h5>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<section class="list">
|
||||||
|
|
||||||
|
<form method="post">
|
||||||
|
<?php foreach ($playlists as $playlist): ?>
|
||||||
|
<div class="playlist-option">
|
||||||
|
<label>
|
||||||
|
<input type="radio" name="playlist_id" value="<?= $playlist->playlistid ?>">
|
||||||
|
<?= $playlist->name ?>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
<div class="submit-button">
|
||||||
|
<button type="submit" class="btn btn-primary">Supprimer de la playlist</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -7,7 +7,7 @@ echo"</div>";
|
|||||||
foreach($playlists as $playlist){
|
foreach($playlists as $playlist){
|
||||||
echo "<div><article>";
|
echo "<div><article>";
|
||||||
echo "<header class='short-text'>";
|
echo "<header class='short-text'>";
|
||||||
echo anchor("playlist/view/{$playlist->playlistid}","{$playlist->name}");
|
echo anchor("chansons/view/{$playlist->playlistid}","{$playlist->name}");
|
||||||
echo "</header>";
|
echo "</header>";
|
||||||
echo "</article></div>";
|
echo "</article></div>";
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user