Example #1
0
 public function for_song()
 {
     $error = array();
     $song_clem = DB::connection('clem')->query('SELECT title, album, artist, albumartist, year, genre, filename,track FROM songs');
     foreach ($song_clem as $value) {
         /* AJOUT D'ARTISTES */
         if (trim($value->artist) != '') {
             $band = new Band(null, 1, utf8_encode($value->artist), null, null);
             try {
                 $band->add();
             } catch (Exception $e) {
                 $this->_error_msg .= 'artiste :' . $e->getMessage() . '<br>';
                 break;
             }
         }
         /* AJOUT D'ALBUM */
         if (trim($value->album) != '') {
             $name_band = Band::from_name_band(utf8_encode($value->artist));
             $album = new Album(null, $name_band[0]->id_band, 1, utf8_encode($value->album), $value->year);
             try {
                 $album->add();
             } catch (Exception $e) {
                 $this->_error_msg .= 'album: ' . $e->getMessage() . '<br>';
                 break;
             }
         }
         if (trim($value->title) != '') {
             $album = Album::from_name_album(utf8_encode($value->album));
             $song = new song(null, 1, utf8_encode($value->title), $value->year, null, $value->filename, $value->track);
             $song->set_id_kind(explode(';', $value->genre));
             $song->id_album = $album[0]->id_album;
             try {
                 $song->add();
             } catch (Exception $e) {
                 $this->_error_msg .= 'chanson: ' . $e->getMessage() . '<br>';
                 break;
             }
         }
     }
     // var_dump($song_clem);
 }