From 82d46c251d7b66f701f41cb610fd9e27196e361c Mon Sep 17 00:00:00 2001 From: stiti Date: Sat, 25 May 2024 19:13:36 +0200 Subject: [PATCH] Correction de bugs --- .../application/config/routes.php | 2 + .../application/controllers/Playlists.php | 70 +++++++++++++++---- .../application/controllers/Utilisateur.php | 4 -- .../application/models/Model_music.php | 15 +++- .../application/models/Model_playlist.php | 39 ++++++++++- .../application/views/nous-contacter.php | 59 +--------------- .../application/views/playlist_add_album.php | 2 +- .../application/views/playlist_add_artist.php | 24 +++++++ .../application/views/playlist_view.php | 16 ++++- .../assets/css/nous-contacter.css | 55 +++++++++++++++ 10 files changed, 206 insertions(+), 80 deletions(-) create mode 100644 CodeIgniter-3.1.13/application/views/playlist_add_artist.php create mode 100644 CodeIgniter-3.1.13/assets/css/nous-contacter.css diff --git a/CodeIgniter-3.1.13/application/config/routes.php b/CodeIgniter-3.1.13/application/config/routes.php index 7616e69..af9e05a 100644 --- a/CodeIgniter-3.1.13/application/config/routes.php +++ b/CodeIgniter-3.1.13/application/config/routes.php @@ -57,6 +57,8 @@ $route['musiques'] = 'Musiques/index'; $route['artiste/(:num)'] = 'artiste/index/$1'; $route['search'] = 'search/index'; $route['mentions-legals'] = 'MentionsLegales/index'; +$route['playlists/add_artist/(:num)'] = 'playlists/add_artist/$1'; + diff --git a/CodeIgniter-3.1.13/application/controllers/Playlists.php b/CodeIgniter-3.1.13/application/controllers/Playlists.php index aa54577..786b88e 100644 --- a/CodeIgniter-3.1.13/application/controllers/Playlists.php +++ b/CodeIgniter-3.1.13/application/controllers/Playlists.php @@ -77,7 +77,12 @@ class Playlists extends CI_Controller { 'playlist_id' => $playlist_id, 'song_id' => $this->input->post('song_id') ); - $this->Model_playlist->add_song_to_playlist($data); + $result = $this->Model_playlist->add_song_to_playlist($data); + if ($result) { + $this->session->set_flashdata('success', 'La chanson a été ajoutée à la playlist.'); + } else { + $this->session->set_flashdata('error', 'La chanson existe déjà dans la playlist.'); + } redirect('playlists/view/' . $playlist_id); } else { // Récupérer toutes les musiques disponibles @@ -87,7 +92,8 @@ class Playlists extends CI_Controller { $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); @@ -148,24 +154,27 @@ class Playlists extends CI_Controller { 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); + // Vérifier si les chansons de l'album existent déjà dans la playlist + if ($this->Model_playlist->album_songs_exist_in_playlist($playlist_id, $album_id)) { + $this->session->set_flashdata('error', 'Certaines chansons de cet album existent déjà dans la playlist.'); + } else { + $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); + foreach ($songs as $song) { + $data = array( + 'playlist_id' => $playlist_id, + 'song_id' => $song->id + ); + $this->Model_playlist->add_song_to_playlist($data); + } + + $this->session->set_flashdata('success', 'Album ajouté avec succès à la playlist.'); } - + 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'); @@ -174,6 +183,7 @@ class Playlists extends CI_Controller { } } + public function view($playlist_id) { // Charger les détails de la playlist spécifique en fonction de son ID $data['playlist'] = $this->Model_playlist->get_playlist_by_id($playlist_id); @@ -187,7 +197,39 @@ class Playlists extends CI_Controller { $this->load->view('layout/footer_dark'); } + public function add_artist($playlist_id) { + if ($this->input->post()) { + // Récupérer l'ID de l'artiste à partir du formulaire + $artist_id = $this->input->post('artist_id'); + + // Vérifier si les chansons de l'artiste existent déjà dans la playlist + if ($this->Model_playlist->artist_songs_exist_in_playlist($playlist_id, $artist_id)) { + $this->session->set_flashdata('error', 'Certaines chansons de cet artiste existent déjà dans la playlist.'); + } else { + $songs = $this->Model_music->get_songs_by_artist($artist_id); + foreach ($songs as $song) { + $data = array( + 'playlist_id' => $playlist_id, + 'song_id' => $song->id + ); + $this->Model_playlist->add_song_to_playlist($data); + } + $this->session->set_flashdata('success', 'Toutes les chansons de l\'artiste ont été ajoutées avec succès à la playlist.'); + } + + redirect('playlists/view/' . $playlist_id); + } else { + // Récupérer tous les artistes disponibles + $data['artists'] = $this->Model_music->get_all_artists(); + $data['playlist_id'] = $playlist_id; + $this->load->view('layout/header_dark'); + $this->load->view('playlist_add_artist', $data); + $this->load->view('layout/footer_dark'); + } + } + + } ?> diff --git a/CodeIgniter-3.1.13/application/controllers/Utilisateur.php b/CodeIgniter-3.1.13/application/controllers/Utilisateur.php index 9afdd79..4f579ab 100644 --- a/CodeIgniter-3.1.13/application/controllers/Utilisateur.php +++ b/CodeIgniter-3.1.13/application/controllers/Utilisateur.php @@ -87,10 +87,6 @@ class Utilisateur extends CI_Controller { redirect('/'); } - - - - public function connexion(){ // Définir les règles de validation $this->form_validation->set_rules('email', 'Email', 'required|valid_email'); diff --git a/CodeIgniter-3.1.13/application/models/Model_music.php b/CodeIgniter-3.1.13/application/models/Model_music.php index 4f170fb..5a682e1 100644 --- a/CodeIgniter-3.1.13/application/models/Model_music.php +++ b/CodeIgniter-3.1.13/application/models/Model_music.php @@ -135,6 +135,10 @@ class Model_music extends CI_Model { public function get_all_albums() { return $this->db->get('album')->result(); } + + public function get_all_artists() { + return $this->db->get('artist')->result(); + } public function get_songs_by_album($album_id) { $this->db->select('song.*'); @@ -144,7 +148,6 @@ class Model_music extends CI_Model { return $this->db->get()->result(); } - public function get_random_songs($limit) { $this->db->order_by('RAND()'); $this->db->limit($limit); @@ -215,5 +218,15 @@ class Model_music extends CI_Model { return $query->row(); } + + public function get_songs_by_artist($artist_id) { + $this->db->select('song.*'); + $this->db->from('track'); + $this->db->join('song', 'track.songid = song.id'); + $this->db->join('album', 'track.albumid = album.id'); + $this->db->where('album.artistid', $artist_id); + return $this->db->get()->result(); + } + } diff --git a/CodeIgniter-3.1.13/application/models/Model_playlist.php b/CodeIgniter-3.1.13/application/models/Model_playlist.php index 7eea9ae..53a44af 100644 --- a/CodeIgniter-3.1.13/application/models/Model_playlist.php +++ b/CodeIgniter-3.1.13/application/models/Model_playlist.php @@ -43,11 +43,48 @@ class Model_playlist extends CI_Model { return $this->db->delete('playlist'); } - // Ajouter une chanson à une playlist public function add_song_to_playlist($data) { + // Vérifier si la combinaison playlist_id et song_id existe déjà + $this->db->where($data); + $existing_entry = $this->db->get('playlist_song')->row(); + + // Si la combinaison existe déjà, retourner false + if ($existing_entry) { + return false; + } + + // Sinon, effectuer l'insertion return $this->db->insert('playlist_song', $data); } + public function song_exists_in_playlist($playlist_id, $song_id) { + $this->db->where('playlist_id', $playlist_id); + $this->db->where('song_id', $song_id); + $query = $this->db->get('playlist_song'); + return $query->num_rows() > 0; + } + + public function artist_songs_exist_in_playlist($playlist_id, $artist_id) { + // Récupérer les chansons de l'artiste spécifié + $artist_songs = $this->Model_music->get_songs_by_artist($artist_id); + + // Récupérer les chansons de la playlist + $playlist_songs = $this->get_songs_by_playlist($playlist_id); + + // Vérifier chaque chanson de l'artiste dans la playlist + foreach ($artist_songs as $artist_song) { + foreach ($playlist_songs as $playlist_song) { + // Si la chanson de l'artiste est déjà dans la playlist, retourner true + if ($artist_song->id == $playlist_song->id) { + return true; + } + } + } + + // Si aucune chanson de l'artiste n'est trouvée dans la playlist, retourner false + return false; + } + // Supprimer une chanson d'une playlist public function remove_song_from_playlist($playlist_id, $song_id) { $this->db->where('playlist_id', $playlist_id); diff --git a/CodeIgniter-3.1.13/application/views/nous-contacter.php b/CodeIgniter-3.1.13/application/views/nous-contacter.php index 0c57119..3cb672d 100644 --- a/CodeIgniter-3.1.13/application/views/nous-contacter.php +++ b/CodeIgniter-3.1.13/application/views/nous-contacter.php @@ -1,64 +1,7 @@ - + Nous contacter - Onzeur diff --git a/CodeIgniter-3.1.13/application/views/playlist_add_album.php b/CodeIgniter-3.1.13/application/views/playlist_add_album.php index f59e488..956ae16 100644 --- a/CodeIgniter-3.1.13/application/views/playlist_add_album.php +++ b/CodeIgniter-3.1.13/application/views/playlist_add_album.php @@ -3,7 +3,7 @@ Ajouter un Album à la Playlist - +
diff --git a/CodeIgniter-3.1.13/application/views/playlist_add_artist.php b/CodeIgniter-3.1.13/application/views/playlist_add_artist.php new file mode 100644 index 0000000..2ec45d7 --- /dev/null +++ b/CodeIgniter-3.1.13/application/views/playlist_add_artist.php @@ -0,0 +1,24 @@ + + + + + Ajouter les musiques d'un Artiste à la Playlist + + + +
+

Ajouter les musiques d'un Artiste à la Playlist

+ +
+ + +
+ + +
+ + diff --git a/CodeIgniter-3.1.13/application/views/playlist_view.php b/CodeIgniter-3.1.13/application/views/playlist_view.php index 6ff4bb5..0e557c0 100644 --- a/CodeIgniter-3.1.13/application/views/playlist_view.php +++ b/CodeIgniter-3.1.13/application/views/playlist_view.php @@ -3,10 +3,23 @@ Détails de la Playlist - +
+ + session->flashdata('success')): ?> +
+ session->flashdata('success'); ?> +
+ + + session->flashdata('error')): ?> +
+ session->flashdata('error'); ?> +
+ +

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

diff --git a/CodeIgniter-3.1.13/assets/css/nous-contacter.css b/CodeIgniter-3.1.13/assets/css/nous-contacter.css new file mode 100644 index 0000000..a7325f9 --- /dev/null +++ b/CodeIgniter-3.1.13/assets/css/nous-contacter.css @@ -0,0 +1,55 @@ +body { + font-family: Arial, sans-serif; + background-color: #f4f4f4; + margin: 0; + padding: 0; + color: #640875; +} +.container { + width: 80%; + margin: 0 auto; + padding: 20px; +} +h1, h2, h3 { + color: #444; +} + +.hero h1 { + color: #9f23b5; +} + +.hero { + background-color: #2d1c30; + color: #fff; + padding: 50px 20px; + text-align: center; +} + +.contact-form { + margin: 20px 0; + padding: 20px; + background: #fff; + border-radius: 8px; + box-shadow: 0 0 10px rgba(0,0,0,0.1); +} + +.contact-form h2 { + margin-top: 0; +} + +.contact-form input, .contact-form textarea { + width: 100%; + padding: 10px; + margin: 10px 0; + border: 1px solid #ccc; + border-radius: 4px; +} + +.contact-form button { + padding: 10px 20px; + background-color: #333; + color: #fff; + border: none; + border-radius: 4px; + cursor: pointer; +} \ No newline at end of file