creation aléatoire de playlist
This commit is contained in:
@@ -74,4 +74,39 @@ class Playlist extends CI_Controller {
|
||||
$this->model_music->DeletePlaylist($id);
|
||||
redirect('playlist');
|
||||
}
|
||||
|
||||
public function create_random_playlist() {
|
||||
$this->form_validation->set_rules('num_tracks', 'num_tracks', 'required');
|
||||
$this->form_validation->set_rules('name', 'name', 'required');
|
||||
|
||||
$data['genres'] = $this->model_music->get_all_genres();
|
||||
$data['artists'] = $this->model_music->get_all_artists();
|
||||
$data['years'] = $this->model_music->get_all_years();
|
||||
|
||||
if ($this->form_validation->run() == FALSE){
|
||||
$this->load->view('layout/header');
|
||||
$this->load->view('random_Playlist',$data);
|
||||
$this->load->view('layout/footer');
|
||||
}else{
|
||||
$genres = $this->input->post('genre');
|
||||
$artists = $this->input->post('artist');
|
||||
$years = $this->input->post('year');
|
||||
$nom = $this->input->post('name');
|
||||
$description = $this->input->post('Description');
|
||||
$userId = $this->session->userdata('userId');
|
||||
$num_tracks = (int) $this->input->post('num_tracks');
|
||||
$playlist = array(
|
||||
'name'=>$nom,
|
||||
'description'=>$description,
|
||||
'userId'=>$userId,
|
||||
);
|
||||
$this->model_music->addPlayliste($playlist);
|
||||
$idplaylist = $this->model_music->IdPLaylistByName($nom);
|
||||
$tracks = $this->model_music->get_random_tracks($genres, $artists, $years, $num_tracks);
|
||||
foreach ($tracks as $musique){
|
||||
$this->model_music->AddSongtoPlaylist($idplaylist, $musique->trackId);
|
||||
}
|
||||
redirect('playlist');
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user