Ajout de génération par genre
This commit is contained in:
parent
0bdee7aeed
commit
4f77b89eeb
codeigniter/application
@ -67,7 +67,7 @@ class Playlist extends CI_Controller {
|
||||
echo "Playlist non trouvée.";
|
||||
}
|
||||
}else{
|
||||
redirect('albums');
|
||||
redirect('playlist');
|
||||
}
|
||||
|
||||
|
||||
@ -136,20 +136,20 @@ public function choix_playlist($albumId) {
|
||||
redirect('playlist/view/' . $playlistId);
|
||||
}
|
||||
|
||||
public function generate(){
|
||||
|
||||
$this->load->view('layout/header');
|
||||
$this->load->view('playlist_generate');
|
||||
$this->load->view('layout/footer');
|
||||
}
|
||||
|
||||
|
||||
public function generate_random(){
|
||||
$genres = $this->model_music->getGenres();
|
||||
$this->load->view('layout/header');
|
||||
$this->load->view('playlist_generate', ['genres' => $genres]);
|
||||
$this->load->view('layout/footer');
|
||||
|
||||
$genre = $this->input->post('genre');
|
||||
$numSongs = (int)$this->input->post('numSongs');
|
||||
$playlistName = $this->input->post('playlistName');
|
||||
$userId = $this->session->userdata('user_id');
|
||||
|
||||
if ($numSongs > 0 && !empty($playlistName)) {
|
||||
$playlistId = $this->model_music->generate_random_playlist($numSongs, $playlistName, $userId);
|
||||
$playlistId = $this->model_music->generate_random_playlist($numSongs, $playlistName, $userId, $genre);
|
||||
redirect('playlist/view/' . $playlistId);
|
||||
} else {
|
||||
echo "Erreur : Veuillez entrer un nombre de chansons valide et un nom de playlist.";
|
||||
|
@ -197,10 +197,21 @@ class Model_music extends CI_Model {
|
||||
return $query->row();
|
||||
}
|
||||
|
||||
public function generate_random_playlist($numSongs, $playlistName, $userId) {
|
||||
$query = $this->db->query(
|
||||
"SELECT id FROM song ORDER BY RAND() LIMIT ?", array((int)$numSongs)
|
||||
);
|
||||
public function generate_random_playlist($numSongs, $playlistName, $userId, $genre = '') {
|
||||
$this->db->select('song.id');
|
||||
$this->db->from('song');
|
||||
$this->db->join('track', 'track.songId = song.id');
|
||||
$this->db->join('album', 'track.albumId = album.id');
|
||||
$this->db->join('genre', 'album.genreId = genre.id');
|
||||
if (!empty($genre)) {
|
||||
$this->db->where('genre.name', $genre);
|
||||
}
|
||||
$this->db->order_by('RAND()');
|
||||
$this->db->limit($numSongs);
|
||||
|
||||
$query = $this->db->get();
|
||||
|
||||
|
||||
$songs = $query->result();
|
||||
|
||||
$playlistId = $this->createPlaylist($playlistName, $userId);
|
||||
@ -208,10 +219,12 @@ class Model_music extends CI_Model {
|
||||
foreach ($songs as $song) {
|
||||
$this->addSongToPlaylist($playlistId, $song->id);
|
||||
}
|
||||
|
||||
return $playlistId;
|
||||
redirect('playlist/view/'.$playlistId);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
@ -3,7 +3,14 @@
|
||||
<form action="<?= site_url('playlist/generate_random'); ?>" method="post" class="generate-playlist-form">
|
||||
<input type="text" name="playlistName" placeholder="Nom de la playlist" required>
|
||||
<input type="number" min="0" max="1000" name="numSongs" placeholder="Nombre de chansons" required>
|
||||
<button type="submit">Générer</button>
|
||||
|
||||
<select name="genre" >
|
||||
<option value="">Tous les genres</option>
|
||||
<?php foreach($genres as $genre): ?>
|
||||
<option value="<?= $genre->name ?>"><?= $genre->name ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
<button type="submit">Générer</button>
|
||||
</form>
|
||||
|
||||
<a href="<?= site_url('playlist'); ?>" class="btn btn-secondary">Retour aux playlists</a>
|
||||
|
@ -6,11 +6,10 @@
|
||||
<button type="submit">Créer</button>
|
||||
</form>
|
||||
|
||||
<form action="<?= site_url('playlist/generate'); ?>" method="get" class="generate-playlist-form">
|
||||
<form action="<?= site_url('playlist/generate_random'); ?>" method="get" class="generate-playlist-form">
|
||||
<button type="submit">Générer une Playlist</button>
|
||||
</form>
|
||||
|
||||
<!-- Affichez les playlist que nous avons -->
|
||||
<section class="playlists">
|
||||
<?php foreach($playlists as $playlist): ?>
|
||||
<div>
|
||||
@ -18,7 +17,6 @@
|
||||
<header class="short-text">
|
||||
<?= anchor("playlist/view/{$playlist->id}", "{$playlist->name}"); ?>
|
||||
</header>
|
||||
<!-- Bouton pour supprimer la playlist -->
|
||||
<form action="<?= site_url('playlist/delete/' . $playlist->id); ?>" method="post" class="btn-supp" style="display:inline;">
|
||||
<button type="submit">Supprimer</button>
|
||||
</form>
|
||||
|
Loading…
x
Reference in New Issue
Block a user