Esempio n. 1
0
 /**
  * Выбрать альбом для прослушивания
  */
 public function actionRandAlbom($unusual = 0)
 {
     if ($unusual) {
         $played = implode(',', ArrayHelper::map(Played::find()->all(), 'id', 'source_id'));
         $alboms = Source::find()->where("id NOT IN (" . $played . ")")->andWhere(['status' => 3])->all();
         if ($alboms) {
             $rand = rand(0, count($alboms));
             $new_played = new Played();
             $new_played->source_id = $alboms[$rand]->id;
             $new_played->save(false);
             echo "Ставь " . $alboms[$rand]->title . " -- " . $alboms[$rand]->author->name . PHP_EOL;
         } else {
             echo "Ничего нет" . PHP_EOL;
         }
     } else {
         $played = implode(',', ArrayHelper::map(Played::find()->all(), 'id', 'source_id'));
         $alboms = Source::find()->where("id NOT IN (" . $played . ")")->andWhere(['status' => 1])->all();
         if ($alboms) {
             $rand = rand(0, count($alboms));
             $data = readline("Устроит " . $alboms[$rand]->title . " -- " . $alboms[$rand]->author->name . " ? Y или N ? ");
             if ($data == 'N') {
                 $this->actionRandAlbom();
             } else {
                 $new_played = new Played();
                 $new_played->source_id = $alboms[$rand]->id;
                 $new_played->save(false);
                 echo "Ставь " . $alboms[$rand]->title . " -- " . $alboms[$rand]->author->name . PHP_EOL;
             }
         } else {
             echo "Ничего нет" . PHP_EOL;
         }
     }
 }
Esempio n. 2
0
 /**
  * Показывает контент
  * @return string
  * @TODO Нужно предусмотреть возможность вывода разного контента, привязаного к одной категории
  *
  */
 public function actionShow()
 {
     $this->cat_id = Yii::$app->getRequest()->getQueryParam('id') ? Yii::$app->getRequest()->getQueryParam('id') : null;
     $cat_obg = Categories::find()->where('id = ' . $this->cat_id)->one();
     $allContent = Articles::find()->where('cat_id = ' . $this->cat_id)->all();
     $allArticlesForPager = Articles::find()->where(['cat_id' => $this->cat_id]);
     $countQueryCont = clone $allArticlesForPager;
     $pagesGlobal = new Pagination(['totalCount' => $countQueryCont->count(), 'pageSize' => 1, 'forcePageParam' => false, 'pageSizeParam' => false]);
     $artPages = $allArticlesForPager->offset($pagesGlobal->offset)->limit($pagesGlobal->limit)->all();
     foreach ($allContent as $article) {
         //var_dump($this->cat_id);
         $this->article_id = $article->id;
         $article = Articles::findOne($this->article_id);
         $allArticles = ArticlesContent::find()->where(['articles_id' => $this->article_id])->orderBy(['id' => SORT_DESC]);
         //var_dump($allArticles); exit;
         $countQuery = clone $allArticles;
         $pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => isset($article->onepages) ? $article->onepages : 0, 'forcePageParam' => false, 'pageSizeParam' => false]);
         $models = $allArticles->offset($pages->offset)->limit($pages->limit)->all();
         $this->source = Source::find()->where(['id' => $models[0]->source_id])->one()->title;
         $this->author = Author::find()->where(['id' => Source::find()->where(['id' => $models[0]->source_id])->one()->author_id])->one()->name;
         $this->articles[] = ['article' => $article, 'contents' => $models, 'pages' => $pages, 'source' => $this->source, 'author' => $this->author];
     }
     //var_dump($this->articles); exit;
     return $this->renderPartial($cat_obg->action, ['articles' => $this->articles, 'cat' => $this->cat_id, 'pagesGlobal' => $pagesGlobal, 'artPages' => $artPages, 'cat_obg' => $cat_obg]);
 }
Esempio n. 3
0
 public function actionAllAjax()
 {
     if (Yii::$app->request->isAjax) {
         echo Json::encode(Source::find()->asArray()->all());
     } else {
         echo "0";
     }
 }
Esempio n. 4
0
 public function search($params)
 {
     $query = Source::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     $query->andFilterWhere(['like', 'title', $this->title]);
     return $dataProvider;
 }
Esempio n. 5
0
 public function search($params)
 {
     $query = Source::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'url', $this->url]);
     return $dataProvider;
 }
Esempio n. 6
0
 public static function getSoureListByNear(Town $town)
 {
     $rawSources = Source::find()->all();
     $sources = [];
     foreach ($rawSources as $source) {
         $source->distance = $source->totalDistance($town);
         $sources[] = $source;
     }
     ArrayHelper::multisort($sources, function ($source) {
         return $source->distance;
     });
     return $sources;
 }
Esempio n. 7
0
 /**
  * Показываем контент
  * @param $id
  * @return string
  */
 public function actionShow($id)
 {
     $article = Articles::findOne($id);
     $comment = new Comments();
     $this->title = $article->title;
     $allArticles = ArticlesContent::find()->where(['articles_id' => $id]);
     //var_dump($allArticles); exit;
     $countQuery = clone $allArticles;
     $pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => isset($article->onepages) ? $article->onepages : 0, 'forcePageParam' => false, 'pageSizeParam' => false]);
     $models = $allArticles->offset($pages->offset)->limit($pages->limit)->all();
     $this->source = Source::find()->where(['id' => $models[0]->source_id])->one()->title;
     $this->author = Author::find()->where(['id' => Source::find()->where(['id' => $models[0]->source_id])->one()->author_id])->one()->name;
     return $this->render('view', ['articles' => $allArticles, 'contents' => $models, 'pages' => $pages, 'title' => $this->title, 'source' => $this->source, 'author' => $this->author, 'comment' => $comment]);
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Source::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'latitude' => $this->latitude, 'longitude' => $this->longitude, 'temperature' => $this->temperature]);
     $query->andFilterWhere(['like', 'name', $this->name]);
     return $dataProvider;
 }
Esempio n. 9
0
 public function actionUpdate($id)
 {
     $model = $this->loadModel($id);
     if ($model->load(Yii::$app->request->post())) {
         $model->title = Yii::$app->request->post('SongText')['title'];
         $model->text = Yii::$app->request->post('SongText')['text'];
         $model->link = Yii::$app->request->post('SongText')['link'];
         if (Source::find()->where(['title' => Yii::$app->request->post('SongText')['source_title']])->one()) {
             $model->source_id = Source::find()->where(['title' => Yii::$app->request->post('SongText')['source_title']])->one()->id;
         } else {
             $model->source_id = 2;
         }
         $model->save(false);
         $texts = SongText::find();
         $dataProvider = new ActiveDataProvider(['query' => $texts]);
         return $this->redirect(Url::toRoute('songtext/index'));
     } else {
         return $this->render('_form', ['model' => $model]);
     }
 }
Esempio n. 10
0
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="site-login">
    <h1 class="text-center"><?php 
echo Html::encode($this->title);
?>
</h1>

    <div class="row">
        <div class="col-sm-3 col-md-2 sidebar">
            <?php 
echo Nav::widget(['options' => ['class' => 'nav nav-sidebar'], 'items' => [['label' => 'Добавить страницу', 'url' => ['/articles/addpage/' . $model->id]]]]);
?>
            <?php 
//фомируем список автокомплита
$data = \app\models\Source::find()->select(['title as label'])->asArray()->all();
//var_dump($data); exit;
?>

        </div>
        <div class="col-lg-10">
            <?php 
$form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']]);
?>

            <?php 
echo $form->field($model, 'minititle')->textInput();
?>

            <?php 
echo $form->field($upload, 'file')->fileInput();
Esempio n. 11
0
 /**
  * Обновляет страницу
  * @param $id
  * @return string
  * @throws \yii\web\HttpException
  */
 public function actionUpdatepage($id)
 {
     $artContent = $this->loadModelcontent($id);
     $artId = $artContent->articles_id;
     $redactor = $this->loadModel($artId)->redactor;
     $upload = new UploadForm();
     //var_dump($upload); exit;
     if (Yii::$app->request->isPost) {
         $upload->file = UploadedFile::getInstance($upload, 'file');
         if ($upload->file && $upload->validate()) {
             $upload->file->saveAs('uploads/' . Yii::$app->translater->translit($upload->file->baseName) . '.' . $upload->file->extension);
         } else {
             print_r($upload->getErrors());
         }
     }
     if ($artContent->load(Yii::$app->request->post())) {
         $artContent->body = Yii::$app->request->post('ArticlesContent')['body'];
         $artContent->minititle = Yii::$app->request->post('ArticlesContent')['minititle'];
         //$artContent->source_id = Yii::$app->request->post('ArticlesContent')['source_id'];
         if (Source::find()->where(['title' => Yii::$app->request->post('ArticlesContent')['source_title']])->one()) {
             $artContent->source_id = Source::find()->where(['title' => Yii::$app->request->post('ArticlesContent')['source_title']])->one()->id;
         } else {
             return 'mistake';
         }
         $artContent->articles_id = $artId;
         if (isset($upload->file)) {
             $artContent->audio = Url::base() . 'uploads/' . Yii::$app->translater->translit($upload->file->baseName) . '.' . $upload->file->extension;
         }
         $artContent->save();
         $content = ArticlesContent::find()->where(['articles_id' => $artId]);
         $dataCont = new ActiveDataProvider(['query' => $content]);
         return $this->render('pages', ['content' => $dataCont, 'model' => $artContent]);
     } else {
         return $this->render('page_form', ['model' => $artContent, 'upload' => $upload, 'redactor' => $redactor]);
     }
 }
Esempio n. 12
0
 public static function getSourceList()
 {
     $sources = Source::find()->asArray()->all();
     return Arrayhelper::map($sources, 'id', 'name');
 }
Esempio n. 13
0
 /**
  * Закладки
  * @return string
  * @throws \Exception
  */
 public function actionMarkers()
 {
     $current_hour = date('G', time() + 7 * 60 * 60);
     //return $current_hour;
     switch ($current_hour) {
         case 6:
             $cat = 136;
             break;
         case 7:
             $cat = 113;
             break;
         case 8:
             $cat = 116;
             break;
         case 9:
             $cat = 116;
             break;
         case 10:
             $cat = 116;
             break;
         case 11:
             $cat = 116;
             break;
         case 12:
             $cat = 116;
             break;
         case 13:
             $cat = 116;
             break;
         case 14:
             $cat = 116;
             break;
         case 15:
             $cat = 116;
             break;
         case 18:
             $cat = 114;
             break;
         case 19:
             $cat = 114;
             break;
         default:
             $cat = 53;
     }
     // return $cat;
     if (Yii::$app->getRequest()->getQueryParam('user')) {
         $user = MarkUser::findOne(Yii::$app->getRequest()->getQueryParam('user'));
         if (!$user) {
             return 'Доступ запрещен!';
         }
         if (Yii::$app->getRequest()->getQueryParam('id') && Yii::$app->getRequest()->getQueryParam('mark')) {
             //return var_dump((int)Yii::$app->getRequest()->getQueryParam('id'));
             $update_source = Source::findOne((int) Yii::$app->getRequest()->getQueryParam('id'));
             $update_source->marker = Yii::$app->getRequest()->getQueryParam('mark');
             $update_source->is_next = 0;
             $update_source->update(false);
             //return var_dump($update_source);
             $next_source = Source::find()->where("id > {$update_source->id} and cat_id = {$cat} ")->one();
             if (!$next_source) {
                 $next_source = Source::find()->where("cat_id = {$cat}")->one();
                 if (!$next_source) {
                     return "Категория!";
                 }
             }
             $next_source->is_next = 1;
             //return var_dump($next_source);
             $next_source->update(false);
             return $this->renderPartial('source', ['source' => $next_source, 'user' => $user]);
         }
         $source = Source::find()->where("cat_id = {$cat} and is_next = 1")->one();
         return $this->renderPartial('source', ['source' => $source, 'user' => $user]);
     }
     return 'нет!';
 }
Esempio n. 14
0
 public function actionGrab()
 {
     //        Yii::$app->response->format = Response::FORMAT_JSON;
     $success = true;
     $source = Source::find()->joinWith('logs')->where(['enable' => true])->orderBy(['updated' => SORT_ASC])->one();
     if ($source) {
         $grabber = new Grabber($source);
         $newPosts = $grabber->execute();
         if (!empty($newPosts)) {
             foreach ($newPosts as $post) {
                 $hashPost = md5($post);
                 // есть ли в базе Post или Moderation
                 $doubling = Post::findOne(['hash' => $hashPost]) || Moderation::findOne(['hash' => $hashPost]);
                 if ($doubling) {
                     continue;
                 }
                 // добавляем новый пост на модерацию
                 $model = new Moderation();
                 $model->text = $post;
                 $model->hash = $hashPost;
                 $model->ip = "127.0.0.1";
                 //Yii::$app->request->getUserIP();
                 $model->user_agent = "Auto Grabber";
                 //Yii::$app->request->getUserAgent();
                 $success = $model->save() && $success;
             }
         }
         $source->updateLog();
     }
     return $success;
 }
Esempio n. 15
0
        <div class="col-lg-10">
            <?php 
$form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']]);
?>

            <?php 
echo $form->field($model, 'title')->textInput();
?>
            <?php 
echo $form->field($model, 'site_id')->dropDownList(ArrayHelper::map(\app\models\Qpsites::find()->all(), 'id', 'title'), ['prompt' => 'Выбрать сайт']);
?>
             <?php 
echo $form->field($model, 'cat_id')->dropDownList(ArrayHelper::map(\app\models\Categories::find()->all(), 'id', 'name'), ['prompt' => 'Выбрать категорию']);
?>
            <?php 
echo $form->field($model, 'source_id')->dropDownList(ArrayHelper::map(\app\models\Source::find()->all(), 'id', 'title'), ['prompt' => 'Выбрать источник']);
?>
            <?php 
echo $form->field($model, 'redactor')->checkbox();
?>
            <?php 
echo $form->field($model, 'text')->textarea(['rows' => 5, 'cols' => 5, 'id' => 'my-textarea-id']);
?>
            <?php 
echo $form->field($model, 'tags')->textInput();
?>
            <?php 
echo $form->field($uploadFile, 'file')->fileInput();
?>
            <?php 
echo $form->field($uploadImg, 'img')->fileInput();
Esempio n. 16
0
 public function actionUpdate($id)
 {
     $model = $this->loadModel($id);
     $uploadFile = new UploadForm();
     $uploadImg = new UploadForm();
     if (Yii::$app->request->isPost) {
         $uploadFile->file = UploadedFile::getInstance($uploadFile, 'file');
         $uploadImg->img = UploadedFile::getInstance($uploadImg, 'img');
         if ($uploadFile->file && $uploadFile->validate()) {
             $uploadFile->file->saveAs('uploads/' . Yii::$app->translater->translit($uploadFile->file->baseName) . '.' . $uploadFile->file->extension);
         } elseif ($uploadImg->img && $uploadImg->validate()) {
             $uploadImg->img->saveAs('uploads/' . Yii::$app->translater->translit($uploadImg->img->baseName) . '.' . $uploadImg->img->extension);
         } else {
             print_r($uploadFile->getErrors());
         }
     }
     if ($model->load(Yii::$app->request->post())) {
         $model->text = Yii::$app->request->post('Items')['text'];
         $model->tags = Yii::$app->request->post('Items')['tags'];
         $model->title = Yii::$app->request->post('Items')['title'];
         $model->cens = Yii::$app->request->post('Items')['cens'];
         //$model->cat_id = Yii::$app->request->post('Items')['cat_id'];
         if (Categories::find()->where(['title' => Yii::$app->request->post('Items')['cat_title']])->one()) {
             $model->cat_id = Categories::find()->where(['title' => Yii::$app->request->post('Items')['cat_title']])->one()->id;
         }
         $model->audio_link = Yii::$app->request->post('Items')['audio_link'];
         $model->in_work_prim = Yii::$app->request->post('Items')['in_work_prim'];
         //$model->play_status = 1;
         Tag::addTags($model->tags, $id);
         //if(isset(Yii::$app->request->post('Items')['source_id']))$model->source_id = Yii::$app->request->post('Items')['source_id'];
         //else $model->source_id = 2;
         if (Source::find()->where(['title' => Yii::$app->request->post('Items')['source_title']])->one()) {
             $model->source_id = Source::find()->where(['title' => Yii::$app->request->post('Items')['source_title']])->one()->id;
         } else {
             $model->source_id = 2;
         }
         if (isset($uploadFile->file)) {
             $model->audio = Url::base() . 'uploads/' . Yii::$app->translater->translit($uploadFile->file->baseName) . '.' . $uploadFile->file->extension;
         }
         if (isset($uploadImg->img)) {
             $model->img = Url::base() . 'uploads/' . Yii::$app->translater->translit($uploadImg->img->baseName) . '.' . $uploadImg->img->extension;
         }
         $model->save(false);
         return $this->redirect(Url::toRoute('item/index'));
     } else {
         return $this->render('_form', ['model' => $model, 'uploadFile' => $uploadFile, 'uploadImg' => $uploadImg]);
     }
 }
Esempio n. 17
0
 public function actionDelete($id)
 {
     if ($model = $this->loadModel($id)->delete()) {
         $source = Source::find();
         $dataProvider = new ActiveDataProvider(['query' => $source]);
         return $this->render('index', ['sources' => $dataProvider]);
     } else {
         throw new \yii\web\HttpException(404, 'Cant delete record.');
     }
 }
Esempio n. 18
0
 /**
  * Парсинг ссылок на песни в таблицу текстов
  */
 function actionGetMusicLinks()
 {
     $dir = '/home/romanych/Музыка/Thoughts_and_klassik/best_alboms';
     $authors = scandir($dir);
     //return var_dump($list);
     if (is_array($authors)) {
         $authors = array_diff($authors, array('.', '..'));
         if ($authors) {
             foreach ($authors as $author) {
                 $path = $dir . '/' . $author;
                 if (is_dir($path)) {
                     $alboms = scandir($path);
                 }
                 if (is_array($alboms)) {
                     $alboms = array_diff($alboms, array('.', '..'));
                     if ($alboms) {
                         foreach ($alboms as $albom) {
                             $path = $dir . '/' . $author . '/' . $albom;
                             if ($source = Source::find()->where("title like '%" . addslashes($albom) . "%'")->one()) {
                                 echo $source->title;
                                 //exit;
                             } else {
                                 continue;
                             }
                             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 = $path . '/' . $song . '/' . $sub_song;
                                         }
                                     } else {
                                         if (preg_match('/(.+).mp3$/', $song, $match)) {
                                             $song_obj->title = $song;
                                             $song_obj->link = $path . '/' . $song;
                                         }
                                     }
                                     $song_obj->save(false);
                                 }
                             } else {
                                 echo $path . '-----no---dir--------------';
                             }
                         }
                     }
                 }
             }
         }
     } else {
         echo 'cant';
     }
 }