From a27deb8ff491c1bf91bfe286f26d82962821bd39 Mon Sep 17 00:00:00 2001 From: gallego Date: Thu, 6 Jun 2024 10:59:12 +0200 Subject: [PATCH] duplicate --- ci/application/controllers/Playlist.php | 11 +++++++++++ ci/application/models/Model_music.php | 23 +++++++++++++++++++++++ ci/application/views/playlist_list.php | 5 ++++- 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/ci/application/controllers/Playlist.php b/ci/application/controllers/Playlist.php index 113845f..5a7acc6 100644 --- a/ci/application/controllers/Playlist.php +++ b/ci/application/controllers/Playlist.php @@ -64,6 +64,17 @@ class Playlist extends CI_Controller { $this->model_music->addSongToPlaylist($songName, $playlistId); redirect('playlist'); } + + public function duplicate($playlist_id){ + // Charger le modèle si ce n'est pas déjà fait + $this->load->model('model_music'); + + // Dupliquer la playlist avec l'ID spécifié + $this->model_music->duplicatePlaylist($playlist_id); + + // Rediriger l'utilisateur vers la page des playlists + redirect('playlist'); + } } diff --git a/ci/application/models/Model_music.php b/ci/application/models/Model_music.php index b71d35a..edd5f26 100644 --- a/ci/application/models/Model_music.php +++ b/ci/application/models/Model_music.php @@ -128,4 +128,27 @@ class Model_music extends CI_Model { ); } } + + public function duplicatePlaylist($playlist_id){ + // Récupérer les informations de la playlist à dupliquer + $playlist = $this->db->get_where('playlist', array('id' => $playlist_id))->row(); + + // Créer une nouvelle entrée pour la playlist avec les mêmes informations + $data = array( + 'name' => $playlist->name . ' (Copy)', + ); + + $this->db->insert('playlist', $data); + + // Récupérer l'ID de la nouvelle playlist + $new_playlist_id = $this->db->insert_id(); + + // Dupliquer les chansons de la playlist originale dans la nouvelle playlist + $this->db->query( + "INSERT INTO SongPlaylist (id, name) + SELECT ?, name + FROM SongPlaylist + WHERE id = ?", + array($new_playlist_id, $playlist_id)); + } } diff --git a/ci/application/views/playlist_list.php b/ci/application/views/playlist_list.php index c7b301c..49854fa 100644 --- a/ci/application/views/playlist_list.php +++ b/ci/application/views/playlist_list.php @@ -9,7 +9,10 @@ foreach($playlists as $playlist){ echo "
"; echo anchor("playlist/SongPlaylist/{$playlist->id}","

{$playlist->name}

"); echo "
"; - echo ""; + echo ""; + echo "
"; + echo "
"; + echo ""; echo "
"; echo "
"; echo "";