48 $idPlaylist = isset($_GET[
'idPlaylist']) ? (int)$_GET[
'idPlaylist'] :
null;
57 $managerPlaylist =
new PlaylistDAO($this->getPdo());
58 $playlist = $managerPlaylist->findFromUser($idPlaylist, $_SESSION[
'user_email'] ??
null);
65 $chansons = $managerPlaylist->getChansonsByPlaylist($idPlaylist, $_SESSION[
'user_email'] ??
null);
67 $nomPlaylist = $playlist->getNomPlaylist();
68 $imagePlaylist = $managerPlaylist->recupererPochetteAuto($idPlaylist);
69 $playlistObj =
new class($nomPlaylist, $imagePlaylist) {
71 private ?
string $image;
72 public function __construct(
string $nom, ?
string $image)
75 $this->image = $image;
77 public function getTitreAlbum():
string
81 public function getUrlImageAlbum(): ?
string
85 public function getArtisteAlbum():
string
89 public function getDateSortieAlbum(): ?
string
96 $template = $this->
getTwig()->load(
'chanson_album.html.twig');
97 echo $template->render([
99 'title' => $playlist->getNomPlaylist(),
100 'name' =>
"playlist",
101 'description' =>
"Playlist dans Paaxio"
103 'album' => $playlistObj,
104 'chansons' => $chansons,
105 'idPlaylist' => $idPlaylist
119 header(
'Content-Type: application/json');
121 if ($_SERVER[
'REQUEST_METHOD'] !==
'POST') {
122 http_response_code(405);
123 echo json_encode([
'success' =>
false,
'message' =>
'Méthode non autorisée']);
127 if (!isset($_SESSION[
'user_logged_in']) || !$_SESSION[
'user_logged_in']) {
128 http_response_code(401);
129 echo json_encode([
'success' =>
false,
'message' =>
'Non authentifié']);
133 $idPlaylist = isset($_POST[
'idPlaylist']) ? (int)$_POST[
'idPlaylist'] : 0;
134 $idChanson = isset($_POST[
'idChanson']) ? (int)$_POST[
'idChanson'] : 0;
136 if (!$idPlaylist || !$idChanson) {
137 http_response_code(400);
138 echo json_encode([
'success' =>
false,
'message' =>
'Paramètres manquants']);
142 $managerPlaylist =
new PlaylistDAO($this->getPdo());
143 $playlist = $managerPlaylist->findFromUser($idPlaylist, $_SESSION[
'user_email'] ??
null);
146 http_response_code(403);
147 echo json_encode([
'success' =>
false,
'message' =>
'Playlist introuvable ou accès refusé']);
151 $added = $managerPlaylist->ajouterChansonPlaylist($idPlaylist, $idChanson);
154 echo json_encode([
'success' =>
true,
'message' =>
'Chanson ajoutée à la playlist']);
156 echo json_encode([
'success' =>
false,
'message' =>
'Cette chanson est déjà dans la playlist']);
171 header(
'Content-Type: application/json');
173 if ($_SERVER[
'REQUEST_METHOD'] !==
'POST') {
174 http_response_code(405);
175 echo json_encode([
'success' =>
false,
'message' =>
'Méthode non autorisée']);
179 if (!isset($_SESSION[
'user_logged_in']) || !$_SESSION[
'user_logged_in']) {
180 http_response_code(401);
181 echo json_encode([
'success' =>
false,
'message' =>
'Non authentifié']);
185 $idPlaylist = isset($_POST[
'idPlaylist']) ? (int)$_POST[
'idPlaylist'] : 0;
186 $idChanson = isset($_POST[
'idChanson']) ? (int)$_POST[
'idChanson'] : 0;
188 if (!$idPlaylist || !$idChanson) {
189 http_response_code(400);
190 echo json_encode([
'success' =>
false,
'message' =>
'Paramètres manquants']);
194 $managerPlaylist =
new PlaylistDAO($this->getPdo());
195 $playlist = $managerPlaylist->findFromUser($idPlaylist, $_SESSION[
'user_email'] ??
null);
198 http_response_code(403);
199 echo json_encode([
'success' =>
false,
'message' =>
'Playlist introuvable ou accès refusé']);
203 $removed = $managerPlaylist->supprimerChansonPlaylist($idPlaylist, $idChanson);
206 echo json_encode([
'success' =>
true,
'message' =>
'Chanson retirée de la playlist']);
208 echo json_encode([
'success' =>
false,
'message' =>
'Cette chanson n\'est pas dans la playlist']);
222 header(
'Content-Type: application/json');
224 if ($_SERVER[
'REQUEST_METHOD'] !==
'POST') {
225 http_response_code(405);
226 echo json_encode([
'success' =>
false,
'message' =>
'Méthode non autorisée']);
230 if (!isset($_SESSION[
'user_logged_in']) || !$_SESSION[
'user_logged_in']) {
231 http_response_code(401);
232 echo json_encode([
'success' =>
false,
'message' =>
'Non authentifié']);
236 $nom = trim($_POST[
'nomPlaylist'] ??
'');
239 http_response_code(400);
240 echo json_encode([
'success' =>
false,
'message' =>
'Le nom de la playlist est requis']);
244 if (mb_strlen($nom) > 255) {
245 http_response_code(400);
246 echo json_encode([
'success' =>
false,
'message' =>
'Le nom est trop long (255 caractères max)']);
250 $managerPlaylist =
new PlaylistDAO($this->getPdo());
251 $idPlaylist = $managerPlaylist->creerPlaylist($nom, $_SESSION[
'user_email']);
255 'message' =>
'Playlist créée',
256 'idPlaylist' => $idPlaylist,
257 'nomPlaylist' => $nom
272 header(
'Content-Type: application/json');
274 if ($_SERVER[
'REQUEST_METHOD'] !==
'POST') {
275 http_response_code(405);
276 echo json_encode([
'success' =>
false,
'message' =>
'Méthode non autorisée']);
280 if (!isset($_SESSION[
'user_logged_in']) || !$_SESSION[
'user_logged_in']) {
281 http_response_code(401);
282 echo json_encode([
'success' =>
false,
'message' =>
'Non authentifié']);
286 $idPlaylist = isset($_POST[
'idPlaylist']) ? (int)$_POST[
'idPlaylist'] : 0;
289 http_response_code(400);
290 echo json_encode([
'success' =>
false,
'message' =>
'Paramètre manquant']);
294 $managerPlaylist =
new PlaylistDAO($this->getPdo());
295 $playlist = $managerPlaylist->findFromUser($idPlaylist, $_SESSION[
'user_email'] ??
null);
298 http_response_code(403);
299 echo json_encode([
'success' =>
false,
'message' =>
'Playlist introuvable ou accès refusé']);
303 $deleted = $managerPlaylist->supprimerPlaylist($idPlaylist, $_SESSION[
'user_email']);
306 echo json_encode([
'success' =>
true,
'message' =>
'Playlist supprimée']);
308 echo json_encode([
'success' =>
false,
'message' =>
'Erreur lors de la suppression']);
323 $managerPlaylist =
new PlaylistDao($this->getPdo());
324 $playlists = $managerPlaylist->findAll();
327 $template = $this->
getTwig()->load(
'test.html.twig');
330 echo $template->render(array(
332 'title' =>
"Playlists",
333 'name' =>
"playlists",
334 'description' =>
"Playlists dans Paaxio"
336 'testing' => $playlists,
349 $managerPlaylist =
new PlaylistDao($this->getPdo());
350 $playlists = $managerPlaylist->findAll();
353 $template = $this->
getTwig()->load(
'test.html.twig');
354 echo $template->render(array(
356 'title' =>
"Playlists tableau",
357 'name' =>
"playlistt",
358 'description' =>
"Playlists tableau dans Paaxio"
360 'testing' => $playlists,
Contrôleur dédié à la gestion des playlists.
creerPlaylist()
Liste toutes les playlists de la plateforme.
lister()
Liste toutes les playlists de la plateforme.
listerTableau()
Liste toutes les playlists sous forme de tableau.
supprimerChanson()
Supprime une chanson d'une playlist de l'utilisateur connecté (AJAX).
__construct(\Twig\Environment $twig, \Twig\Loader\FilesystemLoader $loader)
Constructeur du contrôleur playlist.
supprimerPlaylist()
Supprime une playlist de l'utilisateur connecté (AJAX).
ajouterChanson()
Ajoute une chanson à une playlist de l'utilisateur connecté (AJAX).
afficher()
Affiche une playlist avec ses chansons.
Classe de base pour tous les contrôleurs de l'application.
redirectTo(string $controller, string $method, array $params=[])
Redirige vers un contrôleur et une méthode donnés.
requireAuth(string $controller='', string $method='', array $params=[])
Exige que l'utilisateur soit authentifié.
Twig Loader FilesystemLoader $loader
getTwig()
Récupère l'environnement Twig.