Commentaires
This commit is contained in:
@@ -9,15 +9,15 @@ class Playlist extends CI_Controller {
|
||||
$this->load->helper('html');
|
||||
$this->load->helper('url');
|
||||
$this->load->helper('form');
|
||||
// verifier si il y a une sessions utilisateur en cours
|
||||
if (!$this->session->userdata('user_id')) {
|
||||
redirect('connexion');
|
||||
}
|
||||
}
|
||||
|
||||
public function index(){
|
||||
|
||||
|
||||
$userId = $this->session->userdata('user_id');
|
||||
// recupère toutes les playlist de l'utilisateur
|
||||
$playlists = $this->model_music->getPlaylistsByUser($userId);
|
||||
$this->load->view('layout/header');
|
||||
$this->load->view('playlist_list', ['playlists' => $playlists]);
|
||||
@@ -25,6 +25,7 @@ class Playlist extends CI_Controller {
|
||||
}
|
||||
|
||||
public function create(){
|
||||
// récupère le nom choisis dans le formulaire
|
||||
$name = $this->input->post('name');
|
||||
$userId = $this->session->userdata('user_id');
|
||||
$this->model_music->createPlaylist($name, $userId);
|
||||
@@ -37,13 +38,14 @@ class Playlist extends CI_Controller {
|
||||
}
|
||||
|
||||
public function duplicate($id) {
|
||||
// récupère données de la playlist grâce à son id
|
||||
$playlist = $this->model_music->getPlaylistById($id);
|
||||
if ($playlist) {
|
||||
$newName = $playlist->name . '_bis';
|
||||
$userId = $this->session->userdata('user_id');
|
||||
$newPlaylistId = $this->model_music->createPlaylist($newName, $userId);
|
||||
$songs = $this->model_music->getSongsByPlaylist($id);
|
||||
foreach ($songs as $song) {
|
||||
$newPlaylistId = $this->model_music->createPlaylist($newName, $userId); // création de nouvelle playlist avec les modifs
|
||||
$songs = $this->model_music->getSongsByPlaylist($id); // récupère tout les sons de la playlist
|
||||
foreach ($songs as $song) {
|
||||
$this->model_music->addSongToPlaylist($newPlaylistId, $song->id);
|
||||
}
|
||||
redirect('playlist/view/' . $newPlaylistId);
|
||||
@@ -53,9 +55,10 @@ class Playlist extends CI_Controller {
|
||||
}
|
||||
|
||||
public function view($id) {
|
||||
// vérifier si la playlist apartient à l'utilisateur actuel
|
||||
if($this->model_music->playlistOfUser($id)){
|
||||
$songs = $this->model_music->getSongsByPlaylist($id);
|
||||
$playlist = $this->model_music->getPlaylistById($id);
|
||||
$songs = $this->model_music->getSongsByPlaylist($id); // récupère les chansons
|
||||
$playlist = $this->model_music->getPlaylistById($id); // récupère les données
|
||||
if ($playlist) {
|
||||
$data['playlistName'] = $playlist->name;
|
||||
$data['songs'] = $songs;
|
||||
@@ -89,8 +92,10 @@ class Playlist extends CI_Controller {
|
||||
}
|
||||
|
||||
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');
|
||||
$songName = $this->input->post('songName');
|
||||
// Recherche de la chanson par nom dans la base de données
|
||||
$song = $this->model_music->findSongByName($songName);
|
||||
if ($song) {
|
||||
$this->model_music->addSongToPlaylist($playlistId, $song->id);
|
||||
@@ -99,7 +104,7 @@ class Playlist extends CI_Controller {
|
||||
}
|
||||
|
||||
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'));
|
||||
$this->load->view('layout/header');
|
||||
$this->load->view('choose_playlist', ['playlists' => $playlists, 'songId' => $songId]);
|
||||
@@ -108,13 +113,13 @@ class Playlist extends CI_Controller {
|
||||
|
||||
|
||||
public function choix_playlist($albumId) {
|
||||
|
||||
$playlists = $this->model_music->getPlaylistsByUser($this->session->userdata('user_id'));
|
||||
$this->load->view('layout/header');
|
||||
$this->load->view('choix_playlist', ['playlists' => $playlists, 'albumId' => $albumId]);
|
||||
$this->load->view('layout/footer');
|
||||
}
|
||||
|
||||
// Ajoute une chanson à une playlist spécifiée par formulaire
|
||||
public function add_track() {
|
||||
$songId = $this->input->post('songId');
|
||||
$playlistId = $this->input->post('playlistId');
|
||||
|
Reference in New Issue
Block a user