48 $idChanson = isset($_GET[
'idChanson']) ? $_GET[
'idChanson'] :
null;
51 $managerChanson =
new ChansonDao($this->getPdo());
52 $chanson = $managerChanson->findId($idChanson);
54 $template = $this->
getTwig()->load(
'test.html.twig');
55 echo $template->render(array(
59 'description' =>
"Chanson dans Paaxio"
61 'testing' => $chanson,
74 $titreChanson = isset($_GET[
'titreChanson']) ? $_GET[
'titreChanson'] :
null;
77 $managerChanson =
new ChansonDao($this->getPdo());
78 $chanson = $managerChanson->rechercherParTitre($titreChanson);
80 $template = $this->
getTwig()->load(
'test.html.twig');
81 echo $template->render(array(
85 'description' =>
"Chanson dans Paaxio"
87 'testing' => $chanson,
100 $idAlbum = isset($_GET[
'idAlbum']) ? $_GET[
'idAlbum'] :
null;
103 $managerChanson =
new ChansonDao($this->getPdo());
104 $chanson = $managerChanson->rechercherParAlbum($idAlbum);
106 $template = $this->
getTwig()->load(
'test.html.twig');
107 echo $template->render(array(
109 'title' =>
"Chanson",
111 'description' =>
"Chanson dans Paaxio"
113 'testing' => $chanson,
127 $managerChanson =
new ChansonDao($this->getPdo());
128 $chansons = $managerChanson->findAll();
131 $template = $this->
getTwig()->load(
'test.html.twig');
134 echo $template->render(array(
136 'title' =>
"Chansons",
137 'name' =>
"chansons",
138 'description' =>
"Chansons dans Paaxio"
140 'testing' => $chansons,
153 $managerChanson =
new ChansonDao($this->getPdo());
154 $chansons = $managerChanson->findAll();
157 $template = $this->
getTwig()->load(
'test.html.twig');
158 echo $template->render(array(
160 'title' =>
"Chansons tableau",
161 'name' =>
"chansont",
162 'description' =>
"Chansons tableau dans Paaxio"
164 'testing' => $chansons,
182 $idGenre = $_GET[
'idGenre'] ??
null;
183 $idAlbum = $_GET[
'idAlbum'] ??
null;
186 $ordre = isset($_GET[
'ordre']) && in_array(strtolower($_GET[
'ordre']), [
'asc',
'desc'])
187 ? strtoupper($_GET[
'ordre'])
190 $tri = $_GET[
'tri'] ??
'titreChanson';
191 $colonnesValides = [
'titreChanson',
'dateTeleversementChanson',
'nbEcouteChanson'];
192 $colonne = in_array($tri, $colonnesValides) ? $tri :
'titreChanson';
195 $managerChanson =
new ChansonDao($this->getPdo());
196 $chansons = $managerChanson->filtrerChanson($idGenre, $idAlbum, $colonne, $ordre);
199 $template = $this->
getTwig()->load(
'test.html.twig');
200 echo $template->render([
202 'title' =>
"Chansons filtrées",
203 'name' =>
"chansons_filtrees",
204 'description' =>
"Chansons filtrées dans Paaxio"
206 'testing' => $chansons,
223 $emailUtilisateur = $_SESSION[
'user_email'] ??
null;
226 $idChanson = $_POST[
'idChanson'] ??
null;
228 http_response_code(400);
229 echo json_encode([
'error' =>
'ID de chanson manquant']);
233 $chansonDAO =
new ChansonDAO($this->getPdo());
236 $chansonsLikees = $chansonDAO->findChansonsLikees($emailUtilisateur);
238 foreach ($chansonsLikees as $chanson) {
239 if ($chanson->getIdChanson() == $idChanson) {
246 $chansonDAO->toggleLike($emailUtilisateur, $idChanson);
249 header(
'Content-Type: application/json');
250 echo json_encode([
'liked' => !$estLikee]);
266 $emailUtilisateur = $_SESSION[
'user_email'] ??
null;
267 if (!$emailUtilisateur) {
268 http_response_code(401);
269 echo json_encode([
'error' =>
'Utilisateur non connecté']);
273 $idChanson = $_POST[
'idChanson'] ??
null;
275 http_response_code(400);
276 echo json_encode([
'error' =>
'ID de chanson manquant']);
280 $chansonDAO =
new ChansonDAO($this->getPdo());
281 $nouveau = $chansonDAO->incrementNbEcoute((
int)$idChanson);
283 if ($nouveau ===
null) {
284 http_response_code(500);
285 echo json_encode([
'error' =>
'Impossible d\'incrémenter']);
289 header(
'Content-Type: application/json');
290 echo json_encode([
'success' =>
true,
'nbEcoute' => $nouveau]);
Contrôleur dédié à la gestion des chansons.
rechercherParTitre()
Recherche des chansons par leur titre.
rechercherParAlbum()
Recherche des chansons par album.
afficher()
Affiche les détails d'une chanson spécifique.
toggleLike()
Bascule l'état "j'aime" d'une chanson pour l'utilisateur connecté.
lister()
Liste toutes les chansons de la plateforme.
__construct(\Twig\Environment $twig, \Twig\Loader\FilesystemLoader $loader)
Constructeur du contrôleur chanson.
listerTableau()
Liste toutes les chansons sous forme de tableau.
incrementEcoute()
Incrémente le compteur d'écoutes d'une chanson.
filtrerChanson()
Filtre les chansons selon différents critères.
Classe de base pour tous les contrôleurs de l'application.
requireAuth(string $controller='', string $method='', array $params=[])
Exige que l'utilisateur soit authentifié.
Twig Loader FilesystemLoader $loader
getTwig()
Récupère l'environnement Twig.