84 lines
2.7 KiB
PHP
84 lines
2.7 KiB
PHP
|
<?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);
|
||
|
}
|
||
|
}
|
||
|
?>
|