mirror of
https://grond.iut-fbleau.fr/stiti/SAE_2.02
synced 2024-12-27 01:12:18 +01:00
modifications
This commit is contained in:
parent
2aba540016
commit
fc16b575ed
@ -33,8 +33,7 @@ class Playlists extends CI_Controller {
|
||||
} else {
|
||||
redirect('utilisateur/connexion');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function verify_playlist_ownership($playlist_id) {
|
||||
// Vérifier si l'utilisateur est connecté
|
||||
@ -120,7 +119,6 @@ class Playlists extends CI_Controller {
|
||||
|
||||
public function add_song($playlist_id) {
|
||||
$this->verify_playlist_ownership($playlist_id);
|
||||
|
||||
if ($this->input->post()) {
|
||||
$data = array(
|
||||
'playlist_id' => $playlist_id,
|
||||
@ -134,10 +132,8 @@ class Playlists extends CI_Controller {
|
||||
}
|
||||
redirect('playlists/view/' . $playlist_id);
|
||||
} else {
|
||||
// Récupérer toutes les musiques disponibles
|
||||
$data['songs'] = $this->Model_music->get_all_songs();
|
||||
$data['playlist_id'] = $playlist_id;
|
||||
|
||||
$data['title']="Ajouter une Chanson à la Playlist";
|
||||
$data['css']="assets/css/playlist_add_song";
|
||||
|
||||
@ -149,7 +145,6 @@ class Playlists extends CI_Controller {
|
||||
|
||||
public function delete($playlist_id) {
|
||||
$this->verify_playlist_ownership($playlist_id);
|
||||
|
||||
$this->Model_playlist->delete_playlist($playlist_id);
|
||||
redirect('playlists');
|
||||
}
|
||||
@ -163,7 +158,6 @@ class Playlists extends CI_Controller {
|
||||
|
||||
public function duplicate($playlist_id) {
|
||||
$this->verify_playlist_ownership($playlist_id);
|
||||
|
||||
$playlist = $this->Model_playlist->get_playlist_by_id($playlist_id);
|
||||
$songs = $this->Model_playlist->get_songs_by_playlist($playlist_id);
|
||||
|
||||
@ -191,27 +185,43 @@ class Playlists extends CI_Controller {
|
||||
if (!$this->session->userdata('user_id')) {
|
||||
redirect('utilisateur/connexion');
|
||||
}
|
||||
|
||||
$nbrMusiqueAleatoire = 10;
|
||||
$songs = $this->Model_music->get_random_songs($nbrMusiqueAleatoire); // 10 chansons aléatoires
|
||||
$new_playlist = array(
|
||||
'name' => 'Playlist aléatoire du ' . date('Y-m-d H:i:s'),
|
||||
'description' => 'Une playlist avec ' . $nbrMusiqueAleatoire . ' musiques aléatoires.',
|
||||
'utilisateur_id' => $this->session->userdata('user_id')
|
||||
);
|
||||
|
||||
$this->Model_playlist->create_playlist($new_playlist);
|
||||
$new_playlist_id = $this->db->insert_id();
|
||||
|
||||
foreach ($songs as $song) {
|
||||
$data = array(
|
||||
'playlist_id' => $new_playlist_id,
|
||||
'song_id' => $song->id
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$genre = $this->input->post('genre');
|
||||
$artist = $this->input->post('artist');
|
||||
$nbrMusiqueAleatoire = $this->input->post('nbrMusiqueAleatoire');
|
||||
$nbrMusiqueAleatoire = is_numeric($nbrMusiqueAleatoire) ? intval($nbrMusiqueAleatoire) : 10;
|
||||
$songs = $this->Model_music->get_random_songs($nbrMusiqueAleatoire, $genre, $artist);
|
||||
|
||||
$new_playlist = array(
|
||||
'name' => 'Playlist aléatoire du ' . date('Y-m-d H:i:s'),
|
||||
'description' => 'Une playlist avec ' . $nbrMusiqueAleatoire . ' musiques aléatoires.',
|
||||
'utilisateur_id' => $this->session->userdata('user_id')
|
||||
);
|
||||
$this->Model_playlist->add_song_to_playlist($data);
|
||||
}
|
||||
|
||||
$this->Model_playlist->create_playlist($new_playlist);
|
||||
$new_playlist_id = $this->db->insert_id();
|
||||
|
||||
foreach ($songs as $song) {
|
||||
$data = array(
|
||||
'playlist_id' => $new_playlist_id,
|
||||
'song_id' => $song->id
|
||||
);
|
||||
$this->Model_playlist->add_song_to_playlist($data);
|
||||
}
|
||||
|
||||
redirect('playlists');
|
||||
} else {
|
||||
$data['genres'] = $this->Model_music->get_all_genres();
|
||||
$data['artists'] = $this->Model_music->get_all_artists();
|
||||
$data['title']="Générer une playlist - Onzeur";
|
||||
$data['css']="assets/css/generate_playlist";
|
||||
|
||||
redirect('playlists');
|
||||
|
||||
$this->load->view('layout/header_dark',$data);
|
||||
$this->load->view('generate_playlist', $data);
|
||||
$this->load->view('layout/footer_dark');
|
||||
}
|
||||
}
|
||||
|
||||
public function add_album($playlist_id) {
|
||||
|
@ -157,10 +157,6 @@ class Model_music extends CI_Model {
|
||||
public function get_all_albums() {
|
||||
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) {
|
||||
$this->db->select('song.*');
|
||||
@ -170,13 +166,42 @@ class Model_music extends CI_Model {
|
||||
return $this->db->get()->result();
|
||||
}
|
||||
|
||||
public function get_random_songs($limit) {
|
||||
public function get_random_songs($limit, $genre = null, $artist = null) {
|
||||
$this->db->select('song.id, song.name');
|
||||
$this->db->from('song');
|
||||
$this->db->join('track', 'track.songId = song.id');
|
||||
$this->db->join('album', 'album.id = track.albumId');
|
||||
$this->db->join('artist', 'artist.id = album.artistId', 'left');
|
||||
$this->db->join('genre', 'genre.id = album.genreId', 'left');
|
||||
|
||||
if ($genre) {
|
||||
$this->db->where('genre.name', $genre);
|
||||
}
|
||||
if ($artist) {
|
||||
$this->db->where('artist.name', $artist);
|
||||
}
|
||||
|
||||
$this->db->order_by('RAND()');
|
||||
$this->db->limit($limit);
|
||||
return $this->db->get('song')->result();
|
||||
|
||||
$query = $this->db->get();
|
||||
return $query->result();
|
||||
}
|
||||
|
||||
public function get_all_genres() {
|
||||
$this->db->distinct();
|
||||
$this->db->select('name');
|
||||
$query = $this->db->get('genre');
|
||||
return array_column($query->result_array(), 'name');
|
||||
}
|
||||
|
||||
public function get_all_artists() {
|
||||
$this->db->distinct();
|
||||
$this->db->select('name');
|
||||
$query = $this->db->get('artist');
|
||||
return array_column($query->result_array(), 'name');
|
||||
}
|
||||
|
||||
|
||||
public function get_total_musiques(){
|
||||
$query = $this->db->query("SELECT COUNT(*) as total_musiques FROM song");
|
||||
$result = $query->row();
|
||||
|
25
CodeIgniter-3.1.13/application/views/generate_playlist.php
Normal file
25
CodeIgniter-3.1.13/application/views/generate_playlist.php
Normal file
@ -0,0 +1,25 @@
|
||||
<body>
|
||||
<h1>Générer une playlist</h1>
|
||||
<form action="<?php echo site_url('playlists/generate_random'); ?>" method="post" class="formulaire">
|
||||
<label for="nbrMusiqueAleatoire">Nombre de musiques :</label>
|
||||
<input type="number" name="nbrMusiqueAleatoire" id="nbrMusiqueAleatoire" value="5" min="1" max="50"><br><br>
|
||||
|
||||
<label for="genre">Genre :</label>
|
||||
<select name="genre" id="genre">
|
||||
<option value="">Tous les genres</option>
|
||||
<?php foreach ($genres as $genre): ?>
|
||||
<option value="<?php echo $genre; ?>"><?php echo $genre; ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select><br><br>
|
||||
|
||||
<label for="artist">Artiste :</label>
|
||||
<select name="artist" id="artist">
|
||||
<option value="">Tous les artistes</option>
|
||||
<?php foreach ($artists as $artist): ?>
|
||||
<option value="<?php echo $artist; ?>"><?php echo $artist; ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select><br><br>
|
||||
|
||||
<input type="submit" value="Générer la playlist">
|
||||
</form>
|
||||
</body>
|
40
CodeIgniter-3.1.13/assets/css/generate_playlist.css
Normal file
40
CodeIgniter-3.1.13/assets/css/generate_playlist.css
Normal file
@ -0,0 +1,40 @@
|
||||
.formulaire {
|
||||
background-color: #fff;
|
||||
border-radius: 5px;
|
||||
padding: 20px;
|
||||
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
|
||||
max-width: 500px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
h1 {
|
||||
color: #333;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
label {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
input[type="number"],
|
||||
select {
|
||||
width: calc(100% - 10px);
|
||||
padding: 8px;
|
||||
margin-bottom: 15px;
|
||||
border: 1px solid #ccc;
|
||||
border-radius: 5px;
|
||||
}
|
||||
|
||||
input[type="submit"] {
|
||||
background-color: #5a0993;
|
||||
color: white;
|
||||
padding: 10px 20px;
|
||||
border: none;
|
||||
border-radius: 5px;
|
||||
cursor: pointer;
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
input[type="submit"]:hover {
|
||||
background-color: #2d0648;
|
||||
}
|
@ -1,4 +1,3 @@
|
||||
/* Styles généraux */
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
margin: 0;
|
||||
|
Loading…
Reference in New Issue
Block a user