Commentaires
This commit is contained in:
parent
3c647bb426
commit
47cf47a918
codeigniter/application
@ -3,7 +3,7 @@ defined('BASEPATH') OR exit('No direct script access allowed');
|
|||||||
|
|
||||||
class Albums extends CI_Controller {
|
class Albums extends CI_Controller {
|
||||||
|
|
||||||
private $sort = 'Tri';
|
private $sort = 'Tri'; // Variable privée pour définir l'ordre de tri par défaut
|
||||||
|
|
||||||
public function __construct(){
|
public function __construct(){
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
@ -13,10 +13,11 @@ class Albums extends CI_Controller {
|
|||||||
$this->load->helper('form');
|
$this->load->helper('form');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// on affiche tous les albums
|
||||||
public function index(){
|
public function index(){
|
||||||
$albums = $this->model_music->getAlbums();
|
$albums = $this->model_music->getAlbums();
|
||||||
$genres = $this->model_music->getGenres();
|
$genres = $this->model_music->getGenres();
|
||||||
$num_results = count($albums);
|
$num_results = count($albums); // nombre total d'alubm recup
|
||||||
$this->load->view('layout/header');
|
$this->load->view('layout/header');
|
||||||
$this->load->view('albums_list', [
|
$this->load->view('albums_list', [
|
||||||
'albums' => $albums,
|
'albums' => $albums,
|
||||||
@ -28,16 +29,18 @@ class Albums extends CI_Controller {
|
|||||||
$this->load->view('layout/footer');
|
$this->load->view('layout/footer');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function view($id){
|
// afficher les détail d'un album spécifique (les musiques de l'albums)
|
||||||
$tracks = $this->model_music->getTracksByAlbumId($id);
|
public function view($id){
|
||||||
|
$tracks = $this->model_music->getTracksByAlbumId($id); // recuperer les pistes d'un album par son id
|
||||||
$this->load->view('layout/header');
|
$this->load->view('layout/header');
|
||||||
$this->load->view('album_info', ['tracks' => $tracks]);
|
$this->load->view('album_info', ['tracks' => $tracks]);
|
||||||
$this->load->view('layout/footer');
|
$this->load->view('layout/footer');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// trié en fonction d'un critère
|
||||||
public function tri(){
|
public function tri(){
|
||||||
$Ctri = $this->input->get('Ctri');
|
$Ctri = $this->input->get('Ctri'); // critère de trie via l'url
|
||||||
$trie = $this->model_music->get_tri_Albums($Ctri);
|
$trie = $this->model_music->get_tri_Albums($Ctri);
|
||||||
$genres = $this->model_music->getGenres();
|
$genres = $this->model_music->getGenres();
|
||||||
$num_results = count($trie);
|
$num_results = count($trie);
|
||||||
$this->load->view('layout/header');
|
$this->load->view('layout/header');
|
||||||
|
@ -3,7 +3,7 @@ defined('BASEPATH') OR exit('No direct script access allowed');
|
|||||||
|
|
||||||
class Artistes extends CI_Controller {
|
class Artistes extends CI_Controller {
|
||||||
|
|
||||||
private $sort = 'Tri';
|
private $sort = 'Tri'; // Variable pour définir l'ordre de tri par défaut
|
||||||
|
|
||||||
public function __construct(){
|
public function __construct(){
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
@ -14,14 +14,14 @@ class Artistes extends CI_Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function index(){
|
public function index(){
|
||||||
$artistes = $this->model_music_artistes->getArtistes();
|
$artistes = $this->model_music_artistes->getArtistes(); // recuperer tout les artistes
|
||||||
$this->load->view('layout/header');
|
$this->load->view('layout/header');
|
||||||
$this->load->view('artistes_list', ['artistes'=>$artistes]);
|
$this->load->view('artistes_list', ['artistes'=>$artistes]);
|
||||||
$this->load->view('layout/footer');
|
$this->load->view('layout/footer');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function tri(){
|
public function tri(){
|
||||||
$Ctri = $this->input->get('Ctri');
|
$Ctri = $this->input->get('Ctri'); // récupération du critère de trie depuis l'url
|
||||||
$trie = $this->model_music_artistes->get_tri_Artistes($Ctri);
|
$trie = $this->model_music_artistes->get_tri_Artistes($Ctri);
|
||||||
$num_results = count($trie);
|
$num_results = count($trie);
|
||||||
$this->load->view('layout/header');
|
$this->load->view('layout/header');
|
||||||
|
@ -18,12 +18,12 @@ class ConnexionController extends CI_Controller {
|
|||||||
|
|
||||||
public function authentifier() {
|
public function authentifier() {
|
||||||
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||||
$email = $_POST['email'];
|
$email = $_POST['email']; // recuère email depuis formulaire
|
||||||
$password = $_POST['password'];
|
$password = $_POST['password']; // idem mdp
|
||||||
|
|
||||||
if (!empty($email) && !empty($password)) {
|
if (!empty($email) && !empty($password)) {
|
||||||
$this->load->database();
|
$this->load->database();
|
||||||
// Utilisation d'une requête préparée pour éviter les injections SQL
|
// Utilisation d'une requête préparée
|
||||||
$query = $this->db->query("SELECT * FROM users WHERE email = ?", array($email));
|
$query = $this->db->query("SELECT * FROM users WHERE email = ?", array($email));
|
||||||
$result = $query->row(); // Récupérer la première ligne de résultat
|
$result = $query->row(); // Récupérer la première ligne de résultat
|
||||||
|
|
||||||
@ -50,7 +50,7 @@ class ConnexionController extends CI_Controller {
|
|||||||
|
|
||||||
|
|
||||||
public function traitement() {
|
public function traitement() {
|
||||||
if(isset($_POST['ok'])){
|
if(isset($_POST['ok'])){ // verifie si le formulaire a été envoyé
|
||||||
$this->load->database();
|
$this->load->database();
|
||||||
|
|
||||||
|
|
||||||
@ -58,7 +58,7 @@ class ConnexionController extends CI_Controller {
|
|||||||
$nom = strtoupper($this->input->post('nom'));
|
$nom = strtoupper($this->input->post('nom'));
|
||||||
$pseudo = $this->input->post('pseudo');
|
$pseudo = $this->input->post('pseudo');
|
||||||
$mdp = $this->input->post('pass');
|
$mdp = $this->input->post('pass');
|
||||||
$mdpcrypte = password_hash($mdp, PASSWORD_DEFAULT);
|
$mdpcrypte = password_hash($mdp, PASSWORD_DEFAULT); // cryptage du mot de passe
|
||||||
$email = $this->input->post('email');
|
$email = $this->input->post('email');
|
||||||
$data = array(
|
$data = array(
|
||||||
'pseudo' => $pseudo,
|
'pseudo' => $pseudo,
|
||||||
|
@ -9,15 +9,15 @@ class Playlist extends CI_Controller {
|
|||||||
$this->load->helper('html');
|
$this->load->helper('html');
|
||||||
$this->load->helper('url');
|
$this->load->helper('url');
|
||||||
$this->load->helper('form');
|
$this->load->helper('form');
|
||||||
|
// verifier si il y a une sessions utilisateur en cours
|
||||||
if (!$this->session->userdata('user_id')) {
|
if (!$this->session->userdata('user_id')) {
|
||||||
redirect('connexion');
|
redirect('connexion');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function index(){
|
public function index(){
|
||||||
|
|
||||||
|
|
||||||
$userId = $this->session->userdata('user_id');
|
$userId = $this->session->userdata('user_id');
|
||||||
|
// recupère toutes les playlist de l'utilisateur
|
||||||
$playlists = $this->model_music->getPlaylistsByUser($userId);
|
$playlists = $this->model_music->getPlaylistsByUser($userId);
|
||||||
$this->load->view('layout/header');
|
$this->load->view('layout/header');
|
||||||
$this->load->view('playlist_list', ['playlists' => $playlists]);
|
$this->load->view('playlist_list', ['playlists' => $playlists]);
|
||||||
@ -25,6 +25,7 @@ class Playlist extends CI_Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function create(){
|
public function create(){
|
||||||
|
// récupère le nom choisis dans le formulaire
|
||||||
$name = $this->input->post('name');
|
$name = $this->input->post('name');
|
||||||
$userId = $this->session->userdata('user_id');
|
$userId = $this->session->userdata('user_id');
|
||||||
$this->model_music->createPlaylist($name, $userId);
|
$this->model_music->createPlaylist($name, $userId);
|
||||||
@ -37,13 +38,14 @@ class Playlist extends CI_Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function duplicate($id) {
|
public function duplicate($id) {
|
||||||
|
// récupère données de la playlist grâce à son id
|
||||||
$playlist = $this->model_music->getPlaylistById($id);
|
$playlist = $this->model_music->getPlaylistById($id);
|
||||||
if ($playlist) {
|
if ($playlist) {
|
||||||
$newName = $playlist->name . '_bis';
|
$newName = $playlist->name . '_bis';
|
||||||
$userId = $this->session->userdata('user_id');
|
$userId = $this->session->userdata('user_id');
|
||||||
$newPlaylistId = $this->model_music->createPlaylist($newName, $userId);
|
$newPlaylistId = $this->model_music->createPlaylist($newName, $userId); // création de nouvelle playlist avec les modifs
|
||||||
$songs = $this->model_music->getSongsByPlaylist($id);
|
$songs = $this->model_music->getSongsByPlaylist($id); // récupère tout les sons de la playlist
|
||||||
foreach ($songs as $song) {
|
foreach ($songs as $song) {
|
||||||
$this->model_music->addSongToPlaylist($newPlaylistId, $song->id);
|
$this->model_music->addSongToPlaylist($newPlaylistId, $song->id);
|
||||||
}
|
}
|
||||||
redirect('playlist/view/' . $newPlaylistId);
|
redirect('playlist/view/' . $newPlaylistId);
|
||||||
@ -53,9 +55,10 @@ class Playlist extends CI_Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function view($id) {
|
public function view($id) {
|
||||||
|
// vérifier si la playlist apartient à l'utilisateur actuel
|
||||||
if($this->model_music->playlistOfUser($id)){
|
if($this->model_music->playlistOfUser($id)){
|
||||||
$songs = $this->model_music->getSongsByPlaylist($id);
|
$songs = $this->model_music->getSongsByPlaylist($id); // récupère les chansons
|
||||||
$playlist = $this->model_music->getPlaylistById($id);
|
$playlist = $this->model_music->getPlaylistById($id); // récupère les données
|
||||||
if ($playlist) {
|
if ($playlist) {
|
||||||
$data['playlistName'] = $playlist->name;
|
$data['playlistName'] = $playlist->name;
|
||||||
$data['songs'] = $songs;
|
$data['songs'] = $songs;
|
||||||
@ -89,8 +92,10 @@ class Playlist extends CI_Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function search_song(){
|
public function search_song(){
|
||||||
|
// Récupération de l'ID de la playlist et du nom de la chanson depuis le formulaire
|
||||||
$playlistId = $this->input->post('playlistId');
|
$playlistId = $this->input->post('playlistId');
|
||||||
$songName = $this->input->post('songName');
|
$songName = $this->input->post('songName');
|
||||||
|
// Recherche de la chanson par nom dans la base de données
|
||||||
$song = $this->model_music->findSongByName($songName);
|
$song = $this->model_music->findSongByName($songName);
|
||||||
if ($song) {
|
if ($song) {
|
||||||
$this->model_music->addSongToPlaylist($playlistId, $song->id);
|
$this->model_music->addSongToPlaylist($playlistId, $song->id);
|
||||||
@ -99,7 +104,7 @@ class Playlist extends CI_Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function choose_playlist($songId) {
|
public function choose_playlist($songId) {
|
||||||
|
// Récupération de toutes les playlists de l'utilisateur actuel
|
||||||
$playlists = $this->model_music->getPlaylistsByUser($this->session->userdata('user_id'));
|
$playlists = $this->model_music->getPlaylistsByUser($this->session->userdata('user_id'));
|
||||||
$this->load->view('layout/header');
|
$this->load->view('layout/header');
|
||||||
$this->load->view('choose_playlist', ['playlists' => $playlists, 'songId' => $songId]);
|
$this->load->view('choose_playlist', ['playlists' => $playlists, 'songId' => $songId]);
|
||||||
@ -108,13 +113,13 @@ class Playlist extends CI_Controller {
|
|||||||
|
|
||||||
|
|
||||||
public function choix_playlist($albumId) {
|
public function choix_playlist($albumId) {
|
||||||
|
|
||||||
$playlists = $this->model_music->getPlaylistsByUser($this->session->userdata('user_id'));
|
$playlists = $this->model_music->getPlaylistsByUser($this->session->userdata('user_id'));
|
||||||
$this->load->view('layout/header');
|
$this->load->view('layout/header');
|
||||||
$this->load->view('choix_playlist', ['playlists' => $playlists, 'albumId' => $albumId]);
|
$this->load->view('choix_playlist', ['playlists' => $playlists, 'albumId' => $albumId]);
|
||||||
$this->load->view('layout/footer');
|
$this->load->view('layout/footer');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ajoute une chanson à une playlist spécifiée par formulaire
|
||||||
public function add_track() {
|
public function add_track() {
|
||||||
$songId = $this->input->post('songId');
|
$songId = $this->input->post('songId');
|
||||||
$playlistId = $this->input->post('playlistId');
|
$playlistId = $this->input->post('playlistId');
|
||||||
|
@ -84,7 +84,7 @@ class Model_music extends CI_Model {
|
|||||||
album.id AS albumId,
|
album.id AS albumId,
|
||||||
album.name AS albumName,
|
album.name AS albumName,
|
||||||
artist.name AS artistName,
|
artist.name AS artistName,
|
||||||
song.id AS songId,
|
song.id AS songId,
|
||||||
song.name AS songName
|
song.name AS songName
|
||||||
FROM track
|
FROM track
|
||||||
JOIN album ON track.albumId = album.id
|
JOIN album ON track.albumId = album.id
|
||||||
@ -101,7 +101,7 @@ class Model_music extends CI_Model {
|
|||||||
return $query->result();
|
return $query->result();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// vérifier que la playlist spécifié appartient à l'utilisateur connecté actuellement
|
||||||
public function playlistOfUser($id){
|
public function playlistOfUser($id){
|
||||||
$user_id = $this->session->userdata('user_id');
|
$user_id = $this->session->userdata('user_id');
|
||||||
$this->db->select('id');
|
$this->db->select('id');
|
||||||
@ -153,19 +153,21 @@ class Model_music extends CI_Model {
|
|||||||
'name' => $name,
|
'name' => $name,
|
||||||
'userId' => $userId
|
'userId' => $userId
|
||||||
);
|
);
|
||||||
$this->db->insert('playlist', $data);
|
$this->db->insert('playlist', $data); // Insère les données dans la table 'playlist'
|
||||||
return $this->db->insert_id();
|
return $this->db->insert_id(); // Renvoie l'ID de la dernière insertion
|
||||||
}
|
}
|
||||||
public function deletePlaylist($playlistId) {
|
public function deletePlaylist($playlistId) {
|
||||||
$this->db->delete('playlist', array('id' => $playlistId));
|
$this->db->delete('playlist', array('id' => $playlistId));
|
||||||
$this->db->delete('playlistsong', array('playlistId' => $playlistId));
|
$this->db->delete('playlistsong', array('playlistId' => $playlistId));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// récupère playlist d'un utilisateur avec userid
|
||||||
public function getPlaylistsByUser($userId) {
|
public function getPlaylistsByUser($userId) {
|
||||||
$query = $this->db->get_where('playlist', array('userId' => $userId));
|
$query = $this->db->get_where('playlist', array('userId' => $userId));
|
||||||
return $query->result();
|
return $query->result();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// récupère playlist par id de playlist
|
||||||
public function getPlaylistById($playlistId) {
|
public function getPlaylistById($playlistId) {
|
||||||
$query = $this->db->get_where('playlist', array('id' => $playlistId), 1);
|
$query = $this->db->get_where('playlist', array('id' => $playlistId), 1);
|
||||||
return $query->row(); // Renvoie la première ligne trouvée (la playlist correspondant à l'ID)
|
return $query->row(); // Renvoie la première ligne trouvée (la playlist correspondant à l'ID)
|
||||||
@ -210,21 +212,14 @@ class Model_music extends CI_Model {
|
|||||||
$this->db->limit($numSongs);
|
$this->db->limit($numSongs);
|
||||||
|
|
||||||
$query = $this->db->get();
|
$query = $this->db->get();
|
||||||
|
// Récupère les chansons sélectionnées aléatoirement
|
||||||
|
|
||||||
$songs = $query->result();
|
$songs = $query->result();
|
||||||
|
// Crée une nouvelle playlist avec le nom spécifié
|
||||||
$playlistId = $this->createPlaylist($playlistName, $userId);
|
$playlistId = $this->createPlaylist($playlistName, $userId);
|
||||||
|
// Ajoute chaque chanson à la playlist créée
|
||||||
foreach ($songs as $song) {
|
foreach ($songs as $song) {
|
||||||
$this->addSongToPlaylist($playlistId, $song->id);
|
$this->addSongToPlaylist($playlistId, $song->id);
|
||||||
}
|
}
|
||||||
redirect('playlist/view/'.$playlistId);
|
redirect('playlist/view/'.$playlistId);
|
||||||
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user