From 24fa946cf0f2b83f5433b26115e66a60bcefb42f Mon Sep 17 00:00:00 2001 From: Felix-Vimalaratnam Date: Tue, 18 Jun 2024 19:59:50 +0200 Subject: [PATCH] finition css --- .../application/controllers/Playlist.php | 7 +- .../application/controllers/User.php | 23 ++- .../application/models/Model_music.php | 147 ++++++++---------- .../application/views/connexion_user.php | 2 - .../application/views/create_user.php | 14 +- .../application/views/layout/header.php | 14 +- CodeIgniter-3.1.13/assets/style.css | 38 ++++- 7 files changed, 133 insertions(+), 112 deletions(-) diff --git a/CodeIgniter-3.1.13/application/controllers/Playlist.php b/CodeIgniter-3.1.13/application/controllers/Playlist.php index 62182ae..00f3b2f 100644 --- a/CodeIgniter-3.1.13/application/controllers/Playlist.php +++ b/CodeIgniter-3.1.13/application/controllers/Playlist.php @@ -9,17 +9,18 @@ class Playlist extends CI_Controller { $this->load->library('form_validation'); } public function index(){ + $user = $this->session->userdata('userId'); if ($recherche=filter_input(INPUT_GET,'recherche') == false or $recherche=filter_input(INPUT_GET,'recherche') == null){ - $playlists = $this->model_music->getPlaylist(); + $playlists = $this->model_music->getPlaylist($user); }else{ $recherche=filter_input(INPUT_GET,'recherche'); - $playlists = $this->model_music->getSearchPlaylist($recherche); + $playlists = $this->model_music->getSearchPlaylist($recherche,$user); } $this->load->view('layout/header'); if ($playlists == false){ $page = preg_split('/[\/]/',$_SERVER['REQUEST_URI']); $this->load->view('error',['page'=>$page[count($page)-1]]); - $playlists = $this->model_music->getPlaylist(); + $playlists = $this->model_music->getPlaylist($user); } $this->load->view('playlist_list',['playlists'=>$playlists]); $this->load->view('layout/footer'); diff --git a/CodeIgniter-3.1.13/application/controllers/User.php b/CodeIgniter-3.1.13/application/controllers/User.php index 799e8c6..f7ba55d 100644 --- a/CodeIgniter-3.1.13/application/controllers/User.php +++ b/CodeIgniter-3.1.13/application/controllers/User.php @@ -21,17 +21,28 @@ class User extends CI_Controller { $this->load->view('layout/header'); $this->load->view('create_user'); $this->load->view('layout/footer'); - }else{ - + }else{ $user=array( "usernom" => $this->input->post("nom"), "userprenom" => $this->input->post("prenom"), "usermail" => $this->input->post("email"), "userpassword" => password_hash(($this->input->post("password")), PASSWORD_DEFAULT), ); - - $this->model_music->create_user($user); - redirect("user/auth"); + if($this->model_music->verifyMail($this->input->post("email")) == false){ + $this->model_music->create_user($user); + $dataUser=array( + "usernom" => $this->input->post("nom"), + "userprenom" => $this->input->post("prenom"), + "usermail" => $this->input->post("email"), + "userpassword" => password_hash(($this->input->post("password")), PASSWORD_DEFAULT), + "logged_in" => TRUE + ); + $this->session->set_userdata($dataUser); + redirect("albums"); + }else{ + $this->session->set_flashdata('error', 'Cet email est déjà utilisé.'); + redirect('user/create'); + } } } @@ -63,7 +74,7 @@ class User extends CI_Controller { $this->session->set_userdata($dataUser); redirect("albums"); }else{ - redirect("user/create"); + redirect("user/auth"); } } diff --git a/CodeIgniter-3.1.13/application/models/Model_music.php b/CodeIgniter-3.1.13/application/models/Model_music.php index e2e3e94..d03053b 100644 --- a/CodeIgniter-3.1.13/application/models/Model_music.php +++ b/CodeIgniter-3.1.13/application/models/Model_music.php @@ -176,16 +176,14 @@ class Model_music extends CI_Model { } public function getSearchAlbums($nom){ - $query = $this->db->query( - "SELECT album.name,album.id as albumId,year,artist.name as artistName, genre.name as genreName,jpeg - FROM album - JOIN artist ON album.artistid = artist.id - JOIN genre ON genre.id = album.genreid - JOIN cover ON cover.id = album.coverid - WHERE album.name LIKE '$nom' - " - ); - //$query->result(); + $this->db->select('album.name,album.id as albumId,year,artist.name as artistName, genre.name as genreName,jpeg '); + $this->db->from('album'); + $this->db->join('artist','album.artistid = artist.id'); + $this->db->join('genre','genre.id = album.genreid'); + $this->db->join('cover','cover.id = album.coverid'); + $this->db->where('album.name', $nom); + $this->db->order_by('year','ASC'); + $query = $this->db->get(); if ($query->num_rows() > 0){ return $query->result(); } @@ -193,13 +191,10 @@ class Model_music extends CI_Model { } public function getSearchArtistes($nom){ - $query = $this->db->query( - "SELECT artist.name, artist.id - FROM artist - WHERE artist.name LIKE '$nom' - " - ); - $query->result(); + $this->db->select('artist.name, artist.id'); + $this->db->from('artist'); + $this->db->like('artist.name',$nom); + $query = $this->db->get(); if ($query->num_rows() > 0){ return $query->result(); } @@ -207,18 +202,15 @@ class Model_music extends CI_Model { } public function getSearchChansons($nom){ - $query = $this->db->query( - "SELECT track.id as trackId,song.name,song.id,album.year,album.name as albumName, artist.name as artistName, genre.name as genreName - FROM song - JOIN track ON track.songId = song.id - JOIN album ON album.id = track.albumId - JOIN artist ON album.artistid = artist.id - JOIN genre ON genre.id = album.genreid - WHERE song.name LIKE '$nom' - - " - ); - $query->result(); + $this->db->select('album.name,album.id as albumId,year,artist.name as artistName, genre.name as genreName,jpeg '); + $this->db->from('song'); + $this->db->join('track','track.songId = song.id'); + $this->db->join('album','track.artistid = album.id'); + $this->db->join('artist','album.artistid = artist.id'); + $this->db->join('genre','genre.id = album.genreid'); + $this->db->where('song.name', $nom); + $this->db->order_by('year','ASC'); + $query = $this->db->get(); if ($query->num_rows() > 0){ return $query->result(); } @@ -230,18 +222,16 @@ class Model_music extends CI_Model { $query = $this->db->get('album'); $album = $query->row(); - // Recupere la couverture $this->db->where('id', $album->coverId); $coverQuery = $this->db->get('cover'); $cover = $coverQuery->row(); $album->coverImage = $cover->jpeg; - // Recupere le l'id de la musique a partie de l'album + $this->db->select('songId'); $this->db->where('albumId', $id); $songsQuery = $this->db->get('track'); $songIds = $songsQuery->result(); - // Récupérer les noms des chansons à partir des songIds $album->songs = []; foreach ($songIds as $song) { $this->db->select('name'); @@ -272,22 +262,18 @@ class Model_music extends CI_Model { $artist = $artistQuery->row(); $album->artist = $artist; - - return $album; } public function getAlbumsByArtistId($artistId) { - $query = $this->db->query( - "SELECT album.name,album.id as albumId,year,artist.name as artistName, genre.name as genreName,jpeg - FROM album - JOIN artist ON album.artistid = artist.id - JOIN genre ON genre.id = album.genreid - JOIN cover ON cover.id = album.coverid - WHERE album.artistid=$artistId - ORDER BY year - " - ); + $this->db->select('album.name,album.id as albumId,year,artist.name as artistName, genre.name as genreName,jpeg'); + $this->db->from('album'); + $this->db->join('artist','album.artistid = artist.id'); + $this->db->join('genre','genre.id = album.genreid'); + $this->db->join('cover','cover.id = album.coverid'); + $this->db->where('album.artistid', $artistId); + $this->db->order_by('year','ASC'); + $query = $this->db->get(); return $query->result(); } @@ -305,23 +291,20 @@ class Model_music extends CI_Model { return $query->row(); } - public function getPlaylist(){ - $query = $this->db->query( - "SELECT Playlist.name, Playlist.playlistId - FROM Playlist - ORDER BY Playlist.name - " - ); - return $query->result(); + public function getPlaylist($iduser){ + $this->db->select("Playlist.name, Playlist.playlistId"); + $this->db->from('Playlist'); + $this->db->where('Playlist.userId',$iduser); + $query = $this->db->get(); + return $query->result(); } - public function getSearchPlaylist($nom){ - $query = $this->db->query( - "SELECT Playlist.name, Playlist.playlistId - FROM Playlist - WHERE Playlist.name LIKE '$nom' - " - ); + public function getSearchPlaylist($nom,$iduser){ + $this->db->select("Playlist.name, Playlist.playlistId"); + $this->db->from('Playlist'); + $this->db->where('Playlist.name',$nom); + $this->db->where('Playlist.userId',$iduser); + $query = $this->db->get(); $query->result(); if ($query->num_rows() > 0){ return $query->result(); @@ -335,14 +318,12 @@ class Model_music extends CI_Model { $track = $result->row(); $trackId = $track->trackId; - $query = $this->db->query( - "SELECT Playlist.name, Playlist.playlistId - FROM Playlist - JOIN PlaylistSong ON Playlist.playlistId = PlaylistSong.playlistId - WHERE PlaylistSong.trackId = $trackId - ORDER BY Playlist.name - " - ); + $this->db->select('Playlist.name, Playlist.playlistId'); + $this->db->from('Playlist'); + $this->db->join('PlaylistSong','Playlist.playlistId = PlaylistSong.playlistId'); + $this->db->where('PlaylistSong.trackId',$trackId); + $this->db->order_by('Playlist.name','ASC'); + $query = $this->db->get(); return $query->result(); } @@ -387,7 +368,6 @@ class Model_music extends CI_Model { public function SongInPlaylist($id){ $result = $this->model_music->TrackidSonginPlaylist($id); - // Si on trouve au moins une piste de cette chanson dans la playlist, retourner true if ($result->num_rows() > 0) { return true; } @@ -399,23 +379,19 @@ class Model_music extends CI_Model { $idtrack = array($idtrack); } - // Étape 1: Récupérer l'ID de la chanson à partir de l'un des IDs de piste fournis $this->db->select('song.id as songId'); $this->db->from('track'); $this->db->join('song', 'song.id = track.songId'); $this->db->where_in('track.id', $idtrack); $query = $this->db->get(); - // Vérifier si des résultats ont été trouvés if ($query->num_rows() == 0) { - return false; // Si aucun résultat trouvé, retourner false + return false; } - // Récupérer le premier songId correspondant $result = $query->row(); $songId = $result->songId; - // Étape 2: Récupérer tous les IDs de pistes associés à cette chanson $this->db->select('track.id as trackId'); $this->db->from('track'); $this->db->where('track.songId', $songId); @@ -425,14 +401,12 @@ class Model_music extends CI_Model { $trackIds[] = $track->trackId; } - // Étape 3: Vérifier si l'une des pistes de cette chanson est dans la playlist $this->db->select('PlaylistSong.trackid as trackId'); $this->db->from('PlaylistSong'); $this->db->where_in('PlaylistSong.trackId', $trackIds); $this->db->where('PlaylistSong.playlistId',$idplaylist); $query = $this->db->get(); - // Si on trouve au moins une piste de cette chanson dans la playlist, retourner true if ($query->num_rows() > 0) { return true; } @@ -444,23 +418,19 @@ class Model_music extends CI_Model { $id = array($id); } - // Étape 1: Récupérer l'ID de la chanson à partir de l'un des IDs de piste fournis $this->db->select('song.id as songId'); $this->db->from('track'); $this->db->join('song', 'song.id = track.songId'); $this->db->where_in('track.id', $id); $query = $this->db->get(); - // Vérifier si des résultats ont été trouvés if ($query->num_rows() == 0) { - return false; // Si aucun résultat trouvé, retourner false + return false; } - // Récupérer le premier songId correspondant $result = $query->row(); $songId = $result->songId; - // Étape 2: Récupérer tous les IDs de pistes associés à cette chanson $this->db->select('track.id as trackId'); $this->db->from('track'); $this->db->where('track.songId', $songId); @@ -470,7 +440,6 @@ class Model_music extends CI_Model { $trackIds[] = $track->trackId; } - // Étape 3: Vérifier si l'une des pistes de cette chanson est dans la playlist $this->db->select('PlaylistSong.trackId as trackId'); $this->db->from('PlaylistSong'); $this->db->where_in('PlaylistSong.trackId', $trackIds); @@ -554,9 +523,23 @@ class Model_music extends CI_Model { $this->db->where_in('year', $years); } - $this->db->order_by('RAND()'); + $this->db->order_by('trackId','RANDOM'); $this->db->limit($num_tracks); $query = $this->db->get(); return $query->result(); } + + public function verifyMail($email){ + $this->db->select('usermail'); + $this->db->from('User'); + $this->db->where('usermail', $email); + + $query = $this->db->get(); + + if($query->num_rows() > 0){ + return true; + } + return false; + + } } diff --git a/CodeIgniter-3.1.13/application/views/connexion_user.php b/CodeIgniter-3.1.13/application/views/connexion_user.php index 0e7255a..1cf4454 100644 --- a/CodeIgniter-3.1.13/application/views/connexion_user.php +++ b/CodeIgniter-3.1.13/application/views/connexion_user.php @@ -1,7 +1,6 @@
-
@@ -9,7 +8,6 @@
-
diff --git a/CodeIgniter-3.1.13/application/views/create_user.php b/CodeIgniter-3.1.13/application/views/create_user.php index 8db0982..30d6d49 100644 --- a/CodeIgniter-3.1.13/application/views/create_user.php +++ b/CodeIgniter-3.1.13/application/views/create_user.php @@ -1,9 +1,6 @@
-
- -
-
@@ -24,9 +20,13 @@ -
- +session->flashdata('error')): ?> +
+ session->flashdata('error'); ?> +
+ +
+
-
diff --git a/CodeIgniter-3.1.13/application/views/layout/header.php b/CodeIgniter-3.1.13/application/views/layout/header.php index 2f4c50a..103f65b 100644 --- a/CodeIgniter-3.1.13/application/views/layout/header.php +++ b/CodeIgniter-3.1.13/application/views/layout/header.php @@ -17,11 +17,17 @@ -
- -
+ session->userdata('logged_in')){ ?> +
+ +
+ +
+ +
+ -