vaujdui
This commit is contained in:
@@ -5,22 +5,20 @@ class Playlist extends CI_Controller {
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
$this->load->model('Model_playlist');
|
||||
$this->load->model('Model_music'); // Ajouté pour accéder aux musiques
|
||||
$this->load->model('Model_music');
|
||||
$this->load->library('session');
|
||||
if (!$this->session->userdata('logged_in')) {
|
||||
redirect('connect/login');
|
||||
}
|
||||
}
|
||||
|
||||
public function index() {
|
||||
public function index($data = []) {
|
||||
$is_logged_in = $this->session->userdata('logged_in');
|
||||
$user_email = $this->session->userdata('email');
|
||||
|
||||
if (!$is_logged_in) {
|
||||
redirect('connect/login');
|
||||
}
|
||||
|
||||
$data = array(
|
||||
'is_logged_in' => $is_logged_in,
|
||||
'playlists' => $this->Model_playlist->getPlaylistsByUser($user_email)
|
||||
);
|
||||
$data['is_logged_in'] = $is_logged_in;
|
||||
$data['playlists'] = $this->Model_playlist->getPlaylistsByUser($user_email);
|
||||
$data['genres'] = $this->Model_playlist->getGenres();
|
||||
|
||||
$this->load->view('layout/header', $data);
|
||||
$this->load->view('playlists_list', $data);
|
||||
@@ -31,18 +29,24 @@ class Playlist extends CI_Controller {
|
||||
$is_logged_in = $this->session->userdata('logged_in');
|
||||
$user_email = $this->session->userdata('email');
|
||||
|
||||
if (!$is_logged_in) {
|
||||
redirect('connect/login');
|
||||
}
|
||||
|
||||
$name = $this->input->post('name');
|
||||
$type = $this->input->post('type');
|
||||
$numSongs = $this->input->post('numSongs');
|
||||
$genre = $this->input->post('genre');
|
||||
|
||||
if ($type == 'random') {
|
||||
$numSongs = $this->input->post('numSongs');
|
||||
$artist = $this->input->post('artist');
|
||||
$genre = $this->input->post('genre');
|
||||
$this->Model_playlist->createRandomPlaylist($user_email, $name, $numSongs, $artist, $genre);
|
||||
if ($numSongs <= 0) {
|
||||
$data['error'] = 'Le nombre de chansons doit être supérieur à 0';
|
||||
$this->index($data);
|
||||
return;
|
||||
}
|
||||
|
||||
$result = $this->Model_playlist->createRandomPlaylist($user_email, $name, $numSongs, $genre);
|
||||
if (!$result) {
|
||||
$data['error'] = 'Erreur lors de la création de la playlist aléatoire';
|
||||
$this->index($data);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
$this->Model_playlist->addPlaylist($user_email, $name);
|
||||
}
|
||||
@@ -51,11 +55,13 @@ class Playlist extends CI_Controller {
|
||||
}
|
||||
|
||||
public function selectPlaylist() {
|
||||
$is_logged_in = $this->session->userdata('logged_in');
|
||||
$itemId = $this->input->post('itemId');
|
||||
$itemType = $this->input->post('itemType');
|
||||
$playlists = $this->Model_playlist->getPlaylistsByUser($this->session->userdata('email'));
|
||||
|
||||
$data = array(
|
||||
'is_logged_in' => $is_logged_in,
|
||||
'itemId' => $itemId,
|
||||
'itemType' => $itemType,
|
||||
'playlists' => $playlists
|
||||
@@ -74,14 +80,14 @@ class Playlist extends CI_Controller {
|
||||
if ($itemType == 'album') {
|
||||
$songs = $this->Model_music->getSongsByAlbum($itemId);
|
||||
foreach ($songs as $song) {
|
||||
$this->Model_playlist->addItem($playlistId, $song->id, 'song');
|
||||
$this->Model_playlist->addItem($playlistId, $song->trackId, 'song');
|
||||
}
|
||||
} else if ($itemType == 'artist') {
|
||||
$albums = $this->Model_music->getAlbumsByArtist($itemId);
|
||||
foreach ($albums as $album) {
|
||||
$songs = $this->Model_music->getSongsByAlbum($album->albumId);
|
||||
foreach ($songs as $song) {
|
||||
$this->Model_playlist->addItem($playlistId, $song->id, 'song');
|
||||
$this->Model_playlist->addItem($playlistId, $song->trackId, 'song');
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -94,9 +100,12 @@ class Playlist extends CI_Controller {
|
||||
public function view($playlistId) {
|
||||
$is_logged_in = $this->session->userdata('logged_in');
|
||||
$items = $this->Model_playlist->getPlaylistItems($playlistId);
|
||||
$itemCount = $this->Model_playlist->getPlaylistItemCount($playlistId);
|
||||
|
||||
$data = array(
|
||||
'is_logged_in' => $is_logged_in,
|
||||
'items' => $items
|
||||
'items' => $items,
|
||||
'itemCount' => $itemCount
|
||||
);
|
||||
|
||||
$this->load->view('layout/header', $data);
|
||||
@@ -113,10 +122,6 @@ class Playlist extends CI_Controller {
|
||||
$is_logged_in = $this->session->userdata('logged_in');
|
||||
$user_email = $this->session->userdata('email');
|
||||
|
||||
if (!$is_logged_in) {
|
||||
redirect('connect/login');
|
||||
}
|
||||
|
||||
$this->Model_playlist->deletePlaylist($playlist_id);
|
||||
redirect('playlist');
|
||||
}
|
||||
@@ -125,10 +130,6 @@ class Playlist extends CI_Controller {
|
||||
$is_logged_in = $this->session->userdata('logged_in');
|
||||
$user_email = $this->session->userdata('email');
|
||||
|
||||
if (!$is_logged_in) {
|
||||
redirect('connect/login');
|
||||
}
|
||||
|
||||
$this->Model_playlist->duplicatePlaylist($playlist_id, $user_email);
|
||||
redirect('playlist');
|
||||
}
|
||||
@@ -137,10 +138,6 @@ class Playlist extends CI_Controller {
|
||||
$is_logged_in = $this->session->userdata('logged_in');
|
||||
$user_email = $this->session->userdata('email');
|
||||
|
||||
if (!$is_logged_in) {
|
||||
redirect('connect/login');
|
||||
}
|
||||
|
||||
$playlistId = $this->input->post('playlistId');
|
||||
$newName = $this->input->post('newName');
|
||||
|
||||
@@ -148,4 +145,3 @@ class Playlist extends CI_Controller {
|
||||
redirect('playlist');
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user