Ejemplo n.º 1
0
 /**
  * Execute the job.
  *
  * @return void
  */
 public function handle(SourceRepository $sourceRepo)
 {
     $this->source->sync_status = "processing";
     $this->source->save();
     $id = $this->source->id;
     $rawFilePath = 'sources/' . $id . '/o/file.raw';
     $procFilePath = 'sources/' . $id . '/p/file.processed';
     // File exists in storage/app/sources/XX/o/file.raw ?
     if (!Storage::exists($rawFilePath)) {
         // update sync_status
         $this->source->sync_status = "error";
         $sourceRepo->addRecord($this->source, "Raw file in {$rawFilePath} does not exists!", "error");
     } elseif (Storage::mimeType($rawFilePath) != 'text/plain' && Storage::mimeType($rawFilePath) != 'application/octet-stream') {
         // update sync_status
         $this->source->sync_status = "error";
         $fileMimeType = Storage::mimeType($rawFilePath);
         $sourceRepo->addRecord($this->source, "Mime type {$fileMimeType} of file in {$rawFilePath} not supported!", "error");
     } else {
         $result = $sourceRepo->convertToGeoJSON($this->source, $rawFilePath, $procFilePath);
         if ($result == true) {
             $this->source->sync_status = "processed";
             // Queue the source to be published
             $this->dispatch(new PublishSource($this->source));
         } else {
             $this->source->sync_status = "error";
         }
     }
     $this->source->save();
     $sourceRepo->addRecord($this->source, "Source processed successfully!", "success");
 }
Ejemplo n.º 2
0
 /**
  * Execute the job.
  *
  * @return void
  */
 public function handle(SourceRepository $sourceRepo)
 {
     $this->source->sync_status = "downloading";
     $this->source->save();
     $id = $this->source->id;
     $name = $this->source->name;
     $url = $this->source->origin_url;
     $sourceRepo->addRecord($this->source, "Starting download");
     $response = $sourceRepo->copyRemoteFile($url, storage_path('app/sources/' . $id . '/o/file.raw'));
     if (!$response) {
         // update sync_status
         $this->source->sync_status = "error";
         $sourceRepo->addRecord($this->source, "No response received from server origin", "error");
     } elseif ($response->getStatusCode() == 200) {
         // update origin_format
         $this->source->origin_format = $sourceRepo->guessResponseType($response, $url);
         // update origin_size
         $this->source->origin_size = $sourceRepo->guessResponseLength($response);
         // update synced_at
         $this->source->synced_at = Carbon::now()->toDateTimeString();
         // update sync_status
         $this->source->sync_status = "downloaded";
         $this->source->save();
         // Queue the source to be converted
         $this->dispatch(new ConvertSource($this->source));
         $sourceRepo->addRecord($this->source, "Download success!", "success");
     } else {
         // update sync_status
         $this->source->sync_status = "error";
         $statusCode = $response->getStatusCode();
         $sourceRepo->addRecord($this->source, "Server origin respondend with status code {$statusCode} while downloading" . "error");
     }
     $this->source->save();
 }
Ejemplo n.º 3
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;
         }
     }
 }
Ejemplo n.º 4
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]);
 }
Ejemplo n.º 5
0
 public function optionClass($demo)
 {
     if ($demo == 'all') {
         return Source::lists('name', 'id');
     } else {
         return Source::where('demo', $demo)->lists('name', 'id');
     }
 }
Ejemplo n.º 6
0
 public function search($params)
 {
     $query = Source::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     $query->andFilterWhere(['like', 'title', $this->title]);
     return $dataProvider;
 }
 /**
  * Show the application dashboard.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     $routeName = 'dashboard';
     $routeMethod = 'index';
     $users = \App\Models\User::count();
     $sources = \App\Models\Source::count();
     $maps = \App\Models\Map::count();
     $data = compact('routeName', 'routeMethod', 'users', 'sources', 'maps');
     return view('admin.sections.dashboard.index', $data);
 }
Ejemplo n.º 8
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;
 }
Ejemplo n.º 9
0
 public function storeLayer($request)
 {
     $layer = new Layer();
     $values = $request->except('_token', '_method', 'map_id', 'source_id');
     $layer->fill($values);
     $map = Map::findOrFail($request->map_id);
     $layer->map()->associate($map);
     $source = Source::findOrFail($request->source_id);
     $layer->source()->associate($source);
     $layer->save();
     return $layer;
 }
Ejemplo n.º 10
0
 public function getSourceUrl()
 {
     if (!empty($this->source)) {
         $source = Source::findOne(['name' => $this->source]);
         if (!empty($source->url)) {
             return $source->url;
         } else {
             return false;
         }
     } else {
         return false;
     }
 }
Ejemplo n.º 11
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;
 }
Ejemplo n.º 12
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]);
 }
Ejemplo n.º 13
0
 /**
  * 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;
 }
Ejemplo n.º 14
0
 /**
  * Execute the job.
  *
  * @return void
  */
 public function handle(SourceRepository $sourceRepo)
 {
     $this->source->sync_status = "publishing";
     $this->source->save();
     $id = $this->source->id;
     $hash = $this->source->hash;
     $procFilePath = 'storage/app/sources/' . $id . '/p/file.processed';
     $pubFilePath = 'public/sources/' . $hash . '.geojson';
     // File exists in storage/app/sources/p/file.processed ?
     if (!Storage::disk('base')->exists($procFilePath)) {
         // update sync_status
         $this->source->sync_status = "error";
         $sourceRepo->addRecord($this->source, "Processed file in {$procFilePath} does not exists!", "error");
     } else {
         $result = $sourceRepo->publish($this->source, $procFilePath, $pubFilePath);
         if ($result == true) {
             $this->source->sync_status = "ready";
         } else {
             $this->source->sync_status = "error";
         }
     }
     $this->source->save();
     $sourceRepo->addRecord($this->source, "Source published successfully!", "success");
 }
Ejemplo n.º 15
0
 /**
  * Get the validation rules that apply to the request.
  *
  * @return array
  */
 public function rules()
 {
     $id = $this->route('source');
     $source = Source::findOrFail($id);
     $rules = ['name' => 'required|max:255', 'description' => 'sometimes|string', 'web' => 'sometimes|url'];
     switch ($source->origin_type) {
         case 'url':
             $typeRules = ['sync_interval' => 'required|in:never,yearly,monthly,weekly,daily,onchange'];
             break;
         case 'file':
             $typeRules = [];
             break;
         default:
             $typeRules = [];
     }
     return array_merge($rules, $typeRules);
 }
Ejemplo n.º 16
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]);
     }
 }
Ejemplo n.º 17
0
use App\Models\Source;
use App\Models\Map;
$factory->define(App\Models\User::class, function (Faker\Generator $faker) {
    return ['name' => $faker->name, 'email' => $faker->email, 'password' => bcrypt(str_random(10)), 'api_token' => str_random(60), 'remember_token' => str_random(10)];
});
$factory->define(App\Models\Setting::class, function (Faker\Generator $faker) {
    return ['group' => $faker->randomElement(['general', 'mapbox', 'preferences']), 'key' => $faker->word, 'value' => $faker->sentence];
});
$factory->define(App\Models\Map::class, function (Faker\Generator $faker) {
    $users = User::lists('id')->toArray();
    $hash = "";
    do {
        $hash = str_random(4);
    } while (Map::where("hash", "=", $hash)->first() instanceof Map);
    return ['hash' => $hash, 'user_id' => $faker->randomElement($users), 'active' => $faker->boolean(75), 'visibility' => $faker->randomElement(['public', 'public', 'public', 'shared', 'shared', 'private']), 'name' => $faker->sentence(6), 'description' => $faker->paragraph(2), 'style' => $faker->randomElement(['cilv7wj9m00uxbim8zml4zdz3', 'cikedqlyp00bbkqlxe7kzopov']), 'longitude' => 4.390819, 'latitude' => 51.92696, 'zoom' => $faker->numberBetween(8, 10), 'pitch' => $faker->numberBetween(10, 50), 'bearing' => $faker->numberBetween(20, 180), 'views' => $faker->numberBetween(1, 1000), 'created_at' => $faker->dateTimeBetween('-2 year', '-6 months'), 'updated_at' => $faker->dateTimeBetween('-5 months', 'now')];
});
$factory->define(App\Models\Source::class, function (Faker\Generator $faker) {
    $hash = "";
    do {
        $hash = str_random(4);
    } while (Source::where("hash", "=", $hash)->first() instanceof Source);
    return ['hash' => $hash, 'origin_type' => $faker->randomElement(['url', 'url', 'url', 'url', 'file', 'dropbox', 'gdrive']), 'origin_url' => $faker->randomElement([null, $faker->url]), 'origin_file' => $faker->randomElement([null, 'whatever.csv']), 'origin_format' => $faker->randomElement(['csv', 'geojson']), 'origin_size' => $faker->numberBetween(100000, 15000000), 'name' => $faker->sentence(2), 'description' => $faker->sentence(20), 'web' => 'https://schiedam.dataplatform.nl/dataset/' . $faker->slug, 'sync_status' => $faker->randomElement(['ready', 'ready', 'ready', 'ready', 'ready', 'queued', 'downloading', 'processing', 'disabled', 'disabled', 'error']), 'sync_interval' => $faker->randomElement(['never', 'onchange', 'hourly', 'daily', 'weekly', 'monthly', 'yearly']), 'synced_at' => $faker->dateTimeBetween('-1 month', '-1 day'), 'created_at' => $faker->dateTimeBetween('-2 year', '-6 months'), 'updated_at' => $faker->dateTimeBetween('-5 months', 'now')];
});
$factory->define(App\Models\Tag::class, function (Faker\Generator $faker) {
    return ['name' => $faker->word];
});
$factory->define(App\Models\Layer::class, function (Faker\Generator $faker) {
    $sources = Source::lists('id')->toArray();
    $maps = Map::lists('id')->toArray();
    return ['order' => $faker->numberBetween(0, 100), 'name' => $faker->word, 'map_id' => $faker->randomElement($maps), 'source_id' => $faker->randomElement($sources), 'minzoom' => 0, 'maxzoom' => 22, 'interactive' => $faker->boolean(75), 'type' => $faker->randomElement(['fill', 'line', 'circle']), 'visible' => $faker->boolean(90), 'opacity' => $faker->randomElement([1, 8, 5, 2, 0])];
});
Ejemplo n.º 18
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();
Ejemplo n.º 19
0
 public function optionRate()
 {
     return Source::lists('name', 'id');
 }
Ejemplo n.º 20
0
 public function getSource()
 {
     return $this->hasOne(Source::className(), ['id' => 'source_id']);
 }
Ejemplo n.º 21
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 'нет!';
 }
Ejemplo n.º 22
0
 /**
  * Finds the Source model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Source the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Source::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Ejemplo n.º 23
0
?>

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

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

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

    <?php 
echo $form->field($model, 'source_id')->dropDownList(ArrayHelper::map(Source::getSoureListByNear($model), 'id', 'fullName'));
?>


    <div class="form-group">
        <?php 
echo Html::submitButton($model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']);
?>
    </div>

    <?php 
ActiveForm::end();
?>

</div>
Ejemplo n.º 24
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();
Ejemplo n.º 25
0
 public function syncAllSources()
 {
     $isSynchronizable = ['url'];
     $sourcesAll = collect();
     // sync yearly sources
     $aYearAgo = Carbon::now()->subYear();
     $sourcesYearly = Source::whereIn('origin_type', $isSynchronizable)->where('sync_interval', '=', 'yearly')->where('synced_at', '<', $aYearAgo)->get();
     $sourcesAll = $sourcesAll->merge($sourcesYearly);
     // sync monthly sources
     $aMonthAgo = Carbon::now()->subMonth();
     $sourcesMonthly = Source::whereIn('origin_type', $isSynchronizable)->where('sync_interval', '=', 'monthly')->where('synced_at', '<', $aMonthAgo)->get();
     $sourcesAll = $sourcesAll->merge($sourcesMonthly);
     // sync weekly sources
     $aWeekAgo = Carbon::now()->subWeek();
     $sourcesWeekly = Source::whereIn('origin_type', $isSynchronizable)->where('sync_interval', '=', 'weekly')->where('synced_at', '<', $aWeekAgo)->get();
     $sourcesAll = $sourcesAll->merge($sourcesWeekly);
     // sync daily sources
     $aDayAgo = Carbon::now()->subDay();
     $sourcesDayly = Source::whereIn('origin_type', $isSynchronizable)->where('sync_interval', '=', 'daily')->where('synced_at', '<', $aDayAgo)->get();
     $sourcesAll = $sourcesAll->merge($sourcesDayly);
     // sync onchange sources
     $sourcesOnchange = Source::whereIn('origin_type', $isSynchronizable)->where('sync_interval', '=', 'onchange')->get();
     $sourcesAll = $sourcesAll->merge($sourcesOnchange);
     foreach ($sourcesAll as $source) {
         $this->syncSource($source);
     }
 }
Ejemplo n.º 26
0
 public function actionDefault()
 {
     $this->data->items = Source::findAll();
 }
Ejemplo n.º 27
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;
 }
Ejemplo n.º 28
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]);
     }
 }
Ejemplo n.º 29
0
 public function loadModel($id)
 {
     $model = Source::findOne($id);
     if ($model === null) {
         throw new \yii\web\HttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
Ejemplo n.º 30
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]);
     }
 }