vaujdui v2
This commit is contained in:
@@ -109,7 +109,7 @@ class Model_playlist extends CI_Model {
|
||||
$this->db->insert('playlists', $data);
|
||||
$playlistId = $this->db->insert_id();
|
||||
|
||||
// Filtrage des chansons par genre
|
||||
// Filtrage des chansons par genre et sélection aléatoire
|
||||
$this->db->select('track.id');
|
||||
$this->db->from('track');
|
||||
$this->db->join('song', 'track.songid = song.id');
|
||||
@@ -120,17 +120,13 @@ class Model_playlist extends CI_Model {
|
||||
$this->db->where('genre.name', $genre);
|
||||
}
|
||||
|
||||
$this->db->order_by('RAND()');
|
||||
$this->db->limit($numSongs);
|
||||
|
||||
$query = $this->db->get();
|
||||
$songs = $query->result();
|
||||
|
||||
if ($numSongs > count($songs)) {
|
||||
$numSongs = count($songs);
|
||||
}
|
||||
|
||||
// Sélection aléatoire de chansons
|
||||
$randomKeys = array_rand($songs, $numSongs);
|
||||
foreach ($randomKeys as $key) {
|
||||
$song = $songs[$key];
|
||||
foreach ($songs as $song) {
|
||||
$this->addItem($playlistId, $song->id, 'song');
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user