mirror of
https://grond.iut-fbleau.fr/stiti/SAE_2.02
synced 2024-11-12 22:01:41 +01:00
Ajout de la possibilité de rendre une playlist privée ou publique
This commit is contained in:
parent
a00bb1852e
commit
4095bea242
@ -15,22 +15,27 @@ class Playlists extends CI_Controller {
|
||||
public function index(){
|
||||
// Récupérer l'ID de l'utilisateur connecté depuis la session
|
||||
$user_id = $this->session->userdata('user_id');
|
||||
|
||||
|
||||
// Vérifier si l'utilisateur est connecté
|
||||
if ($user_id) {
|
||||
// Récupérer les playlists de l'utilisateur connecté
|
||||
$data['playlists'] = $this->Model_playlist->get_user_playlists($user_id);
|
||||
|
||||
|
||||
// Récupérer les playlists publiques
|
||||
$data['public_playlists'] = $this->Model_playlist->get_public_playlists($user_id);
|
||||
|
||||
$data['title']="Liste des Playlists - Onzeur";
|
||||
$data['css']="assets/css/playlists_list.css";
|
||||
|
||||
|
||||
$this->load->view('layout/header_dark', $data);
|
||||
$this->load->view('playlists_list',$data);
|
||||
$this->load->view('playlists_list', $data);
|
||||
$this->load->view('layout/footer_dark');
|
||||
} else {
|
||||
redirect('utilisateur/connexion');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function verify_playlist_ownership($playlist_id) {
|
||||
// Vérifier si l'utilisateur est connecté
|
||||
if (!$this->session->userdata('user_id')) {
|
||||
@ -63,7 +68,8 @@ class Playlists extends CI_Controller {
|
||||
$data = array(
|
||||
'name' => $this->input->post('name'),
|
||||
'description' => $this->input->post('description'),
|
||||
'utilisateur_id' => $user_id // Ajoutez l'ID de l'utilisateur
|
||||
'utilisateur_id' => $user_id, // Ajoutez l'ID de l'utilisateur
|
||||
'public' => $this->input->post('public') ? 1 : 0 // Champ pour définir si la playlist est publique ou privée
|
||||
);
|
||||
$this->Model_playlist->create_playlist($data);
|
||||
redirect('playlists');
|
||||
@ -73,10 +79,10 @@ class Playlists extends CI_Controller {
|
||||
redirect('utilisateur/connexion');
|
||||
}
|
||||
} else {
|
||||
|
||||
|
||||
$data['title']="Créer une Nouvelle Playlist";
|
||||
$data['css']="assets/css/playlist_create";
|
||||
|
||||
|
||||
$this->load->view('layout/header_dark', $data);
|
||||
$this->load->view('playlist_create');
|
||||
$this->load->view('layout/footer_dark');
|
||||
@ -84,7 +90,7 @@ class Playlists extends CI_Controller {
|
||||
}
|
||||
|
||||
public function update($playlist_id) {
|
||||
// Vérifier si l'utilisateur est connecté
|
||||
// Vérifier si l'utilisateur est connecté et s'il est propriétaire de la playlist
|
||||
$this->verify_playlist_ownership($playlist_id);
|
||||
|
||||
// Récupérer l'ID de l'utilisateur connecté
|
||||
@ -101,7 +107,8 @@ class Playlists extends CI_Controller {
|
||||
if ($this->input->post()) {
|
||||
$data = array(
|
||||
'name' => $this->input->post('name'),
|
||||
'description' => $this->input->post('description')
|
||||
'description' => $this->input->post('description'),
|
||||
'public' => $this->input->post('public') ? 1 : 0 // Mise à jour de la visibilité
|
||||
);
|
||||
$this->Model_playlist->update_playlist($playlist_id, $data);
|
||||
redirect('playlists/view/' . $playlist_id);
|
||||
@ -109,7 +116,7 @@ class Playlists extends CI_Controller {
|
||||
// Gérer le cas où les données POST ne sont pas disponibles
|
||||
redirect('playlists/view/' . $playlist_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function add_song($playlist_id) {
|
||||
$this->verify_playlist_ownership($playlist_id);
|
||||
@ -253,25 +260,39 @@ class Playlists extends CI_Controller {
|
||||
}
|
||||
|
||||
public function view($playlist_id) {
|
||||
$this->verify_playlist_ownership($playlist_id);
|
||||
|
||||
// Vérifiez si la playlist est accessible à l'utilisateur actuellement connecté
|
||||
$this->verify_playlist_accessibility($playlist_id);
|
||||
|
||||
// Charger les détails de la playlist spécifique en fonction de son ID
|
||||
$data['playlist'] = $this->Model_playlist->get_playlist_by_id($playlist_id);
|
||||
|
||||
|
||||
// Charger les chansons de la playlist spécifique
|
||||
$data['songs'] = $this->Model_playlist->get_songs_by_playlist($playlist_id);
|
||||
|
||||
|
||||
$data['title']="Détails de la Playlist - Onzeur";
|
||||
$data['css']="assets/css/playlist_view";
|
||||
|
||||
|
||||
|
||||
$data['title'] = "Détails de la Playlist - Onzeur";
|
||||
$data['css'] = "assets/css/playlist_view";
|
||||
|
||||
// Charger la vue pour afficher les détails de la playlist
|
||||
$this->load->view('layout/header_dark', $data);
|
||||
$this->load->view('playlist_view', $data);
|
||||
$this->load->view('layout/footer_dark');
|
||||
}
|
||||
|
||||
private function verify_playlist_accessibility($playlist_id) {
|
||||
// Récupérer l'ID de l'utilisateur connecté
|
||||
$user_id = $this->session->userdata('user_id');
|
||||
|
||||
// Récupérer les détails de la playlist
|
||||
$playlist = $this->Model_playlist->get_playlist_by_id($playlist_id);
|
||||
|
||||
// Vérifier si la playlist existe et si elle est publique
|
||||
if (!$playlist || ($playlist->public == 0 && $playlist->utilisateur_id !== $user_id)) {
|
||||
// Rediriger vers une page d'erreur ou une page appropriée
|
||||
redirect('erreur/page_non_autorisee');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function add_artist($playlist_id) {
|
||||
$this->verify_playlist_ownership($playlist_id);
|
||||
|
||||
|
@ -8,10 +8,11 @@ class Model_playlist extends CI_Model {
|
||||
}
|
||||
|
||||
public function create_playlist($data) {
|
||||
// Récupérer l'ID de l'utilisateur à partir de la session
|
||||
$user_id = $this->session->userdata('user_id');
|
||||
if ($user_id !== null) {
|
||||
$data['utilisateur_id'] = $user_id;
|
||||
// Définir la visibilité par défaut
|
||||
$data['public'] = 0; // Playlist privée par défaut
|
||||
return $this->db->insert('playlist', $data);
|
||||
} else {
|
||||
return false;
|
||||
@ -26,10 +27,11 @@ class Model_playlist extends CI_Model {
|
||||
// Récupérer toutes les playlists d'un utilisateur spécifique
|
||||
public function get_user_playlists($user_id) {
|
||||
$this->db->where('utilisateur_id', $user_id);
|
||||
// Ne récupérer que les playlists publiques ou celles appartenant à l'utilisateur
|
||||
$this->db->where('(public = 1 OR utilisateur_id = ' . $user_id . ')');
|
||||
return $this->db->get('playlist')->result();
|
||||
}
|
||||
|
||||
|
||||
// Mettre à jour une playlist
|
||||
public function update_playlist($playlist_id, $data) {
|
||||
$this->db->where('id', $playlist_id);
|
||||
@ -115,5 +117,13 @@ class Model_playlist extends CI_Model {
|
||||
public function add_album_to_playlist($data) {
|
||||
return $this->db->insert('playlist_album', $data);
|
||||
}
|
||||
|
||||
public function get_public_playlists($user_id) {
|
||||
// Récupérer les playlists publiques en excluant celles de l'utilisateur connecté
|
||||
$this->db->where('utilisateur_id !=', $user_id);
|
||||
$this->db->where('public', 1);
|
||||
return $this->db->get('playlist')->result();
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
|
@ -1,18 +1,20 @@
|
||||
<div class="container">
|
||||
<!-- Messages Flash -->
|
||||
<?php if($this->session->flashdata('success')): ?>
|
||||
<div class="alert alert-success mt-3">
|
||||
<?php echo $this->session->flashdata('success'); ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<div class="container">
|
||||
<!-- Messages Flash -->
|
||||
<?php if($this->session->flashdata('success')): ?>
|
||||
<div class="alert alert-success mt-3">
|
||||
<?php echo $this->session->flashdata('success'); ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if($this->session->flashdata('error')): ?>
|
||||
<div class="alert alert-danger mt-3">
|
||||
<?php echo $this->session->flashdata('error'); ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php if($this->session->flashdata('error')): ?>
|
||||
<div class="alert alert-danger mt-3">
|
||||
<?php echo $this->session->flashdata('error'); ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<h1><?php echo htmlspecialchars($playlist->name, ENT_QUOTES, 'UTF-8'); ?></h1>
|
||||
<h1><?php echo htmlspecialchars($playlist->name, ENT_QUOTES, 'UTF-8'); ?></h1>
|
||||
|
||||
<?php if ($this->session->userdata('user_id') === $playlist->utilisateur_id): ?>
|
||||
<form action="<?php echo site_url('playlists/update/' . $playlist->id); ?>" method="post">
|
||||
<div class="form-group">
|
||||
<label for="name">Nom de la Playlist:</label>
|
||||
@ -22,45 +24,58 @@
|
||||
<label for="description">Description de la Playlist:</label>
|
||||
<textarea name="description" class="form-control" required><?php echo htmlspecialchars($playlist->description, ENT_QUOTES, 'UTF-8'); ?></textarea>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="visibility">Visibilité de la Playlist:</label>
|
||||
<select name="public" class="form-control">
|
||||
<option value="1" <?php if ($playlist->public == 1) echo 'selected'; ?>>Public</option>
|
||||
<option value="0" <?php if ($playlist->public == 0) echo 'selected'; ?>>Privé</option>
|
||||
</select>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary">Enregistrer</button>
|
||||
</form>
|
||||
<?php endif; ?>
|
||||
|
||||
<h2>Chansons</h2>
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Titre</th>
|
||||
<th>Artiste</th>
|
||||
<th>Écouter sur</th>
|
||||
<h2>Chansons</h2>
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Titre</th>
|
||||
<th>Artiste</th>
|
||||
<th>Écouter sur</th>
|
||||
<?php if ($this->session->userdata('user_id') === $playlist->utilisateur_id): ?>
|
||||
<th>Actions</th>
|
||||
</tr>
|
||||
<tbody>
|
||||
<?php if (!empty($songs)) : ?>
|
||||
<?php foreach ($songs as $song) : ?>
|
||||
<tr>
|
||||
<td><?php echo htmlspecialchars($song->name, ENT_QUOTES, 'UTF-8'); ?></td>
|
||||
<td><a href="<?php echo site_url('artiste/index/' . $song->artistId); ?>"><?php echo htmlspecialchars($song->artist_name, ENT_QUOTES, 'UTF-8'); ?></a></td>
|
||||
<td>
|
||||
<a href="https://open.spotify.com/search/<?php echo urlencode($song->artist_name . ' ' . $song->name); ?>" class="spotify" target="_blank">Spotify</a> |
|
||||
<a href="https://www.deezer.com/search/<?php echo urlencode($song->artist_name . ' ' . $song->name); ?>" class="deezer" target="_blank">Deezer</a> |
|
||||
<a href="https://www.youtube.com/results?search_query=<?php echo urlencode($song->artist_name . ' ' . $song->name); ?>" class="youtube" target="_blank">YouTube</a>
|
||||
</td>
|
||||
<?php endif; ?>
|
||||
</tr>
|
||||
<tbody>
|
||||
<?php if (!empty($songs)) : ?>
|
||||
<?php foreach ($songs as $song) : ?>
|
||||
<tr>
|
||||
<td><?php echo htmlspecialchars($song->name, ENT_QUOTES, 'UTF-8'); ?></td>
|
||||
<td><a href="<?php echo site_url('artiste/index/' . $song->artistId); ?>"><?php echo htmlspecialchars($song->artist_name, ENT_QUOTES, 'UTF-8'); ?></a></td>
|
||||
<td>
|
||||
<a href="https://open.spotify.com/search/<?php echo urlencode($song->artist_name . ' ' . $song->name); ?>" class="spotify" target="_blank">Spotify</a> |
|
||||
<a href="https://www.deezer.com/search/<?php echo urlencode($song->artist_name . ' ' . $song->name); ?>" class="deezer" target="_blank">Deezer</a> |
|
||||
<a href="https://www.youtube.com/results?search_query=<?php echo urlencode($song->artist_name . ' ' . $song->name); ?>" class="youtube" target="_blank">YouTube</a>
|
||||
</td>
|
||||
<?php if ($this->session->userdata('user_id') === $playlist->utilisateur_id): ?>
|
||||
<td>
|
||||
<a href="<?php echo site_url('playlists/remove_song/' . $playlist->id . '/' . $song->id); ?>" class="btn btn-danger" onclick="return confirm('Êtes-vous sûr de vouloir supprimer cette chanson de la playlist ?');">Supprimer</a>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
<?php else : ?>
|
||||
<tr>
|
||||
<td colspan="4">Aucune chanson trouvée dans cette playlist.</td>
|
||||
<?php endif; ?>
|
||||
</tr>
|
||||
<?php endif; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
<?php endforeach; ?>
|
||||
<?php else : ?>
|
||||
<tr>
|
||||
<td colspan="<?php echo ($this->session->userdata('user_id') === $playlist->utilisateur_id) ? '4' : '3'; ?>">Aucune chanson trouvée dans cette playlist.</td>
|
||||
</tr>
|
||||
<?php endif; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<?php if ($this->session->userdata('user_id') === $playlist->utilisateur_id): ?>
|
||||
<a href="<?php echo site_url('playlists/add_song/' . $playlist->id); ?>" class="btn btn-primary">Ajouter une musique</a>
|
||||
<a href="<?php echo site_url('playlists/add_album/' . $playlist->id); ?>" class="btn btn-primary">Ajouter un album</a>
|
||||
<a href="<?php echo site_url('playlists/add_artist/' . $playlist->id); ?>" class="btn btn-primary">Ajouter les musiques d'un artiste</a>
|
||||
<a href="<?php echo site_url('playlists'); ?>" class="btn btn-secondary">Retour</a>
|
||||
</div>
|
||||
</body>
|
||||
<?php endif; ?>
|
||||
<a href="<?php echo site_url('playlists'); ?>" class="btn btn-secondary">Retour</a>
|
||||
</div>
|
||||
|
@ -1,34 +1,61 @@
|
||||
<div class="container">
|
||||
<h1>Liste des Playlists</h1>
|
||||
<a href="<?php echo site_url('playlists/create'); ?>" class="btn btn-primary">Créer une Nouvelle Playlist</a>
|
||||
<a href="<?php echo site_url('playlists/generate_random'); ?>" class="btn btn-primary">Générer une playlist aléatoire</a>
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Nom</th>
|
||||
<th>Description</th>
|
||||
<th>Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php if (!empty($playlists)) : ?>
|
||||
<?php foreach ($playlists as $playlist) : ?>
|
||||
<tr>
|
||||
<td><?php echo htmlspecialchars($playlist->name, ENT_QUOTES, 'UTF-8'); ?></td>
|
||||
<td><?php echo htmlspecialchars($playlist->description, ENT_QUOTES, 'UTF-8'); ?></td>
|
||||
<td>
|
||||
<a href="<?php echo site_url('playlists/view/' . $playlist->id); ?>" class="btn btn-info">Voir</a>
|
||||
<a href="<?php echo site_url('playlists/delete/' . $playlist->id); ?>" class="btn btn-danger" onclick="return confirm('Êtes-vous sûr de vouloir supprimer cette playlist ?');">Supprimer</a>
|
||||
<a href="<?php echo site_url('playlists/duplicate/' . $playlist->id); ?>" class="btn btn-warning" onclick="return confirm('Êtes-vous sûr de vouloir dupliquer cette playlist ?');">Dupliquer</a>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
<?php else : ?>
|
||||
<div class="container">
|
||||
<h1>Liste des Playlists</h1>
|
||||
<a href="<?php echo site_url('playlists/create'); ?>" class="btn btn-primary">Créer une Nouvelle Playlist</a>
|
||||
<a href="<?php echo site_url('playlists/generate_random'); ?>" class="btn btn-primary">Générer une playlist aléatoire</a>
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Nom</th>
|
||||
<th>Description</th>
|
||||
<th>Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php if (!empty($playlists)) : ?>
|
||||
<?php foreach ($playlists as $playlist) : ?>
|
||||
<tr>
|
||||
<td colspan="3">Aucune playlist trouvée.</td>
|
||||
<td><?php echo htmlspecialchars($playlist->name, ENT_QUOTES, 'UTF-8'); ?></td>
|
||||
<td><?php echo htmlspecialchars($playlist->description, ENT_QUOTES, 'UTF-8'); ?></td>
|
||||
<td>
|
||||
<a href="<?php echo site_url('playlists/view/' . $playlist->id); ?>" class="btn btn-info">Voir</a>
|
||||
<a href="<?php echo site_url('playlists/delete/' . $playlist->id); ?>" class="btn btn-danger" onclick="return confirm('Êtes-vous sûr de vouloir supprimer cette playlist ?');">Supprimer</a>
|
||||
<a href="<?php echo site_url('playlists/duplicate/' . $playlist->id); ?>" class="btn btn-warning" onclick="return confirm('Êtes-vous sûr de vouloir dupliquer cette playlist ?');">Dupliquer</a>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endif; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</body>
|
||||
<?php endforeach; ?>
|
||||
<?php else : ?>
|
||||
<tr>
|
||||
<td colspan="3">Aucune playlist trouvée.</td>
|
||||
</tr>
|
||||
<?php endif; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<h1><br>Playlists Publiques</h1>
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Nom</th>
|
||||
<th>Description</th>
|
||||
<th>Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php if (!empty($public_playlists)) : ?>
|
||||
<?php foreach ($public_playlists as $playlist) : ?>
|
||||
<tr>
|
||||
<td><?php echo htmlspecialchars($playlist->name, ENT_QUOTES, 'UTF-8'); ?></td>
|
||||
<td><?php echo htmlspecialchars($playlist->description, ENT_QUOTES, 'UTF-8'); ?></td>
|
||||
<td>
|
||||
<a href="<?php echo site_url('playlists/view/' . $playlist->id); ?>" class="btn btn-info">Voir</a>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
<?php else : ?>
|
||||
<tr>
|
||||
<td colspan="3">Aucune playlist publique trouvée.</td>
|
||||
</tr>
|
||||
<?php endif; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user