ajouter song playlist

This commit is contained in:
Wilfried BRIGITTE 2024-06-05 19:36:03 +02:00
parent ef10b58bb0
commit ba57a3adc3
7 changed files with 39 additions and 14 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. | a PHP script and you can easily do that on your own.
| |
*/ */
$config['base_url'] = '/~boutaric/SAEWEB2.2/ci/'; $config['base_url'] = '/~brigitte/SAEWEB2.2/ci/';
/* /*
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------

View File

@ -20,8 +20,9 @@ class Albums extends CI_Controller {
if (empty($songs)) { if (empty($songs)) {
$songs = []; $songs = [];
} }
$playlists = $this->model_music->getPlaylist();
$this->load->view('layout/header'); $this->load->view('layout/header');
$this->load->view('song_album_list', ['songs' => $songs]); $this->load->view('song_album_list', ['songs' => $songs, 'playlists' => $playlists]);
$this->load->view('layout/footer'); $this->load->view('layout/footer');
} }
} }

View File

@ -57,6 +57,13 @@ class Playlist extends CI_Controller {
$create = $this->model_music->createPlaylist($name_playlist); $create = $this->model_music->createPlaylist($name_playlist);
redirect('playlist'); redirect('playlist');
} }
public function addSongToPlaylist(){
$songName = $this->input->post('song');
$playlistId = $this->input->post('playlist');
$this->model_music->addSongToPlaylist($songName, $playlistId);
redirect('playlist');
}
} }

View File

@ -10,8 +10,9 @@ class Song extends CI_Controller {
public function view($album_id){ public function view($album_id){
$songs = $this->model_music->getSongOfAlbum($album_id); $songs = $this->model_music->getSongOfAlbum($album_id);
$playlists = $this->model_music->getPlaylist();
$this->load->view('layout/header'); $this->load->view('layout/header');
$this->load->view('song_album_list',['songs'=>$songs]); $this->load->view('song_album_list', ['songs' => $songs, 'playlists' => $playlists]);
$this->load->view('layout/footer'); $this->load->view('layout/footer');
} }
} }

View File

@ -99,4 +99,11 @@ class Model_music extends CI_Model {
return $query->result(); return $query->result();
} }
public function addSongToPlaylist($songName, $playlistId){
$query = $this->db->query(
"INSERT INTO SongPlaylist (id, name) VALUES (?, ?)",
array($playlistId, $songName)
);
}
} }

View File

@ -14,21 +14,21 @@
</div> </div>
<nav class="menu"> <nav class="menu">
<ul> <ul>
<li><?= anchor('https://dwarves.iut-fbleau.fr/~boutaric/SAEWEB2.2/ci/','Home'); ?></li> <li><?= anchor('https://dwarves.iut-fbleau.fr/~brigitte/SAEWEB2.2/ci/','Home'); ?></li>
<li class="menu_déroulant"><?= anchor('albums','Albums'); ?> <li class="menu_déroulant"><?= anchor('albums','Albums'); ?>
<div class="menu_déroulant_content"> <div class="menu_déroulant_content">
<?= anchor('https://dwarves.iut-fbleau.fr/~boutaric/SAEWEB2.2/ci/index.php/Song/view/196','New Masters'); ?> <?= anchor('https://dwarves.iut-fbleau.fr/~brigitte/SAEWEB2.2/ci/index.php/Song/view/196','New Masters'); ?>
<?= anchor('https://dwarves.iut-fbleau.fr/~boutaric/SAEWEB2.2/ci/index.php/Song/view/88','Joe Cocker!'); ?> <?= anchor('https://dwarves.iut-fbleau.fr/~brigitte/SAEWEB2.2/ci/index.php/Song/view/88','Joe Cocker!'); ?>
<?= anchor('https://dwarves.iut-fbleau.fr/~boutaric/SAEWEB2.2/ci/index.php/Song/view/213','Dylan'); ?> <?= anchor('https://dwarves.iut-fbleau.fr/~brigitte/SAEWEB2.2/ci/index.php/Song/view/213','Dylan'); ?>
<?= anchor('https://dwarves.iut-fbleau.fr/~boutaric/SAEWEB2.2/ci/index.php/Song/view/142','Mothers Milk'); ?> <?= anchor('https://dwarves.iut-fbleau.fr/~brigitte/SAEWEB2.2/ci/index.php/Song/view/142','Mothers Milk'); ?>
</div> </div>
</li> </li>
<li class="menu_déroulant"><?= anchor('artistes','Artistes'); ?> <li class="menu_déroulant"><?= anchor('artistes','Artistes'); ?>
<div class="menu_déroulant_content"> <div class="menu_déroulant_content">
<?= anchor('https://dwarves.iut-fbleau.fr/~boutaric/SAEWEB2.2/ci/index.php/artistes/view/34','Queen'); ?> <?= anchor('https://dwarves.iut-fbleau.fr/~brigitte/SAEWEB2.2/ci/index.php/artistes/view/34','Queen'); ?>
<?= anchor('https://dwarves.iut-fbleau.fr/~boutaric/SAEWEB2.2/ci/index.php/Song/view/21','Slayer'); ?> <?= anchor('https://dwarves.iut-fbleau.fr/~brigitte/SAEWEB2.2/ci/index.php/Song/view/21','Slayer'); ?>
<?= anchor('https://dwarves.iut-fbleau.fr/~boutaric/SAEWEB2.2/ci/index.php/Song/view/63','Muse'); ?> <?= anchor('https://dwarves.iut-fbleau.fr/~brigitte/SAEWEB2.2/ci/index.php/Song/view/63','Muse'); ?>
<?= anchor('https://dwarves.iut-fbleau.fr/~boutaric/SAEWEB2.2/ci/index.php/Song/view/62','Tool'); ?> <?= anchor('https://dwarves.iut-fbleau.fr/~brigitte/SAEWEB2.2/ci/index.php/Song/view/62','Tool'); ?>
</div> </div>
</li> </li>
<li><?= anchor('playlist','Playlist'); ?></li> <li><?= anchor('playlist','Playlist'); ?></li>

View File

@ -3,8 +3,16 @@
foreach($songs as $song){ foreach($songs as $song){
echo "<div><article>"; echo "<div><article>";
echo "<header class='short-text'>"; echo "<header class='short-text'>";
echo "<form action='" . base_url("index.php/playlist/addSongToPlaylist") . "' method='post'>";
echo "{$song->name} "; echo "{$song->name} ";
echo " <button class='add-to-playlist' data-song='{$song->name}'>+</button>"; echo "<select name='playlist'>";
foreach ($playlists as $playlist) {
echo "<option value='{$playlist->id}'>{$playlist->name}</option>";
}
echo "</select>";
echo "<input type='hidden' name='song' value='{$song->name}' />";
echo "<button type='submit' class='add-to-playlist'>+</button>";
echo "</form>";
echo "<br>"; echo "<br>";
echo "</header>"; echo "</header>";
echo "</article></div>"; echo "</article></div>";
@ -12,3 +20,4 @@ foreach($songs as $song){
?> ?>
</section> </section>