ajout tout les morceau d'un artiste

This commit is contained in:
Julian GALLEGO 2024-06-06 10:47:55 +02:00
parent 831f05ca6b
commit adcb08be5d
4 changed files with 45 additions and 12 deletions

View File

@ -23,7 +23,7 @@ defined('BASEPATH') OR exit('No direct script access allowed');
| a PHP script and you can easily do that on your own.
|
*/
$config['base_url'] = '/~brigitte/SAEWEB2.2/ci/';
$config['base_url'] = '/~gallego/SAEWEB2.2/ci/';
/*
|--------------------------------------------------------------------------

View File

@ -9,8 +9,9 @@ class artistes extends CI_Controller {
}
public function index(){
$artistes = $this->model_music->getArtists();
$playlists = $this->model_music->getPlaylist();
$this->load->view('layout/header');
$this->load->view('artistes_list',['artistes'=>$artistes]);
$this->load->view('artistes_list',['artistes'=>$artistes, 'playlists' => $playlists]);
$this->load->view('layout/footer');
}
@ -32,4 +33,12 @@ class artistes extends CI_Controller {
redirect('playlist');
}
public function addSongOfArtistToPlaylist(){
$playlistId = $this->input->post('playlist');
$artistId = $this->input->post('artistId');
$this->model_music->addAllSongsOfArtistInPlaylist($artistId, $playlistId);
redirect('artistes');
}
}

View File

@ -107,4 +107,25 @@ class Model_music extends CI_Model {
);
}
public function addAllSongsOfArtistInPlaylist($artistId, $playlistId){
// Récupérer toutes les chansons de l'artiste spécifié
$query = $this->db->query(
"SELECT song.name
FROM song, track, album
WHERE song.id = track.songId
AND track.albumId = album.id
AND album.artistId = ?",
array($artistId)
);
$songs = $query->result();
// Ajouter chaque chanson dans la playlist spécifiée
foreach ($songs as $song) {
$this->db->query(
"INSERT INTO SongPlaylist (id, name) VALUES (?, ?)",
array($playlistId, $song->name)
);
}
}
}

View File

@ -1,14 +1,17 @@
<section class="artiste">
<?php
foreach($artistes as $artiste){
//echo "<div><article>";
//echo "<header class='short-text'>";
echo anchor("artistes/view/{$artiste->id}","{$artiste->name}");
echo "<form action='" . base_url("index.php/artistes/addSongOfArtistToPlaylist") . "' method='post'>";
echo anchor("artistes/view/{$artiste->id}", "{$artiste->name}");
echo "<select name='playlist'>";
foreach ($playlists as $playlist) {
echo "<option value='{$playlist->id}'>{$playlist->name}</option>";
}
echo "</select>";
echo "<input type='hidden' name='artistId' value='{$artiste->id}' />"; // Utilisez l'identifiant de l'artiste ici
echo "<button type='submit' class='add-to-playlist'>+</button>";
echo "</form>";
echo "<br>";
echo "</header>";
//echo "<footer class='short-text'>{$artistes->year} - {$artistes->artistName}</footer>
//</article></div>";
}
?>
</section>