25 if (ob_get_length()) ob_clean();
26 header(
'Content-Type: application/json');
28 $term = $_GET[
'term'] ??
'';
43 $artistes = $utilisateurDAO->rechercher($term);
44 if (is_array($artistes)) {
45 foreach ($artistes as $artiste) {
46 $results[
'artistes'][] = [
47 'pseudo' => $artiste->getPseudoUtilisateur(),
48 'image' => $artiste->geturlPhotoUtilisateur() ?:
"assets/images/profile_pictures/default.png"
55 $listaAlbums = $albumDAO->rechercher($term);
56 if (is_array($listaAlbums)) {
57 foreach ($listaAlbums as $album) {
58 $img = $album->geturlPochetteAlbum();
59 $path = $img ? ltrim($img,
'/') :
"assets/images/albums/default.png";
61 $results[
'albums'][] = [
62 'id' => $album->getIdAlbum(),
63 'titre' => $album->getTitreAlbum(),
65 'artiste' => $album->getPseudoArtiste()
72 $listaChansons = $chansonDAO->rechercherParTitre($term);
73 if (is_array($listaChansons)) {
74 foreach ($listaChansons as $chanson) {
75 $albumObj = $chanson->getAlbumChanson();
76 $idAlbum = ($albumObj && method_exists($albumObj,
'getIdAlbum')) ? $albumObj->getIdAlbum() :
null;
78 $results[
'chansons'][] = [
79 'id' => $chanson->getIdChanson(),
80 'titre' => $chanson->getTitrechanson(),
81 'ecoutes' => $chanson->getNbecoutechanson(),
82 'idAlbum' => $idAlbum,
89 echo json_encode($results);
91 }
catch (Exception $e) {
93 echo json_encode([
'error' => $e->getMessage()]);