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 @@
- +