creation aléatoire de playlist
This commit is contained in:
@@ -469,14 +469,17 @@ class Model_music extends CI_Model {
|
||||
}
|
||||
}
|
||||
|
||||
public function DuplicatePlaylist($idplaylist,$nomplaylist){
|
||||
public function IdPLaylistByName($nomPLaylist){
|
||||
$this->db->select('Playlist.playlistId');
|
||||
$this->db->from('Playlist');
|
||||
$this->db->where('name', $nomplaylist);
|
||||
$this->db->where('name', $nomPLaylist);
|
||||
$query = $this->db->get();
|
||||
$result = $query->row();
|
||||
$id = $result->playlistId;
|
||||
print_r($id);
|
||||
return $result->playlistId;
|
||||
}
|
||||
|
||||
public function DuplicatePlaylist($idplaylist,$nomplaylist){
|
||||
$id = $this->model_music->IdPLaylistByName($nomplaylist);
|
||||
|
||||
$this->db->select('PlaylistSong.trackId');
|
||||
$this->db->from('PlaylistSong');
|
||||
@@ -495,4 +498,29 @@ class Model_music extends CI_Model {
|
||||
$this->db->where('playlistId',$idplaylist);
|
||||
$this->db->delete("Playlist");
|
||||
}
|
||||
|
||||
public function get_random_tracks($genres = [], $artists = [], $years = [], $num_tracks = 10) {
|
||||
$this->db->select('track.id as trackId');
|
||||
$this->db->from('track');
|
||||
$this->db->join('album', 'album.id = track.albumId');
|
||||
$this->db->join('artist', 'album.artistId = artist.Id');
|
||||
$this->db->join('genre', 'genre.id = album.genreid');
|
||||
|
||||
if (!empty($genres)) {
|
||||
$this->db->where_in('genre.name', $genres);
|
||||
}
|
||||
|
||||
if (!empty($artists)) {
|
||||
$this->db->where_in('artist.name', $artists);
|
||||
}
|
||||
|
||||
if (!empty($years)) {
|
||||
$this->db->where_in('year', $years);
|
||||
}
|
||||
|
||||
$this->db->order_by('RAND()');
|
||||
$this->db->limit($num_tracks);
|
||||
$query = $this->db->get();
|
||||
return $query->result();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user