mirror of
https://grond.iut-fbleau.fr/stiti/SAE_2.02
synced 2024-12-27 01:12:18 +01:00
Commit de Louay : Grosse mise à jour
This commit is contained in:
parent
5096daeda0
commit
684ef237f4
@ -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');
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
@ -380,5 +378,55 @@ class Playlists extends CI_Controller {
|
||||
$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');
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
@ -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(){
|
||||
@ -40,6 +42,11 @@ class Search extends CI_Controller {
|
||||
$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";
|
||||
|
||||
|
@ -1,4 +1,3 @@
|
||||
|
||||
<div class="artist-list-container">
|
||||
<h1>Liste des Artistes</h1>
|
||||
<div class="sort-options">
|
||||
@ -16,9 +15,19 @@
|
||||
<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>
|
||||
</body>
|
||||
|
@ -14,6 +14,14 @@
|
||||
<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>
|
||||
@ -32,6 +40,14 @@
|
||||
<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>
|
||||
@ -62,6 +78,14 @@
|
||||
<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>
|
||||
@ -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>
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user