duplicate

This commit is contained in:
Julian GALLEGO 2024-06-06 10:59:12 +02:00
parent adcb08be5d
commit a27deb8ff4
3 changed files with 38 additions and 1 deletions

View File

@ -64,6 +64,17 @@ class Playlist extends CI_Controller {
$this->model_music->addSongToPlaylist($songName, $playlistId); $this->model_music->addSongToPlaylist($songName, $playlistId);
redirect('playlist'); 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');
}
} }

View File

@ -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));
}
} }

View File

@ -9,7 +9,10 @@ foreach($playlists as $playlist){
echo "<header class='short-text'>"; echo "<header class='short-text'>";
echo anchor("playlist/SongPlaylist/{$playlist->id}","<h3>{$playlist->name}</h3>"); echo anchor("playlist/SongPlaylist/{$playlist->id}","<h3>{$playlist->name}</h3>");
echo "<form action='" . base_url("index.php/playlist/delete/{$playlist->id}") . "' method='post'>"; echo "<form action='" . base_url("index.php/playlist/delete/{$playlist->id}") . "' method='post'>";
echo "<button type='submit' class='delete-button'>Delete</button>"; echo "<button type='submit' class='delete-button'>supprimer</button>";
echo "</form>";
echo "<form action='" . base_url("index.php/playlist/duplicate/{$playlist->id}") . "' method='post'>";
echo "<button type='submit' class='delete-button'>dupliquer</button>";
echo "</form>"; echo "</form>";
echo "</header>"; echo "</header>";
echo "</div>"; echo "</div>";