Correction de bugs

This commit is contained in:
stiti 2024-05-25 19:13:36 +02:00
parent fb03d5b832
commit 82d46c251d
10 changed files with 206 additions and 80 deletions

View File

@ -57,6 +57,8 @@ $route['musiques'] = 'Musiques/index';
$route['artiste/(:num)'] = 'artiste/index/$1'; $route['artiste/(:num)'] = 'artiste/index/$1';
$route['search'] = 'search/index'; $route['search'] = 'search/index';
$route['mentions-legals'] = 'MentionsLegales/index'; $route['mentions-legals'] = 'MentionsLegales/index';
$route['playlists/add_artist/(:num)'] = 'playlists/add_artist/$1';

View File

@ -77,7 +77,12 @@ class Playlists extends CI_Controller {
'playlist_id' => $playlist_id, 'playlist_id' => $playlist_id,
'song_id' => $this->input->post('song_id') 'song_id' => $this->input->post('song_id')
); );
$this->Model_playlist->add_song_to_playlist($data); $result = $this->Model_playlist->add_song_to_playlist($data);
if ($result) {
$this->session->set_flashdata('success', 'La chanson a été ajoutée à la playlist.');
} else {
$this->session->set_flashdata('error', 'La chanson existe déjà dans la playlist.');
}
redirect('playlists/view/' . $playlist_id); redirect('playlists/view/' . $playlist_id);
} else { } else {
// Récupérer toutes les musiques disponibles // Récupérer toutes les musiques disponibles
@ -87,7 +92,8 @@ class Playlists extends CI_Controller {
$this->load->view('playlist_add_song', $data); $this->load->view('playlist_add_song', $data);
$this->load->view('layout/footer_dark'); $this->load->view('layout/footer_dark');
} }
} }
public function delete($playlist_id) { public function delete($playlist_id) {
$this->Model_playlist->delete_playlist($playlist_id); $this->Model_playlist->delete_playlist($playlist_id);
@ -148,24 +154,27 @@ class Playlists extends CI_Controller {
public function add_album($playlist_id) { public function add_album($playlist_id) {
if ($this->input->post()) { if ($this->input->post()) {
// Récupérer l'ID de l'album à partir du formulaire
$album_id = $this->input->post('album_id'); $album_id = $this->input->post('album_id');
// Récupérer toutes les chansons de l'album // Vérifier si les chansons de l'album existent déjà dans la playlist
$songs = $this->Model_music->get_songs_by_album($album_id); if ($this->Model_playlist->album_songs_exist_in_playlist($playlist_id, $album_id)) {
$this->session->set_flashdata('error', 'Certaines chansons de cet album existent déjà dans la playlist.');
} else {
$songs = $this->Model_music->get_songs_by_album($album_id);
// Ajouter chaque chanson à la playlist foreach ($songs as $song) {
foreach ($songs as $song) { $data = array(
$data = array( 'playlist_id' => $playlist_id,
'playlist_id' => $playlist_id, 'song_id' => $song->id
'song_id' => $song->id );
); $this->Model_playlist->add_song_to_playlist($data);
$this->Model_playlist->add_song_to_playlist($data); }
$this->session->set_flashdata('success', 'Album ajouté avec succès à la playlist.');
} }
redirect('playlists/view/' . $playlist_id); redirect('playlists/view/' . $playlist_id);
} else { } else {
// Récupérer tous les albums disponibles
$data['albums'] = $this->Model_music->get_all_albums(); $data['albums'] = $this->Model_music->get_all_albums();
$data['playlist_id'] = $playlist_id; $data['playlist_id'] = $playlist_id;
$this->load->view('layout/header_dark'); $this->load->view('layout/header_dark');
@ -174,6 +183,7 @@ class Playlists extends CI_Controller {
} }
} }
public function view($playlist_id) { public function view($playlist_id) {
// Charger les détails de la playlist spécifique en fonction de son 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); $data['playlist'] = $this->Model_playlist->get_playlist_by_id($playlist_id);
@ -187,7 +197,39 @@ class Playlists extends CI_Controller {
$this->load->view('layout/footer_dark'); $this->load->view('layout/footer_dark');
} }
public function add_artist($playlist_id) {
if ($this->input->post()) {
// Récupérer l'ID de l'artiste à partir du formulaire
$artist_id = $this->input->post('artist_id');
// Vérifier si les chansons de l'artiste existent déjà dans la playlist
if ($this->Model_playlist->artist_songs_exist_in_playlist($playlist_id, $artist_id)) {
$this->session->set_flashdata('error', 'Certaines chansons de cet artiste existent déjà dans la playlist.');
} else {
$songs = $this->Model_music->get_songs_by_artist($artist_id);
foreach ($songs as $song) {
$data = array(
'playlist_id' => $playlist_id,
'song_id' => $song->id
);
$this->Model_playlist->add_song_to_playlist($data);
}
$this->session->set_flashdata('success', 'Toutes les chansons de l\'artiste ont été ajoutées avec succès à la playlist.');
}
redirect('playlists/view/' . $playlist_id);
} else {
// Récupérer tous les artistes disponibles
$data['artists'] = $this->Model_music->get_all_artists();
$data['playlist_id'] = $playlist_id;
$this->load->view('layout/header_dark');
$this->load->view('playlist_add_artist', $data);
$this->load->view('layout/footer_dark');
}
}
} }
?> ?>

View File

@ -87,10 +87,6 @@ class Utilisateur extends CI_Controller {
redirect('/'); redirect('/');
} }
public function connexion(){ public function connexion(){
// Définir les règles de validation // Définir les règles de validation
$this->form_validation->set_rules('email', 'Email', 'required|valid_email'); $this->form_validation->set_rules('email', 'Email', 'required|valid_email');

View File

@ -135,6 +135,10 @@ class Model_music extends CI_Model {
public function get_all_albums() { public function get_all_albums() {
return $this->db->get('album')->result(); return $this->db->get('album')->result();
} }
public function get_all_artists() {
return $this->db->get('artist')->result();
}
public function get_songs_by_album($album_id) { public function get_songs_by_album($album_id) {
$this->db->select('song.*'); $this->db->select('song.*');
@ -144,7 +148,6 @@ class Model_music extends CI_Model {
return $this->db->get()->result(); return $this->db->get()->result();
} }
public function get_random_songs($limit) { public function get_random_songs($limit) {
$this->db->order_by('RAND()'); $this->db->order_by('RAND()');
$this->db->limit($limit); $this->db->limit($limit);
@ -215,5 +218,15 @@ class Model_music extends CI_Model {
return $query->row(); return $query->row();
} }
public function get_songs_by_artist($artist_id) {
$this->db->select('song.*');
$this->db->from('track');
$this->db->join('song', 'track.songid = song.id');
$this->db->join('album', 'track.albumid = album.id');
$this->db->where('album.artistid', $artist_id);
return $this->db->get()->result();
}
} }

View File

@ -43,11 +43,48 @@ class Model_playlist extends CI_Model {
return $this->db->delete('playlist'); return $this->db->delete('playlist');
} }
// Ajouter une chanson à une playlist
public function add_song_to_playlist($data) { public function add_song_to_playlist($data) {
// Vérifier si la combinaison playlist_id et song_id existe déjà
$this->db->where($data);
$existing_entry = $this->db->get('playlist_song')->row();
// Si la combinaison existe déjà, retourner false
if ($existing_entry) {
return false;
}
// Sinon, effectuer l'insertion
return $this->db->insert('playlist_song', $data); return $this->db->insert('playlist_song', $data);
} }
public function song_exists_in_playlist($playlist_id, $song_id) {
$this->db->where('playlist_id', $playlist_id);
$this->db->where('song_id', $song_id);
$query = $this->db->get('playlist_song');
return $query->num_rows() > 0;
}
public function artist_songs_exist_in_playlist($playlist_id, $artist_id) {
// Récupérer les chansons de l'artiste spécifié
$artist_songs = $this->Model_music->get_songs_by_artist($artist_id);
// Récupérer les chansons de la playlist
$playlist_songs = $this->get_songs_by_playlist($playlist_id);
// Vérifier chaque chanson de l'artiste dans la playlist
foreach ($artist_songs as $artist_song) {
foreach ($playlist_songs as $playlist_song) {
// Si la chanson de l'artiste est déjà dans la playlist, retourner true
if ($artist_song->id == $playlist_song->id) {
return true;
}
}
}
// Si aucune chanson de l'artiste n'est trouvée dans la playlist, retourner false
return false;
}
// Supprimer une chanson d'une playlist // Supprimer une chanson d'une playlist
public function remove_song_from_playlist($playlist_id, $song_id) { public function remove_song_from_playlist($playlist_id, $song_id) {
$this->db->where('playlist_id', $playlist_id); $this->db->where('playlist_id', $playlist_id);

View File

@ -1,64 +1,7 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<style> <link rel="stylesheet" href="<?php echo base_url('assets/css/nous-contacter'); ?>">
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
margin: 0;
padding: 0;
color: #640875;
}
.container {
width: 80%;
margin: 0 auto;
padding: 20px;
}
h1, h2, h3 {
color: #444;
}
.hero h1 {
color: #9f23b5;
}
.hero {
background-color: #2d1c30;
color: #fff;
padding: 50px 20px;
text-align: center;
}
.contact-form {
margin: 20px 0;
padding: 20px;
background: #fff;
border-radius: 8px;
box-shadow: 0 0 10px rgba(0,0,0,0.1);
}
.contact-form h2 {
margin-top: 0;
}
.contact-form input, .contact-form textarea {
width: 100%;
padding: 10px;
margin: 10px 0;
border: 1px solid #ccc;
border-radius: 4px;
}
.contact-form button {
padding: 10px 20px;
background-color: #333;
color: #fff;
border: none;
border-radius: 4px;
cursor: pointer;
}
</style>
<title>Nous contacter - Onzeur</title> <title>Nous contacter - Onzeur</title>
</head> </head>
<body> <body>

View File

@ -3,7 +3,7 @@
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>Ajouter un Album à la Playlist</title> <title>Ajouter un Album à la Playlist</title>
<link rel="stylesheet" href="<?php echo base_url('assets/css/style.css'); ?>"> <link rel="stylesheet" href="<?php echo base_url('assets/css/playlist_add_song'); ?>">
</head> </head>
<body> <body>
<div class="container"> <div class="container">

View File

@ -0,0 +1,24 @@
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<title>Ajouter les musiques d'un Artiste à la Playlist</title>
<link rel="stylesheet" href="<?php echo base_url('assets/css/playlist_add_song'); ?>">
</head>
<body>
<div class="container">
<h1>Ajouter les musiques d'un Artiste à la Playlist</h1>
<?php echo form_open('playlists/add_artist/'.$playlist_id); ?>
<div class="form-group">
<label for="artist_id">Sélectionner un Artiste :</label>
<select name="artist_id" class="form-control" required>
<?php foreach ($artists as $artist): ?>
<option value="<?php echo $artist->id; ?>"><?php echo $artist->name; ?></option>
<?php endforeach; ?>
</select>
</div>
<button type="submit" class="btn btn-primary">Ajouter les musiques de l'artiste</button>
<?php echo form_close(); ?>
</div>
</body>
</html>

View File

@ -3,10 +3,23 @@
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>Détails de la Playlist</title> <title>Détails de la Playlist</title>
<link rel="stylesheet" href="<?php echo base_url('assets/css/playlist_view'); ?>"> <link rel="stylesheet" href="<?php echo base_url('assets/css/playlist_view.css'); ?>">
</head> </head>
<body> <body>
<div class="container"> <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; ?>
<h1><?php echo htmlspecialchars($playlist->name, ENT_QUOTES, 'UTF-8'); ?></h1> <h1><?php echo htmlspecialchars($playlist->name, ENT_QUOTES, 'UTF-8'); ?></h1>
<form action="<?php echo site_url('playlists/update/' . $playlist->id); ?>" method="post"> <form action="<?php echo site_url('playlists/update/' . $playlist->id); ?>" method="post">
<div class="form-group"> <div class="form-group">
@ -48,6 +61,7 @@
<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_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_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> <a href="<?php echo site_url('playlists'); ?>" class="btn btn-secondary">Retour</a>
</div> </div>
</body> </body>

View File

@ -0,0 +1,55 @@
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
margin: 0;
padding: 0;
color: #640875;
}
.container {
width: 80%;
margin: 0 auto;
padding: 20px;
}
h1, h2, h3 {
color: #444;
}
.hero h1 {
color: #9f23b5;
}
.hero {
background-color: #2d1c30;
color: #fff;
padding: 50px 20px;
text-align: center;
}
.contact-form {
margin: 20px 0;
padding: 20px;
background: #fff;
border-radius: 8px;
box-shadow: 0 0 10px rgba(0,0,0,0.1);
}
.contact-form h2 {
margin-top: 0;
}
.contact-form input, .contact-form textarea {
width: 100%;
padding: 10px;
margin: 10px 0;
border: 1px solid #ccc;
border-radius: 4px;
}
.contact-form button {
padding: 10px 20px;
background-color: #333;
color: #fff;
border: none;
border-radius: 4px;
cursor: pointer;
}