Esempio n. 1
0
 public function search($params)
 {
     $query = SongText::find()->where(['text' => '']);
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     $query->andFilterWhere(['like', 'title', $this->title]);
     return $dataProvider;
 }
Esempio n. 2
0
 public function loadModel($id)
 {
     $model = SongText::findOne($id);
     if ($model === null) {
         throw new \yii\web\HttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
Esempio n. 3
0
 /**
  * Для выбора и прослушивания музыки
  * @return string
  */
 function actionMusic()
 {
     if ($user = Yii::$app->getRequest()->getQueryParam('user')) {
         if (!$user) {
             return 'Доступ запрещен!';
         }
         if (Yii::$app->getRequest()->getQueryParam('theme_song')) {
             $theme = Yii::$app->getRequest()->getQueryParam('theme_song');
             $arr_theme = explode(',', Yii::$app->getRequest()->getQueryParam('theme_song'));
             if (!empty($arr_theme)) {
                 $this->songs = [];
             }
             foreach ($arr_theme as $theme) {
                 $query = new Query();
                 $songs_ids = $query->from('songtexts')->match($theme)->all();
                 foreach ($songs_ids as $arr_item_rec) {
                     foreach ($arr_item_rec as $id) {
                         $this->songs[] = SongText::findOne((int) $id);
                     }
                 }
             }
             //return var_dump($arr);
             return $this->renderPartial('songs', ['songs' => $this->songs]);
             //else  return $this->renderPartial('songs', ['song' => SongText::findOne(2)]);
         }
         $songs = [];
         $query = new Query();
         $songs_ids = $query->from('songtexts')->match('new year')->all();
         foreach ($songs_ids as $arr_item_rec) {
             foreach ($arr_item_rec as $id) {
                 $songs[] = SongText::findOne((int) $id);
             }
         }
         return $this->renderPartial('songs', ['songs' => $songs]);
     }
 }
Esempio n. 4
0
 public function actionNoradio()
 {
     $comment = new RadioComment();
     $texts = SongText::find()->limit(10)->all();
     return $this->render('noradio', ['comment' => $comment, 'texts' => $texts]);
 }
Esempio n. 5
0
 function actionGetMusicLinksAlbom($new_artist)
 {
     $dir = '/home/romanych/Музыка/Thoughts_and_klassik/best_alboms/' . $new_artist;
     //return var_dump($dir);
     try {
         $alboms = scandir($dir);
     } catch (\ErrorException $e) {
         return $e->getMessage();
     }
     if (is_array($alboms)) {
         $alboms = array_diff($alboms, array('.', '..'));
         if ($alboms) {
             foreach ($alboms as $albom) {
                 // return var_dump($albom);
                 $source = new Source();
                 $source->title = $albom;
                 if (Author::find()->where('name like "%' . addslashes($new_artist) . '%"')->one()) {
                     $source->author_id = Author::find()->where("name like '%" . addslashes($new_artist) . "%'")->one()->id;
                 } else {
                     return 'author error';
                 }
                 $source->status = 1;
                 $source->cat_id = 34;
                 if (!$source->save(false)) {
                     return 'source error';
                 } else {
                     echo $source->title . ' made' . PHP_EOL;
                 }
                 $path = $dir . '/' . $albom;
                 if (is_dir($path)) {
                     $songs = scandir($path);
                     $songs = array_diff($songs, array('.', '..'));
                     foreach ($songs as $song) {
                         $song_obj = new SongText();
                         try {
                             $song_obj->source_id = $source->id;
                         } catch (\ErrorException $e) {
                             echo $e->getMessage();
                             continue;
                         }
                         $song_path = $path . '/' . $song;
                         if (is_dir($song_path)) {
                             $sub_songs = scandir($song_path);
                             $sub_songs = array_diff($sub_songs, array('.', '..'));
                             foreach ($sub_songs as $sub_song) {
                                 if (preg_match('/(.+).mp3$/', $sub_song, $match)) {
                                     $song_obj->title = $sub_song;
                                 }
                                 $song_obj->link = substr($path . '/' . $song . '/' . $sub_song, 48);
                             }
                         } else {
                             if (preg_match('/(.+).mp3$/', $song, $match)) {
                                 $song_obj->title = $song;
                                 $song_obj->link = substr($path . '/' . $song, 48);
                             }
                         }
                         $song_obj->save(false);
                     }
                 } else {
                     echo $path . '-----no---dir--------------';
                 }
             }
         }
     }
 }