Paaxio 1.0
Plateforme de streaming musical - SAE IUT Bayonne
Chargement...
Recherche...
Aucune correspondance
controller_playlist.class.php
Aller à la documentation de ce fichier.
1<?php
2
24{
31 public function __construct(\Twig\Environment $twig, \Twig\Loader\FilesystemLoader $loader)
32 {
33 parent::__construct($loader, $twig);
34 }
35
45 public function afficher()
46 {
47
48 $idPlaylist = isset($_GET['idPlaylist']) ? (int)$_GET['idPlaylist'] : null;
49
50 if (!$idPlaylist) {
51 $this->redirectTo('home', 'afficher');
52 }
53
54 $this->requireAuth();
55
56 // Récupération de la playlist
57 $managerPlaylist = new PlaylistDAO($this->getPdo());
58 $playlist = $managerPlaylist->findFromUser($idPlaylist, $_SESSION['user_email'] ?? null);
59
60 if (!$playlist) {
61 $this->redirectTo('home', 'afficher');
62 }
63
64 // Récupération des chansons de la playlist
65 $chansons = $managerPlaylist->getChansonsByPlaylist($idPlaylist, $_SESSION['user_email'] ?? null);
66
67 // Conversion de la playlist en objet stdClass pour utiliser avec le template
68 $playlistObj = (object) [
69 "getTitreAlbum" => function () use ($playlist) {
70 return $playlist->getNomPlaylist();
71 },
72 "getUrlImageAlbum" => function () {
73 return null;
74 },
75 "getArtisteAlbum" => function () {
76 return "Ma Playlist";
77 },
78 "getDateSortieAlbum" => function () {
79 return null;
80 },
81 ];
82
83 // Chargement du template
84 $template = $this->getTwig()->load('chanson_album.html.twig');
85 echo $template->render([
86 'page' => [
87 'title' => $playlist->getNomPlaylist(),
88 'name' => "playlist",
89 'description' => "Playlist dans Paaxio"
90 ],
91 'album' => $playlistObj,
92 'chansons' => $chansons
93 ]);
94 }
95
103 public function lister()
104 {
105 // Récupération des playlists
106 $managerPlaylist = new PlaylistDao($this->getPdo());
107 $playlists = $managerPlaylist->findAll();
108
109 // Choix du template
110 $template = $this->getTwig()->load('test.html.twig');
111
112 // Affichage de la page
113 echo $template->render(array(
114 'page' => [
115 'title' => "Playlists",
116 'name' => "playlists",
117 'description' => "Playlists dans Paaxio"
118 ],
119 'testing' => $playlists,
120 ));
121 }
122
130 public function listerTableau()
131 {
132 $managerPlaylist = new PlaylistDao($this->getPdo());
133 $playlists = $managerPlaylist->findAll();
134
135 // Génération de la vue
136 $template = $this->getTwig()->load('test.html.twig');
137 echo $template->render(array(
138 'page' => [
139 'title' => "Playlists tableau",
140 'name' => "playlistt",
141 'description' => "Playlists tableau dans Paaxio"
142 ],
143 'testing' => $playlists,
144 ));
145 }
146}
Contrôleur dédié à la gestion des playlists.
lister()
Liste toutes les playlists de la plateforme.
listerTableau()
Liste toutes les playlists sous forme de tableau.
__construct(\Twig\Environment $twig, \Twig\Loader\FilesystemLoader $loader)
Constructeur du contrôleur playlist.
afficher()
Affiche une playlist avec ses chansons.
Classe de base pour tous les contrôleurs de l'application.
Twig Environment $twig
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.