From dfb10221deb926ef7477eb6a229b5531b718dbac Mon Sep 17 00:00:00 2001 From: stiti Date: Sat, 25 May 2024 15:44:57 +0200 Subject: [PATCH] Ajout des playlists --- .../application/controllers/Playlists.php | 180 ++++++++++++++++++ .../application/models/Model_music.php | 24 +++ .../application/models/Model_playlist.php | 71 +++++++ .../views/layout/header_logged_dark.php | 2 +- .../application/views/playlist_add_album.php | 24 +++ .../application/views/playlist_add_song.php | 24 +++ .../application/views/playlist_create.php | 24 +++ .../application/views/playlist_view.php | 54 ++++++ .../application/views/playlists_list.php | 43 +++++ .../assets/css/playlist_add_song.css | 60 ++++++ .../assets/css/playlist_create.css | 48 +++++ .../assets/css/playlist_view.css | 69 +++++++ .../assets/css/playlists_list.css | 118 ++++++++++++ 13 files changed, 740 insertions(+), 1 deletion(-) create mode 100644 CodeIgniter-3.1.13/application/controllers/Playlists.php create mode 100644 CodeIgniter-3.1.13/application/models/Model_playlist.php create mode 100644 CodeIgniter-3.1.13/application/views/playlist_add_album.php create mode 100644 CodeIgniter-3.1.13/application/views/playlist_add_song.php create mode 100644 CodeIgniter-3.1.13/application/views/playlist_create.php create mode 100644 CodeIgniter-3.1.13/application/views/playlist_view.php create mode 100644 CodeIgniter-3.1.13/application/views/playlists_list.php create mode 100644 CodeIgniter-3.1.13/assets/css/playlist_add_song.css create mode 100644 CodeIgniter-3.1.13/assets/css/playlist_create.css create mode 100644 CodeIgniter-3.1.13/assets/css/playlist_view.css create mode 100644 CodeIgniter-3.1.13/assets/css/playlists_list.css diff --git a/CodeIgniter-3.1.13/application/controllers/Playlists.php b/CodeIgniter-3.1.13/application/controllers/Playlists.php new file mode 100644 index 0000000..6d195e6 --- /dev/null +++ b/CodeIgniter-3.1.13/application/controllers/Playlists.php @@ -0,0 +1,180 @@ +load->model('Model_playlist'); + $this->load->model('Model_music'); + $this->load->helper('url'); + $this->load->helper('html'); + $this->load->library('session'); // Charger la bibliothèque de sessions + } + + public function index(){ + // Récupérer l'ID de l'utilisateur connecté depuis la session + $user_id = $this->session->userdata('user_id'); + + // Vérifier si l'utilisateur est connecté + if ($user_id) { + $data['playlists'] = $this->Model_playlist->get_user_playlists($user_id); + $this->load->view('layout/header_dark'); + $this->load->view('playlists_list', $data); + $this->load->view('layout/footer_dark'); + } else { + redirect('utilisateur/connexion'); + } + } + + + public function create() { + if ($this->input->post()) { + // Récupérer l'ID de l'utilisateur depuis la session + $user_id = $this->session->userdata('user_id'); + + // Vérifier si l'ID de l'utilisateur est présent + if($user_id) { + // Si l'ID de l'utilisateur est disponible, créer la playlist avec cet ID + $data = array( + 'name' => $this->input->post('name'), + 'description' => $this->input->post('description'), + 'utilisateur_id' => $user_id // Ajoutez l'ID de l'utilisateur + ); + $this->Model_playlist->create_playlist($data); + redirect('playlists'); + } else { + // Gérer le cas où l'ID de l'utilisateur est manquant + // Peut-être rediriger vers la page de connexion ou afficher un message d'erreur + redirect('utilisateur/connexion'); + } + } else { + $this->load->view('layout/header_dark'); + $this->load->view('playlist_create'); + $this->load->view('layout/footer_dark'); + } + } + + + + public function update($playlist_id) { + if ($this->input->post()) { + $data = array( + 'name' => $this->input->post('name'), + 'description' => $this->input->post('description') + ); + $this->Model_playlist->update_playlist($playlist_id, $data); + redirect('playlists/view/' . $playlist_id); + } else { + // Gérer le cas où les données POST ne sont pas disponibles + redirect('playlists/view/' . $playlist_id); + } + } + + + + public function add_song($playlist_id) { + if ($this->input->post()) { + $data = array( + 'playlist_id' => $playlist_id, + 'song_id' => $this->input->post('song_id') + ); + $this->Model_playlist->add_song_to_playlist($data); + redirect('playlists/view/' . $playlist_id); + } else { + // Récupérer toutes les musiques disponibles + $data['songs'] = $this->Model_music->get_all_songs(); + $data['playlist_id'] = $playlist_id; + $this->load->view('layout/header_dark'); + $this->load->view('playlist_add_song', $data); + $this->load->view('layout/footer_dark'); + } + } + + public function delete($playlist_id) { + $this->Model_playlist->delete_playlist($playlist_id); + redirect('playlists'); + } + + public function remove_song($playlist_id, $song_id) { + $this->Model_playlist->remove_song_from_playlist($playlist_id, $song_id); + redirect('playlists/view/' . $playlist_id); + } + + public function duplicate($playlist_id) { + $playlist = $this->Model_playlist->get_playlist_by_id($playlist_id); + $songs = $this->Model_playlist->get_songs_by_playlist($playlist_id); + + $new_playlist = array( + 'name' => $playlist->name . ' (Duplicate)', + 'description' => $playlist->description, + 'utilisateur_id' => $playlist->utilisateur_id + ); + + $this->Model_playlist->create_playlist($new_playlist); + $new_playlist_id = $this->db->insert_id(); + + foreach ($songs as $song) { + $data = array( + 'playlist_id' => $new_playlist_id, + 'song_id' => $song->id + ); + $this->Model_playlist->add_song_to_playlist($data); + } + + redirect('playlists'); + } + + public function generate_random() { + $songs = $this->Model_music->get_random_songs(10); // 10 chansons aléatoires + $new_playlist = array( + 'name' => 'Random Playlist ' . date('Y-m-d H:i:s'), + 'description' => 'A randomly generated playlist', + 'utilisateur_id' => $this->session->userdata('user_id') + ); + + $this->Model_playlist->create_playlist($new_playlist); + $new_playlist_id = $this->db->insert_id(); + + foreach ($songs as $song) { + $data = array( + 'playlist_id' => $new_playlist_id, + 'song_id' => $song->id + ); + $this->Model_playlist->add_song_to_playlist($data); + } + + redirect('playlists'); + } + + public function add_album($playlist_id) { + if ($this->input->post()) { + // Récupérer l'ID de l'album à partir du formulaire + $album_id = $this->input->post('album_id'); + + // Récupérer toutes les chansons de l'album + $songs = $this->Model_music->get_songs_by_album($album_id); + + // Ajouter chaque chanson à la playlist + 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); + } else { + // Récupérer tous les albums disponibles + $data['albums'] = $this->Model_music->get_all_albums(); + $data['playlist_id'] = $playlist_id; + $this->load->view('layout/header_dark'); + $this->load->view('playlist_add_album', $data); + $this->load->view('layout/footer_dark'); + } + } + + +} +?> diff --git a/CodeIgniter-3.1.13/application/models/Model_music.php b/CodeIgniter-3.1.13/application/models/Model_music.php index 580b88c..4f170fb 100644 --- a/CodeIgniter-3.1.13/application/models/Model_music.php +++ b/CodeIgniter-3.1.13/application/models/Model_music.php @@ -127,7 +127,31 @@ class Model_music extends CI_Model { return $query->result(); } + + public function get_all_songs() { + return $this->db->get('song')->result(); + } + + public function get_all_albums() { + return $this->db->get('album')->result(); + } + public function get_songs_by_album($album_id) { + $this->db->select('song.*'); + $this->db->from('track'); + $this->db->join('song', 'track.songid = song.id'); + $this->db->where('track.albumid', $album_id); + return $this->db->get()->result(); + } + + + public function get_random_songs($limit) { + $this->db->order_by('RAND()'); + $this->db->limit($limit); + return $this->db->get('song')->result(); + } + + public function get_total_musiques(){ $query = $this->db->query("SELECT COUNT(*) as total_musiques FROM song"); $result = $query->row(); diff --git a/CodeIgniter-3.1.13/application/models/Model_playlist.php b/CodeIgniter-3.1.13/application/models/Model_playlist.php new file mode 100644 index 0000000..7eea9ae --- /dev/null +++ b/CodeIgniter-3.1.13/application/models/Model_playlist.php @@ -0,0 +1,71 @@ +session->userdata('user_id'); + if ($user_id !== null) { + $data['utilisateur_id'] = $user_id; + return $this->db->insert('playlist', $data); + } else { + return false; + } + } + + + // Récupérer une playlist par ID + public function get_playlist_by_id($playlist_id) { + return $this->db->get_where('playlist', array('id' => $playlist_id))->row(); + } + + // Récupérer toutes les playlists d'un utilisateur spécifique + public function get_user_playlists($user_id) { + $this->db->where('utilisateur_id', $user_id); + return $this->db->get('playlist')->result(); + } + + + // Mettre à jour une playlist + public function update_playlist($playlist_id, $data) { + $this->db->where('id', $playlist_id); + return $this->db->update('playlist', $data); + } + + // Supprimer une playlist + public function delete_playlist($playlist_id) { + $this->db->where('id', $playlist_id); + return $this->db->delete('playlist'); + } + + // Ajouter une chanson à une playlist + public function add_song_to_playlist($data) { + return $this->db->insert('playlist_song', $data); + } + + // Supprimer une chanson d'une playlist + public function remove_song_from_playlist($playlist_id, $song_id) { + $this->db->where('playlist_id', $playlist_id); + $this->db->where('song_id', $song_id); + return $this->db->delete('playlist_song'); + } + + // Récupérer les chansons d'une playlist + public function get_songs_by_playlist($playlist_id) { + $this->db->select('song.*'); + $this->db->from('playlist_song'); + $this->db->join('song', 'song.id = playlist_song.song_id'); + $this->db->where('playlist_song.playlist_id', $playlist_id); + return $this->db->get()->result(); + } + + public function add_album_to_playlist($data) { + return $this->db->insert('playlist_album', $data); + } +} +?> diff --git a/CodeIgniter-3.1.13/application/views/layout/header_logged_dark.php b/CodeIgniter-3.1.13/application/views/layout/header_logged_dark.php index 4680094..e68aafb 100644 --- a/CodeIgniter-3.1.13/application/views/layout/header_logged_dark.php +++ b/CodeIgniter-3.1.13/application/views/layout/header_logged_dark.php @@ -19,7 +19,7 @@ Albums Artistes Musiques - Mes Playlists + Mes Playlists Mon compte Déconnexion diff --git a/CodeIgniter-3.1.13/application/views/playlist_add_album.php b/CodeIgniter-3.1.13/application/views/playlist_add_album.php new file mode 100644 index 0000000..f59e488 --- /dev/null +++ b/CodeIgniter-3.1.13/application/views/playlist_add_album.php @@ -0,0 +1,24 @@ + + + + + Ajouter un Album à la Playlist + + + +
+

Ajouter un Album à la Playlist

+ +
+ + +
+ + +
+ + diff --git a/CodeIgniter-3.1.13/application/views/playlist_add_song.php b/CodeIgniter-3.1.13/application/views/playlist_add_song.php new file mode 100644 index 0000000..899e1ed --- /dev/null +++ b/CodeIgniter-3.1.13/application/views/playlist_add_song.php @@ -0,0 +1,24 @@ + + + + + Ajouter une Chanson à la Playlist + + + +
+

Ajouter une Chanson à la Playlist

+ +
+ + +
+ + +
+ + diff --git a/CodeIgniter-3.1.13/application/views/playlist_create.php b/CodeIgniter-3.1.13/application/views/playlist_create.php new file mode 100644 index 0000000..b6d1766 --- /dev/null +++ b/CodeIgniter-3.1.13/application/views/playlist_create.php @@ -0,0 +1,24 @@ + + + + + Créer une Nouvelle Playlist + + + +
+

Créer une Nouvelle Playlist

+ +
+ + +
+
+ + +
+ + +
+ + diff --git a/CodeIgniter-3.1.13/application/views/playlist_view.php b/CodeIgniter-3.1.13/application/views/playlist_view.php new file mode 100644 index 0000000..af0f891 --- /dev/null +++ b/CodeIgniter-3.1.13/application/views/playlist_view.php @@ -0,0 +1,54 @@ + + + + + Détails de la Playlist + + + +
+

name, ENT_QUOTES, 'UTF-8'); ?>

+
+
+ + +
+
+ + +
+ +
+ +

Chansons

+ + + + + + + + + + + + + + + + + + + + + +
TitreActions
name, ENT_QUOTES, 'UTF-8'); ?> + Supprimer +
Aucune chanson trouvée dans cette playlist.
+ + Ajouter une musique + Ajouter un album + Retour à la Liste des Playlists +
+ + diff --git a/CodeIgniter-3.1.13/application/views/playlists_list.php b/CodeIgniter-3.1.13/application/views/playlists_list.php new file mode 100644 index 0000000..6912ffd --- /dev/null +++ b/CodeIgniter-3.1.13/application/views/playlists_list.php @@ -0,0 +1,43 @@ + + + + + Liste des Playlists + + + +
+

Liste des Playlists

+ Créer une Nouvelle Playlist + Générer une playlist aléatoire + + + + + + + + + + + + + + + + + + + + + + + +
NomDescriptionActions
name, ENT_QUOTES, 'UTF-8'); ?>description, ENT_QUOTES, 'UTF-8'); ?> + Voir + Supprimer + Dupliquer +
Aucune playlist trouvée.
+
+ + diff --git a/CodeIgniter-3.1.13/assets/css/playlist_add_song.css b/CodeIgniter-3.1.13/assets/css/playlist_add_song.css new file mode 100644 index 0000000..2e3c4ce --- /dev/null +++ b/CodeIgniter-3.1.13/assets/css/playlist_add_song.css @@ -0,0 +1,60 @@ +/* Reset CSS */ +* { + margin: 0; + padding: 0; + box-sizing: border-box; +} + +/* Body styles */ +body { + font-family: Arial, sans-serif; + background-color: #f4f4f4; + color: #333; +} + +.container { + max-width: 600px; + margin: 0 auto; + padding: 20px; + background-color: #fff; + border-radius: 8px; + box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); +} + +h1 { + margin-bottom: 20px; +} + +.form-group { + margin-bottom: 20px; +} + +label { + display: block; + font-weight: bold; +} + +.form-control { + width: 100%; + padding: 8px; + font-size: 16px; + border: 1px solid #ccc; + border-radius: 4px; +} + +button[type="submit"] { + display: block; + width: 100%; + padding: 10px; + border: none; + border-radius: 4px; + background-color: #5c10d6; + color: #fff; + font-size: 16px; + cursor: pointer; + transition: background-color 0.3s ease; +} + +button[type="submit"]:hover { + background-color: #330c72; +} diff --git a/CodeIgniter-3.1.13/assets/css/playlist_create.css b/CodeIgniter-3.1.13/assets/css/playlist_create.css new file mode 100644 index 0000000..f4863d2 --- /dev/null +++ b/CodeIgniter-3.1.13/assets/css/playlist_create.css @@ -0,0 +1,48 @@ +/* style.css */ + +.container { + max-width: 600px; + margin: 0 auto; + padding: 20px; + background-color: #f9f9f9; + border-radius: 5px; + box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); +} + +h1 { + text-align: center; + margin-bottom: 20px; +} + +.form-group { + margin-bottom: 20px; +} + +label { + font-weight: bold; +} + +input[type="text"], +textarea { + width: 100%; + padding: 10px; + border: 1px solid #ccc; + border-radius: 5px; + box-sizing: border-box; +} + +button[type="submit"] { + display: block; + width: 100%; + padding: 10px; + background-color: #5c10d6; + color: #fff; + border: none; + border-radius: 5px; + cursor: pointer; + transition: background-color 0.3s ease; +} + +button[type="submit"]:hover { + background-color: #330c72; +} diff --git a/CodeIgniter-3.1.13/assets/css/playlist_view.css b/CodeIgniter-3.1.13/assets/css/playlist_view.css new file mode 100644 index 0000000..2fa1db7 --- /dev/null +++ b/CodeIgniter-3.1.13/assets/css/playlist_view.css @@ -0,0 +1,69 @@ +/* Reset CSS */ +* { + margin: 0; + padding: 0; + box-sizing: border-box; +} + +/* Body styles */ +body { + font-family: Arial, sans-serif; + background-color: #f4f4f4; + color: #333; +} + +.container { + max-width: 800px; + margin: 0 auto; + padding: 20px; +} + +h1, h2 { + margin-bottom: 10px; +} + +p { + margin-bottom: 20px; +} + +.table { + width: 100%; + border-collapse: collapse; + margin-bottom: 20px; +} + +.table th, .table td { + padding: 8px; + border: 1px solid #ddd; + text-align: left; +} + +.table th { + background-color: #f2f2f2; + font-weight: bold; +} + +.btn { + display: inline-block; + padding: 8px 16px; + border: none; + border-radius: 4px; + background-color: #7700ff; + color: #fff; + text-decoration: none; + cursor: pointer; + transition: background-color 0.3s ease; +} + +.btn:hover { + background-color: #3c0c72; +} + +.btn-secondary { + background-color: #6c757d; +} + +.btn-secondary:hover { + background-color: #545b62; +} + diff --git a/CodeIgniter-3.1.13/assets/css/playlists_list.css b/CodeIgniter-3.1.13/assets/css/playlists_list.css new file mode 100644 index 0000000..9966291 --- /dev/null +++ b/CodeIgniter-3.1.13/assets/css/playlists_list.css @@ -0,0 +1,118 @@ +/* Fichier: assets/css/style.css */ + +/* Réinitialisation de certains styles par défaut */ +* { + margin: 0; + padding: 0; + box-sizing: border-box; +} + +/* Styles pour le conteneur principal */ +.container { + width: 80%; + margin: 20px auto; + padding: 20px; + background-color: #f9f9f9; + border-radius: 10px; + box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); +} + +/* Styles pour le titre principal */ +h1 { + text-align: center; + margin-bottom: 20px; + color: #333; +} + +/* Styles pour les boutons */ +.btn { + display: inline-block; + padding: 10px 20px; + margin: 5px 0; + color: #fff; + text-decoration: none; + border-radius: 5px; + transition: background-color 0.3s ease; +} + +.btn-primary { + background-color: #6c0980; +} + +.btn-primary:hover { + background-color: #551063; +} + +.btn-info { + background-color: #17a2b8; +} + +.btn-info:hover { + background-color: #117a8b; +} + +.btn-danger { + background-color: #dc3545; +} + +.btn-danger:hover { + background-color: #c82333; +} + +.btn-warning { + background-color: #ffc107; + color: #212529; +} + +.btn-warning:hover { + background-color: #e0a800; +} + +/* Styles pour la table */ +.table { + width: 100%; + border-collapse: collapse; + margin-top: 20px; +} + +.table th, .table td { + padding: 12px 15px; + text-align: left; + border-bottom: 1px solid #ddd; +} + +.table th { + background-color: #f2f2f2; + color: #333; +} + +.table tbody tr:hover { + background-color: #f1f1f1; +} + +/* Styles pour les messages d'erreur ou d'information */ +.alert { + padding: 20px; + background-color: #f44336; /* Red */ + color: white; + margin-bottom: 15px; +} + +.alert.success {background-color: #4CAF50;} /* Green */ +.alert.info {background-color: #2196F3;} /* Blue */ +.alert.warning {background-color: #ff9800;} /* Orange */ + +.closebtn { + margin-left: 15px; + color: white; + font-weight: bold; + float: right; + font-size: 22px; + line-height: 20px; + cursor: pointer; + transition: 0.3s; +} + +.closebtn:hover { + color: black; +}