Ajout de la playlist, ajout et suppression de son dans l'onglet playlist
This commit is contained in:
@@ -26,12 +26,18 @@ class ConnexionController extends CI_Controller {
|
||||
$result = $query->row(); // Récupérer la première ligne de résultat
|
||||
|
||||
if($result){ // Vérifier si l'utilisateur existe
|
||||
$this->session->set_userdata('user_id', $result->id);
|
||||
$this->session->set_userdata('pseudo', $result->pseudo);
|
||||
redirect('../index.php');
|
||||
} else {
|
||||
$data['error_msg'] = "Email ou mot de passe incorrect.";
|
||||
}
|
||||
}
|
||||
|
||||
echo "<pre>";
|
||||
print_r($this->session->userdata());
|
||||
echo "</pre>";
|
||||
|
||||
$this->load->view('layout/header');
|
||||
$this->load->view('connexion', $data);
|
||||
$this->load->view('layout/footer');
|
||||
|
83
codeigniter/application/controllers/Playlist.php
Normal file
83
codeigniter/application/controllers/Playlist.php
Normal file
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
class Playlist extends CI_Controller {
|
||||
|
||||
public function __construct(){
|
||||
parent::__construct();
|
||||
$this->load->model('model_music');
|
||||
$this->load->helper('html');
|
||||
$this->load->helper('url');
|
||||
$this->load->helper('form');
|
||||
}
|
||||
|
||||
public function index(){
|
||||
|
||||
$userId = $this->session->userdata('user_id');
|
||||
$playlists = $this->model_music->getPlaylistsByUser($userId);
|
||||
$this->load->view('layout/header');
|
||||
$this->load->view('playlist_list', ['playlists' => $playlists]);
|
||||
$this->load->view('layout/footer');
|
||||
}
|
||||
|
||||
public function create(){
|
||||
$name = $this->input->post('name');
|
||||
$userId = $this->session->userdata('user_id');
|
||||
$this->model_music->createPlaylist($name, $userId);
|
||||
redirect('playlist');
|
||||
}
|
||||
|
||||
public function delete($playlistId){
|
||||
$this->model_music->deletePlaylist($playlistId);
|
||||
redirect('playlist');
|
||||
}
|
||||
|
||||
public function view($id) {
|
||||
$songs = $this->model_music->getSongsByPlaylist($id);
|
||||
$playlist = $this->model_music->getPlaylistById($id);
|
||||
|
||||
if ($playlist) {
|
||||
$data['playlistName'] = $playlist->name; // Passez le nom de la playlist à la vue
|
||||
$data['songs'] = $songs;
|
||||
$data['playlistId'] = $id;
|
||||
|
||||
$this->load->view('layout/header');
|
||||
$this->load->view('playlist_view', $data);
|
||||
$this->load->view('layout/footer');
|
||||
} else {
|
||||
echo "Playlist non trouvée.";
|
||||
}
|
||||
}
|
||||
|
||||
public function add_song(){
|
||||
$playlistId = $this->input->post('playlistId');
|
||||
$songId = $this->input->post('songId');
|
||||
$this->model_music->addSongToPlaylist($playlistId, $songId);
|
||||
redirect('playlists/view/' . $playlistId);
|
||||
}
|
||||
|
||||
|
||||
public function remove_song(){
|
||||
$playlistId = $this->input->post('playlistId');
|
||||
$songId = $this->input->post('songId');
|
||||
$this->model_music->removeSongFromPlaylist($playlistId, $songId);
|
||||
redirect('playlist/view/' . $playlistId);
|
||||
}
|
||||
|
||||
public function search_song(){
|
||||
$playlistId = $this->input->post('playlistId');
|
||||
$songName = $this->input->post('songName');
|
||||
|
||||
// Recherche la chanson par son nom
|
||||
$song = $this->model_music->findSongByName($songName);
|
||||
|
||||
if ($song) {
|
||||
// Si la chanson est trouvée, ajoutez-la à la playlist
|
||||
$this->model_music->addSongToPlaylist($playlistId, $song->id);
|
||||
}
|
||||
|
||||
// Redirige l'utilisateur vers la vue de la playlist mise à jour
|
||||
redirect('playlist/view/' . $playlistId);
|
||||
}
|
||||
}
|
||||
?>
|
Reference in New Issue
Block a user