vaujdui v2

This commit is contained in:
2024-06-19 15:47:11 +02:00
parent 6bfbf46dcc
commit 46e7b0d369
10 changed files with 158 additions and 94 deletions

View File

@@ -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');
}