Commit de Louay : Grosse mise à jour

This commit is contained in:
stiti 2024-06-01 17:49:36 +02:00
parent 5096daeda0
commit 684ef237f4
8 changed files with 219 additions and 53 deletions

View File

@ -7,8 +7,10 @@ class Artiste extends CI_Controller {
parent::__construct();
$this->load->model('Model_artist');
$this->load->model('Model_music');
$this->load->model('Model_playlist');
$this->load->helper('url');
$this->load->helper('html');
$this->load->library('session');
}
public function index($artiste_id){
@ -23,6 +25,7 @@ class Artiste extends CI_Controller {
// Charger la vue avec les détails de l'artiste et ses albums
$data['artiste'] = $artiste;
$data['albums'] = $albums;
$data['mostUsedGenre'] = $mostUsedGenre; // Passer $mostUsedGenre à la vue
$data['title']="Détails de l'artiste - Onzeur ".$artiste->name;
$data['css'] = 'assets/css/artiste_details';
@ -51,6 +54,11 @@ class Artiste extends CI_Controller {
$data['title']="Détails de l'artiste - Onzeur ";
$data['css'] = 'assets/css/artists_list.css';
if ($this->session->userdata('user_id')) {
$user_id = $this->session->userdata('user_id');
$data['user_playlists'] = $this->Model_playlist->get_user_playlists($user_id);
}
$this->load->view('layout/header_dark',$data);
$this->load->view('artists_list', $data);
$this->load->view('layout/footer_dark');

View File

@ -316,19 +316,17 @@ class Playlists extends CI_Controller {
}
public function add_music_to_playlist($music_id, $playlist_id) {
// Vérifiez si l'utilisateur est connecté
// Vérifier si l'utilisateur est connecté
if (!$this->session->userdata('user_id')) {
redirect('utilisateur/connexion');
}
// Ajoutez la musique à la playlist spécifiée
$data = array(
'playlist_id' => $playlist_id,
'song_id' => $music_id // Utilisez 'song_id' au lieu de 'music_id'
'song_id' => $music_id
);
$this->Model_playlist->add_song_to_playlist($data);
// Redirigez l'utilisateur vers la vue de la playlist
redirect('playlists/view/' . $playlist_id);
}
@ -375,6 +373,56 @@ class Playlists extends CI_Controller {
$data['title']="Ajouter les musiques d'un Artiste à la Playlist";
$data['css']="assets/css/playlist_add_song";
$this->load->view('layout/header_dark', $data);
$this->load->view('playlist_add_artist',$data);
$this->load->view('layout/footer_dark');
}
}
public function add_artist_in_playlist_from_list($artist_id,$playlist_id = NULL) {
if($playlist_id === NULL){
$playlist_id = $this->input->post('playlist_id');
}
$this->verify_playlist_ownership($playlist_id);
if ($this->input->post() || $playlist_id) {
// Récupérer l'ID de l'artiste à partir du formulaire
$songs = $this->Model_music->get_songs_by_artist($artist_id);
$all_songs_exist = true; // Variable pour vérifier si toutes les chansons existent déjà dans la playlist
// Vérifier si toutes les chansons de l'artiste existent déjà dans la playlist
foreach ($songs as $song) {
if (!$this->Model_playlist->song_exists_in_playlist($playlist_id, $song->id)) {
$all_songs_exist = false;
break;
}
}
if ($all_songs_exist) {
$this->session->set_flashdata('error', 'Toutes les chansons de cet artiste existent déjà dans la playlist.');
} else {
foreach ($songs as $song) {
if (!$this->Model_playlist->song_exists_in_playlist($playlist_id, $song->id)) {
$data = array(
'playlist_id' => $playlist_id,
'song_id' => $song->id
);
$this->Model_playlist->add_song_to_playlist($data);
}
}
$this->session->set_flashdata('success', '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;
$data['title']="Ajouter les musiques d'un Artiste à la Playlist";
$data['css']="assets/css/playlist_add_song";
$this->load->view('layout/header_dark', $data);
$this->load->view('playlist_add_artist',$data);
$this->load->view('layout/footer_dark');

View File

@ -6,7 +6,9 @@ class Search extends CI_Controller {
public function __construct(){
parent::__construct();
$this->load->model('Search_model');
$this->load->model('Model_playlist');
$this->load->helper(['url', 'html']);
$this->load->library('session');
}
public function index(){
@ -39,6 +41,11 @@ class Search extends CI_Controller {
$data['albums'] = $albums;
$data['genres'] = $genres;
$data['artistes'] = $artistes;
if ($this->session->userdata('user_id')) {
$user_id = $this->session->userdata('user_id');
$data['user_playlists'] = $this->Model_playlist->get_user_playlists($user_id);
}
$data['title'] = "Résultats de la recherche";
$data['css'] = "assets/css/search_results";

View File

@ -74,4 +74,4 @@
// Redirection vers la méthode du contrôleur Playlists pour ajouter la chanson à la playlist spécifiée
window.location.href = "<?php echo base_url('index.php/playlists/add_album_to_playlist/'); ?>" + albumId + "/" + playlistId;
}
</script>
</script>

View File

@ -1,24 +1,33 @@
<div class="artist-list-container">
<h1>Liste des Artistes</h1>
<div class="sort-options">
<a href="<?php echo site_url('artiste/list_artists?order=ASC'); ?>">Trier par ordre alphabétique</a> |
<a href="<?php echo site_url('artiste/list_artists?order=DESC'); ?>">Trier par ordre inverse</a>
</div>
<ul class="artist-list">
<?php foreach($artists as $artist): ?>
<li>
<div class="artist-details">
<h2><?php echo $artist->name; ?></h2>
<p>
<a href="<?php echo site_url('artiste/'.$artist->id); ?>">Voir les détails</a> <br><br>
<a href="https://open.spotify.com/search/<?php echo urlencode($artist->name); ?>/artists" class="spotify" target="_blank">Spotify</a> |
<a href="https://www.deezer.com/search/<?php echo urlencode($artist->name); ?>/artist" class="deezer" target="_blank">Deezer</a> |
<a href="https://www.youtube.com/results?search_query=<?php echo urlencode($artist->name); ?>&sp=EgIQAg%253D%253D" class="youtube" target="_blank">YouTube</a>
</p>
</div>
</li>
<?php endforeach; ?>
</ul>
<div class="artist-list-container">
<h1>Liste des Artistes</h1>
<div class="sort-options">
<a href="<?php echo site_url('artiste/list_artists?order=ASC'); ?>">Trier par ordre alphabétique</a> |
<a href="<?php echo site_url('artiste/list_artists?order=DESC'); ?>">Trier par ordre inverse</a>
</div>
</body>
<ul class="artist-list">
<?php foreach($artists as $artist): ?>
<li>
<div class="artist-details">
<h2><?php echo $artist->name; ?></h2>
<p>
<a href="<?php echo site_url('artiste/'.$artist->id); ?>">Voir les détails</a> <br><br>
<a href="https://open.spotify.com/search/<?php echo urlencode($artist->name); ?>/artists" class="spotify" target="_blank">Spotify</a> |
<a href="https://www.deezer.com/search/<?php echo urlencode($artist->name); ?>/artist" class="deezer" target="_blank">Deezer</a> |
<a href="https://www.youtube.com/results?search_query=<?php echo urlencode($artist->name); ?>&sp=EgIQAg%253D%253D" class="youtube" target="_blank">YouTube</a>
</p>
<?php if ($this->session->userdata('user_id')): ?>
<form method="post" action="<?php echo site_url('playlists/add_artist_in_playlist_from_list/'.$artist->id); ?>">
<select name="playlist_id" class="select-playlist">
<?php foreach ($user_playlists as $playlist) : ?>
<option value="<?php echo $playlist->id; ?>"><?php echo $playlist->name; ?></option>
<?php endforeach; ?>
</select>
<input type="hidden" name="artist_id" value="<?php echo $artist->id; ?>">
<button type="submit" class="btn-add-to-playlist">Ajouter les musiques de l'artiste à la playlist</button>
</form>
<?php endif; ?>
</div>
</li>
<?php endforeach; ?>
</ul>
</div>

View File

@ -8,14 +8,22 @@
<div class="section">
<h3 class="section-title">Musiques</h3>
<ul class="music-list">
<?php foreach ($musiques as $musique): ?>
<li>
<?php echo htmlspecialchars($musique->name, ENT_QUOTES, 'UTF-8'); ?> -
<a href="<?php echo site_url('artiste/' . htmlspecialchars($musique->artist_id, ENT_QUOTES, 'UTF-8')); ?>">
<?php echo htmlspecialchars($musique->artistName, ENT_QUOTES, 'UTF-8'); ?>
</a>
</li>
<?php endforeach; ?>
<?php foreach ($musiques as $musique): ?>
<li>
<?php echo htmlspecialchars($musique->name, ENT_QUOTES, 'UTF-8'); ?> -
<a href="<?php echo site_url('artiste/' . htmlspecialchars($musique->artist_id, ENT_QUOTES, 'UTF-8')); ?>">
<?php echo htmlspecialchars($musique->artistName, ENT_QUOTES, 'UTF-8'); ?>
</a>
<?php if ($this->session->userdata('user_id')): ?>
<select id="playlist_<?php echo $musique->id; ?>" class="select-playlist">
<?php foreach ($user_playlists as $playlist) : ?>
<option value="<?php echo $playlist->id; ?>"><?php echo $playlist->name; ?></option>
<?php endforeach; ?>
</select>
<button onclick="addToMusicPlaylist(<?php echo $musique->id; ?>)" class="btn-add-to-playlist">Ajouter la musique à la playlist</button>
<?php endif; ?>
</li>
<?php endforeach; ?>
</ul>
</div>
<?php endif; ?>
@ -24,16 +32,24 @@
<div class="section">
<h3 class="section-title">Albums</h3>
<ul class="album-list">
<?php foreach ($albums as $album): ?>
<li>
<a href="<?php echo site_url('albums/view/' . htmlspecialchars($album->id, ENT_QUOTES, 'UTF-8')); ?>">
<?php echo htmlspecialchars($album->name, ENT_QUOTES, 'UTF-8'); ?>
</a> -
<a href="<?php echo site_url('artiste/' . htmlspecialchars($album->artist_id, ENT_QUOTES, 'UTF-8')); ?>">
<?php echo htmlspecialchars($album->artistName, ENT_QUOTES, 'UTF-8'); ?>
</a>
</li>
<?php endforeach; ?>
<?php foreach ($albums as $album): ?>
<li>
<a href="<?php echo site_url('albums/view/' . htmlspecialchars($album->id, ENT_QUOTES, 'UTF-8')); ?>">
<?php echo htmlspecialchars($album->name, ENT_QUOTES, 'UTF-8'); ?>
</a> -
<a href="<?php echo site_url('artiste/' . htmlspecialchars($album->artist_id, ENT_QUOTES, 'UTF-8')); ?>">
<?php echo htmlspecialchars($album->artistName, ENT_QUOTES, 'UTF-8'); ?>
</a>
<?php if ($this->session->userdata('user_id')): ?>
<select id="playlist_<?php echo $album->id; ?>" class="select-playlist">
<?php foreach ($user_playlists as $playlist) : ?>
<option value="<?php echo $playlist->id; ?>"><?php echo $playlist->name; ?></option>
<?php endforeach; ?>
</select>
<button onclick="addAlbumToPlaylist(<?php echo $album->id; ?>)" class="btn-add-to-playlist">Ajouter l'album à la playlist</button>
<?php endif; ?>
</li>
<?php endforeach; ?>
</ul>
</div>
<?php endif; ?>
@ -57,13 +73,21 @@
<div class="section">
<h3 class="section-title">Artistes</h3>
<ul class="artist-list">
<?php foreach ($artistes as $artiste): ?>
<li>
<a href="<?php echo site_url('artiste/' . htmlspecialchars($artiste->id, ENT_QUOTES, 'UTF-8')); ?>">
<?php echo htmlspecialchars($artiste->name, ENT_QUOTES, 'UTF-8'); ?>
</a>
</li>
<?php endforeach; ?>
<?php foreach ($artistes as $artiste): ?>
<li>
<a href="<?php echo site_url('artiste/' . htmlspecialchars($artiste->id, ENT_QUOTES, 'UTF-8')); ?>">
<?php echo htmlspecialchars($artiste->name, ENT_QUOTES, 'UTF-8'); ?>
</a>
<?php if ($this->session->userdata('user_id')): ?>
<select id="playlist_<?php echo $artiste->id; ?>" class="select-playlist">
<?php foreach ($user_playlists as $playlist) : ?>
<option value="<?php echo $playlist->id; ?>"><?php echo $playlist->name; ?></option>
<?php endforeach; ?>
</select>
<button onclick="addArtistToPlaylist(<?php echo $artiste->id; ?>)" class="btn-add-to-playlist">Ajouter l'artiste à la playlist</button>
<?php endif; ?>
</li>
<?php endforeach; ?>
</ul>
</div>
<?php endif; ?>
@ -73,3 +97,19 @@
<?php endif; ?>
</body>
<script>
function addToMusicPlaylist(musicId) {
var playlistId = document.getElementById('playlist_' + musicId).value;
window.location.href = "<?php echo base_url('index.php/playlists/add_music_to_playlist/'); ?>" + musicId + "/" + playlistId;
}
function addArtistToPlaylist(artistId) {
var playlistId = document.getElementById('playlist_' + artistId).value;
window.location.href = "<?php echo base_url('index.php/playlists/add_artist_in_playlist_from_list/'); ?>" + artistId + "/" + playlistId;
}
function addAlbumToPlaylist(albumId) {
var playlistId = document.getElementById('playlist_' + albumId).value;
window.location.href = "<?php echo base_url('index.php/playlists/add_album_to_playlist/'); ?>" + albumId + "/" + playlistId;
}
</script>

View File

@ -132,3 +132,35 @@ body {
color: rgb(255, 255, 255);
background-color: rgba(84, 15, 202, 0.8);
}
.select-playlist {
padding: 8px 15px;
font-size: 16px;
border: 1px solid #ccc;
border-radius: 4px;
background-color: #f0f0f0;
align-items: baseline;
}
.select-playlist option {
padding: 8px 15px;
font-size: 16px;
background-color: #fff;
color: #333;
}
.btn-add-to-playlist {
background-color: #6021aa;
color: white;
padding: 10px 20px;
margin-top: 10px;
border: none;
border-radius: 4px;
cursor: pointer;
transition: background-color 0.3s;
align-items: baseline;
}
.btn-add-to-playlist:hover {
background-color: #461860;
}

View File

@ -149,3 +149,25 @@ body {
.pagination .active {
background-color: #29043e;
}
.btn-add-to-playlist {
margin-top: 10px;
background-color: #4a0772;
color: #fff;
border: none;
padding: 5px 10px;
cursor: pointer;
border-radius: 3px;
}
.select-playlist {
margin-top: 10px;
display: block;
padding: 5px;
border: 1px solid #ccc;
border-radius: 3px;
}
.select-playlist option {
padding: 5px;
}