Ajout de génération par genre
This commit is contained in:
@@ -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);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
Reference in New Issue
Block a user