Gestions playlist ++
This commit is contained in:
parent
ea4ced0442
commit
9357b68c5d
codeigniter/application
@ -12,7 +12,6 @@ class Playlist extends CI_Controller {
|
||||
}
|
||||
|
||||
public function index(){
|
||||
|
||||
$userId = $this->session->userdata('user_id');
|
||||
$playlists = $this->model_music->getPlaylistsByUser($userId);
|
||||
$this->load->view('layout/header');
|
||||
@ -32,15 +31,29 @@ class Playlist extends CI_Controller {
|
||||
redirect('playlist');
|
||||
}
|
||||
|
||||
public function duplicate($id) {
|
||||
$playlist = $this->model_music->getPlaylistById($id);
|
||||
if ($playlist) {
|
||||
$newName = $playlist->name . '_bis';
|
||||
$userId = $this->session->userdata('user_id');
|
||||
$newPlaylistId = $this->model_music->createPlaylist($newName, $userId);
|
||||
$songs = $this->model_music->getSongsByPlaylist($id);
|
||||
foreach ($songs as $song) {
|
||||
$this->model_music->addSongToPlaylist($newPlaylistId, $song->id);
|
||||
}
|
||||
redirect('playlist/view/' . $newPlaylistId);
|
||||
} else {
|
||||
echo "Playlist non trouvée.";
|
||||
}
|
||||
}
|
||||
|
||||
public function view($id) {
|
||||
$songs = $this->model_music->getSongsByPlaylist($id);
|
||||
$playlist = $this->model_music->getPlaylistById($id);
|
||||
|
||||
if ($playlist) {
|
||||
$data['playlistName'] = $playlist->name; // Passez le nom de la playlist à la vue
|
||||
$data['songs'] = $songs;
|
||||
$data['playlistId'] = $id;
|
||||
|
||||
$this->load->view('layout/header');
|
||||
$this->load->view('playlist_view', $data);
|
||||
$this->load->view('layout/footer');
|
||||
@ -67,16 +80,46 @@ class Playlist extends CI_Controller {
|
||||
public function search_song(){
|
||||
$playlistId = $this->input->post('playlistId');
|
||||
$songName = $this->input->post('songName');
|
||||
|
||||
// Recherche la chanson par son nom
|
||||
$song = $this->model_music->findSongByName($songName);
|
||||
|
||||
if ($song) {
|
||||
// Si la chanson est trouvée, ajoutez-la à la playlist
|
||||
$this->model_music->addSongToPlaylist($playlistId, $song->id);
|
||||
}
|
||||
|
||||
// Redirige l'utilisateur vers la vue de la playlist mise à jour
|
||||
redirect('playlist/view/' . $playlistId);
|
||||
}
|
||||
|
||||
public function choose_playlist($songId) {
|
||||
$playlists = $this->model_music->getPlaylistsByUser($this->session->userdata('user_id'));
|
||||
$this->load->view('layout/header');
|
||||
$this->load->view('choose_playlist', ['playlists' => $playlists, 'songId' => $songId]);
|
||||
$this->load->view('layout/footer');
|
||||
}
|
||||
|
||||
|
||||
public function choix_playlist($albumId) {
|
||||
$playlists = $this->model_music->getPlaylistsByUser($this->session->userdata('user_id'));
|
||||
$this->load->view('layout/header');
|
||||
$this->load->view('choix_playlist', ['playlists' => $playlists, 'albumId' => $albumId]);
|
||||
$this->load->view('layout/footer');
|
||||
}
|
||||
|
||||
public function add_track() {
|
||||
$songId = $this->input->post('songId');
|
||||
$playlistId = $this->input->post('playlistId');
|
||||
if (!empty($songId) && !empty($playlistId)) {
|
||||
$this->model_music->addSongToPlaylist($playlistId, $songId);
|
||||
redirect('playlist/view/' . $playlistId);
|
||||
} else {
|
||||
echo "Erreur : Veuillez sélectionner une playlist.";
|
||||
}
|
||||
}
|
||||
|
||||
public function add_album_to_playlist() {
|
||||
$albumId = $this->input->post('albumId');
|
||||
$playlistId = $this->input->post('playlistId');
|
||||
$songs = $this->model_music->getMusicsByAlbum($albumId);
|
||||
foreach ($songs as $song) {
|
||||
$this->model_music->addSongToPlaylist($playlistId, $song->songId);
|
||||
}
|
||||
redirect('playlist/view/' . $playlistId);
|
||||
}
|
||||
}
|
||||
|
@ -125,9 +125,8 @@ class Model_music extends CI_Model {
|
||||
if (count($conditions) > 0) {
|
||||
$sql .= " WHERE " . implode(' AND ', $conditions);
|
||||
}
|
||||
|
||||
|
||||
$sql .= " ORDER BY album.id ASC";
|
||||
|
||||
$query = $this->db->query($sql, $params);
|
||||
return $query->result();
|
||||
}
|
||||
@ -137,7 +136,8 @@ class Model_music extends CI_Model {
|
||||
'name' => $name,
|
||||
'userId' => $userId
|
||||
);
|
||||
return $this->db->insert('playlist', $data);
|
||||
$this->db->insert('playlist', $data);
|
||||
return $this->db->insert_id();
|
||||
}
|
||||
public function deletePlaylist($playlistId) {
|
||||
$this->db->delete('playlist', array('id' => $playlistId));
|
||||
|
@ -1,19 +1,16 @@
|
||||
<h5>Liste des Musiques de l'Album</h5>
|
||||
<section class="list">
|
||||
<?php
|
||||
foreach ($musics as $music) {
|
||||
echo "<div><article>";
|
||||
echo "<ul>";
|
||||
echo "<li>$music->songName</li>";
|
||||
echo "<li>Durée: {$music->trackDuration} secondes</li>";
|
||||
// Ajout du bouton pour ajouter la musique à la playlist
|
||||
echo "<button onclick=\"location.href='" . site_url("playlist/add_track/{$music->songId}") . "'\">Ajouter à la Playlist</button>";
|
||||
echo "</ul>";
|
||||
echo "</article></div>";
|
||||
}
|
||||
?>
|
||||
</section>
|
||||
|
||||
|
||||
|
||||
|
||||
<?php foreach ($musics as $music): ?>
|
||||
<div>
|
||||
<article>
|
||||
<ul>
|
||||
<li><?= $music->songName ?></li>
|
||||
<li>Durée: <?= $music->trackDuration ?> secondes</li>
|
||||
<form action="<?= site_url('playlist/choose_playlist/' . $music->songId) ?>" method="get">
|
||||
<button type="submit">Ajouter à la Playlist</button>
|
||||
</form>
|
||||
</ul>
|
||||
</article>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
</section>
|
@ -40,7 +40,7 @@ foreach($albums as $album){
|
||||
echo "<header class='short-text'>";
|
||||
echo anchor("music/view/{$album->id}", "{$album->name}");
|
||||
echo "<br>";
|
||||
echo "<button onclick=\"location.href='" . site_url("playlist/add_track/{$album->id}") . "'\">Ajouter à la Playlist</button>";
|
||||
echo "<button onclick=\"location.href='" . site_url("playlist/choix_playlist/{$album->id}") . "'\">Ajouter toutes les music à la Playlist</button>";
|
||||
echo "</header>";
|
||||
echo '<img src="data:image/jpeg;base64,'.base64_encode($album->jpeg).'" />';
|
||||
echo "<footer class='short-text'>{$album->year} - {$album->artistName}</footer>
|
||||
|
@ -23,7 +23,7 @@ foreach ($artistAlbums as $artistName => $albums) {
|
||||
echo "<ul>";
|
||||
foreach ($albums as $album) {
|
||||
echo "<li>" . anchor("music/view/{$album['albumId']}", $album['albumName']) . " - " . $album['year'] . "</li>";
|
||||
echo "<button onclick=\"location.href='" . site_url("playlist/add_track/{$album['albumId']}") . "'\">Ajouter à la Playlist</button>";
|
||||
echo "<button onclick=\"location.href='" . site_url("playlist/choix_playlist/{$album['albumId']}") . "'\">Ajouter toutes les chansons à la Playlist</button>";
|
||||
}
|
||||
echo "</ul>";
|
||||
echo "</article></div>";
|
||||
|
12
codeigniter/application/views/choix_playlist.php
Normal file
12
codeigniter/application/views/choix_playlist.php
Normal file
@ -0,0 +1,12 @@
|
||||
<h5>Choisir une Playlist :</h5>
|
||||
<section class="list">
|
||||
<form action="<?= site_url('playlist/add_album_to_playlist') ?>" method="post">
|
||||
<input type="hidden" name="albumId" value="<?= $albumId ?>">
|
||||
<select name="playlistId">
|
||||
<?php foreach ($playlists as $playlist): ?>
|
||||
<option value="<?= $playlist->id ?>"><?= $playlist->name ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
<button type="submit">Ajouter toutes les chansons à la Playlist</button>
|
||||
</form>
|
||||
</section>
|
12
codeigniter/application/views/choose_playlist.php
Normal file
12
codeigniter/application/views/choose_playlist.php
Normal file
@ -0,0 +1,12 @@
|
||||
<h5>Choisir une Playlist :</h5>
|
||||
<section class="list">
|
||||
<form action="<?= site_url('playlist/add_track') ?>" method="post">
|
||||
<input type="hidden" name="songId" value="<?= $songId ?>">
|
||||
<select name="playlistId">
|
||||
<?php foreach ($playlists as $playlist): ?>
|
||||
<option value="<?= $playlist->id ?>"><?= $playlist->name ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
<button type="submit">Ajouter à la Playlist</button>
|
||||
</form>
|
||||
</section>
|
@ -1,4 +1,3 @@
|
||||
<!-- En-tête de la playlist -->
|
||||
<h5>Playlist : <?= $playlistName; ?></h5>
|
||||
|
||||
<!-- Formulaire pour rechercher et ajouter une chanson -->
|
||||
@ -49,5 +48,6 @@
|
||||
</section>
|
||||
<?php endif; ?>
|
||||
|
||||
<a href="<?= site_url('playlist/duplicate/' . $playlistId); ?>" class="btn btn-primary">Dupliquer cette playlist</a>
|
||||
<a href="<?= site_url('playlist'); ?>" class="btn btn-secondary">Retour à toutes les playlists</a>
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user