Ajout de la playlist, ajout et suppression de son dans l'onglet playlist
This commit is contained in:
parent
ec78b24e7a
commit
ea4ced0442
codeigniter
application
controllers
models
views
assets
@ -26,12 +26,18 @@ class ConnexionController extends CI_Controller {
|
|||||||
$result = $query->row(); // Récupérer la première ligne de résultat
|
$result = $query->row(); // Récupérer la première ligne de résultat
|
||||||
|
|
||||||
if($result){ // Vérifier si l'utilisateur existe
|
if($result){ // Vérifier si l'utilisateur existe
|
||||||
|
$this->session->set_userdata('user_id', $result->id);
|
||||||
$this->session->set_userdata('pseudo', $result->pseudo);
|
$this->session->set_userdata('pseudo', $result->pseudo);
|
||||||
redirect('../index.php');
|
redirect('../index.php');
|
||||||
} else {
|
} else {
|
||||||
$data['error_msg'] = "Email ou mot de passe incorrect.";
|
$data['error_msg'] = "Email ou mot de passe incorrect.";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
echo "<pre>";
|
||||||
|
print_r($this->session->userdata());
|
||||||
|
echo "</pre>";
|
||||||
|
|
||||||
$this->load->view('layout/header');
|
$this->load->view('layout/header');
|
||||||
$this->load->view('connexion', $data);
|
$this->load->view('connexion', $data);
|
||||||
$this->load->view('layout/footer');
|
$this->load->view('layout/footer');
|
||||||
|
83
codeigniter/application/controllers/Playlist.php
Normal file
83
codeigniter/application/controllers/Playlist.php
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
<?php
|
||||||
|
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||||
|
|
||||||
|
class Playlist extends CI_Controller {
|
||||||
|
|
||||||
|
public function __construct(){
|
||||||
|
parent::__construct();
|
||||||
|
$this->load->model('model_music');
|
||||||
|
$this->load->helper('html');
|
||||||
|
$this->load->helper('url');
|
||||||
|
$this->load->helper('form');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function index(){
|
||||||
|
|
||||||
|
$userId = $this->session->userdata('user_id');
|
||||||
|
$playlists = $this->model_music->getPlaylistsByUser($userId);
|
||||||
|
$this->load->view('layout/header');
|
||||||
|
$this->load->view('playlist_list', ['playlists' => $playlists]);
|
||||||
|
$this->load->view('layout/footer');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function create(){
|
||||||
|
$name = $this->input->post('name');
|
||||||
|
$userId = $this->session->userdata('user_id');
|
||||||
|
$this->model_music->createPlaylist($name, $userId);
|
||||||
|
redirect('playlist');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function delete($playlistId){
|
||||||
|
$this->model_music->deletePlaylist($playlistId);
|
||||||
|
redirect('playlist');
|
||||||
|
}
|
||||||
|
|
||||||
|
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');
|
||||||
|
} else {
|
||||||
|
echo "Playlist non trouvée.";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function add_song(){
|
||||||
|
$playlistId = $this->input->post('playlistId');
|
||||||
|
$songId = $this->input->post('songId');
|
||||||
|
$this->model_music->addSongToPlaylist($playlistId, $songId);
|
||||||
|
redirect('playlists/view/' . $playlistId);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function remove_song(){
|
||||||
|
$playlistId = $this->input->post('playlistId');
|
||||||
|
$songId = $this->input->post('songId');
|
||||||
|
$this->model_music->removeSongFromPlaylist($playlistId, $songId);
|
||||||
|
redirect('playlist/view/' . $playlistId);
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
@ -132,4 +132,52 @@ class Model_music extends CI_Model {
|
|||||||
return $query->result();
|
return $query->result();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function createPlaylist($name, $userId) {
|
||||||
|
$data = array(
|
||||||
|
'name' => $name,
|
||||||
|
'userId' => $userId
|
||||||
|
);
|
||||||
|
return $this->db->insert('playlist', $data);
|
||||||
|
}
|
||||||
|
public function deletePlaylist($playlistId) {
|
||||||
|
$this->db->delete('playlist', array('id' => $playlistId));
|
||||||
|
$this->db->delete('playlistsong', array('playlistId' => $playlistId));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPlaylistsByUser($userId) {
|
||||||
|
$query = $this->db->get_where('playlist', array('userId' => $userId));
|
||||||
|
return $query->result();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPlaylistById($playlistId) {
|
||||||
|
$query = $this->db->get_where('playlist', array('id' => $playlistId), 1);
|
||||||
|
return $query->row(); // Renvoie la première ligne trouvée (la playlist correspondant à l'ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addSongToPlaylist($playlistId, $songId) {
|
||||||
|
$data = array(
|
||||||
|
'playlistId' => $playlistId,
|
||||||
|
'songId' => $songId
|
||||||
|
);
|
||||||
|
return $this->db->insert('playlistsong', $data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function removeSongFromPlaylist($playlistId, $songId) {
|
||||||
|
$this->db->delete('playlistsong', array('playlistId' => $playlistId, 'songId' => $songId));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getSongsByPlaylist($playlistId) {
|
||||||
|
$this->db->select('song.*');
|
||||||
|
$this->db->from('playlistsong');
|
||||||
|
$this->db->join('song', 'playlistsong.songId = song.id');
|
||||||
|
$this->db->where('playlistsong.playlistId', $playlistId);
|
||||||
|
$query = $this->db->get();
|
||||||
|
return $query->result();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function findSongByName($songName) {
|
||||||
|
$query = $this->db->get_where('song', array('name' => $songName));
|
||||||
|
return $query->row();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
25
codeigniter/application/views/playlist_list.php
Normal file
25
codeigniter/application/views/playlist_list.php
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
<h5>Mes Playlists</h5>
|
||||||
|
|
||||||
|
<!-- Formulaire pour créer la playlist avec le nom voulu -->
|
||||||
|
<form action="<?= site_url('playlist/create'); ?>" method="post" class="create-playlist-form">
|
||||||
|
<input type="text" name="name" placeholder="Nom de la playlist" required>
|
||||||
|
<button type="submit">Créer</button>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<!-- Affichez les playlist que nous avons -->
|
||||||
|
<section class="playlists">
|
||||||
|
<?php foreach($playlists as $playlist): ?>
|
||||||
|
<div>
|
||||||
|
<article>
|
||||||
|
<header class="short-text">
|
||||||
|
<?= anchor("playlist/view/{$playlist->id}", "{$playlist->name}"); ?>
|
||||||
|
</header>
|
||||||
|
<!-- Bouton pour supprimer la playlist -->
|
||||||
|
<form action="<?= site_url('playlist/delete/' . $playlist->id); ?>" method="post" style="display:inline;">
|
||||||
|
<button type="submit">Supprimer</button>
|
||||||
|
</form>
|
||||||
|
</article>
|
||||||
|
</div>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</section>
|
||||||
|
|
53
codeigniter/application/views/playlist_view.php
Normal file
53
codeigniter/application/views/playlist_view.php
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
<!-- En-tête de la playlist -->
|
||||||
|
<h5>Playlist : <?= $playlistName; ?></h5>
|
||||||
|
|
||||||
|
<!-- Formulaire pour rechercher et ajouter une chanson -->
|
||||||
|
<form action="<?= site_url('playlist/search_song'); ?>" method="post" class="add-song-form">
|
||||||
|
<input type="hidden" name="playlistId" value="<?= $playlistId; ?>">
|
||||||
|
<input type="text" name="songName" placeholder="Nom de la chanson" required>
|
||||||
|
<button type="submit">Rechercher et Ajouter</button>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<!-- Section pour afficher les résultats de la recherche -->
|
||||||
|
<?php if (!empty($searchResults)): ?>
|
||||||
|
<section class="search-results">
|
||||||
|
<h5>Résultats de la recherche :</h5>
|
||||||
|
<ul>
|
||||||
|
<?php foreach($searchResults as $song): ?>
|
||||||
|
<li>
|
||||||
|
<?= $song->name; ?>
|
||||||
|
<!-- Formulaire pour ajouter la chanson à la playlist -->
|
||||||
|
<form action="<?= site_url('playlist/add_song'); ?>" method="post" style="display:inline;">
|
||||||
|
<input type="hidden" name="playlistId" value="<?= $playlistId; ?>">
|
||||||
|
<input type="hidden" name="songId" value="<?= $song->id; ?>">
|
||||||
|
<button type="submit">Ajouter</button>
|
||||||
|
</form>
|
||||||
|
</li>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</ul>
|
||||||
|
</section>
|
||||||
|
<p>Test</p>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<!-- Section pour afficher les chansons de son playlist -->
|
||||||
|
<?php if (!empty($songs)): ?>
|
||||||
|
<section class="current-songs">
|
||||||
|
<h5>Chansons actuelles :</h5>
|
||||||
|
<ul>
|
||||||
|
<?php foreach($songs as $song): ?>
|
||||||
|
<li>
|
||||||
|
<?= $song->name; ?>
|
||||||
|
<!-- Formulaire pour supprimer la chanson de la playlist -->
|
||||||
|
<form action="<?= site_url('playlist/remove_song'); ?>" method="post" style="display:inline;">
|
||||||
|
<input type="hidden" name="playlistId" value="<?= $playlistId; ?>">
|
||||||
|
<input type="hidden" name="songId" value="<?= $song->id; ?>">
|
||||||
|
<button type="submit">Supprimer</button>
|
||||||
|
</form>
|
||||||
|
</li>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</ul>
|
||||||
|
</section>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<a href="<?= site_url('playlist'); ?>" class="btn btn-secondary">Retour à toutes les playlists</a>
|
||||||
|
|
27
codeigniter/application/views/song_search_results.php
Normal file
27
codeigniter/application/views/song_search_results.php
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
<h5>Résultats de la recherche pour : <?= $this->input->get('query'); ?></h5>
|
||||||
|
|
||||||
|
<form action="<?= site_url('playlist/search_song'); ?>" method="get" class="search-song-form">
|
||||||
|
<input type="text" name="query" placeholder="Nom de la chanson" required>
|
||||||
|
<button type="submit">Rechercher</button>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<section class="songs">
|
||||||
|
<?php foreach($songs as $song): ?>
|
||||||
|
<div>
|
||||||
|
<article>
|
||||||
|
<header class="short-text">
|
||||||
|
<?= $song->name; ?>
|
||||||
|
<form action="<?= site_url('playlists/add_song'); ?>" method="post" style="display:inline;">
|
||||||
|
<input type="hidden" name="songId" value="<?= $song->id; ?>">
|
||||||
|
<select name="playlistId" required>
|
||||||
|
<?php foreach($playlists as $playlist): ?>
|
||||||
|
<option value="<?= $playlist->id; ?>"><?= $playlist->name; ?></option>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</select>
|
||||||
|
<button type="submit">Ajouter à la playlist</button>
|
||||||
|
</form>
|
||||||
|
</header>
|
||||||
|
</article>
|
||||||
|
</div>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</section>
|
@ -195,3 +195,7 @@ div.new {
|
|||||||
.tri-button {
|
.tri-button {
|
||||||
width: 55%!important;
|
width: 55%!important;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
form.search-form {
|
||||||
|
margin-left: -200px;
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user