/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = ParseRegion::find(); // add conditions that should always apply here $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; } // grid filtering conditions $query->andFilterWhere(['id' => $this->id, 'updated_at' => $this->updated_at]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'url', $this->url]); return $dataProvider; }
<?php /* @var $this yii\web\View */ use yii\helpers\Html; /* @var $region \common\models\ParseRegion */ $this->title = 'Dashboard'; $this->params['breadcrumbs'][] = $this->title; $parse_regions = \common\models\ParseRegion::find()->all(); ?> <div class="group-index"> <table class="table table-bordered table-hover"> <tbody> <tr> <th>Район</th> <th>Кол-во кск</th> <th>Кол-во ссылок</th> <th>Кол-во отчетов</th> <th>Дата</th> </tr> <?php foreach ($parse_regions as $region) { ?> <tr> <td><?php echo $region->name; ?> </td> <td><?php echo \common\models\ParseKsk::find()->where(['parse_region_id' => $region->id])->count() . ' '; ?> </td>
<?php use yii\helpers\ArrayHelper; use yii\helpers\Html; use yii\grid\GridView; /* @var $this yii\web\View */ /* @var $searchModel backend\modules\parse\models\ParseKskSearch */ /* @var $dataProvider yii\data\ActiveDataProvider */ $this->title = 'Parse Ksks'; $this->params['breadcrumbs'][] = $this->title; ?> <div class="parse-ksk-index"> <h1><?php echo Html::encode($this->title); ?> </h1> <?php // echo $this->render('_search', ['model' => $searchModel]); ?> <p> <?php echo Html::a('Create Parse Ksk', ['create'], ['class' => 'btn btn-success']); ?> </p> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], 'id', ['attribute' => 'parse_region_id', 'value' => 'parseRegion.name', 'filter' => ArrayHelper::map(\common\models\ParseRegion::find()->all(), 'id', 'name')], 'name', 'url_ksk:url', 'url_otchet:url', ['class' => 'yii\\grid\\ActionColumn']]]); ?> </div>
public function actionUpdateReport() { foreach (ParseRegion::find()->all() as $region) { /* @var $region ParseRegion*/ echo $region->url . "\n"; $saved = 0; $errors = []; $models = ParseKsk::find()->where(['parse_region_id' => $region->id])->andWhere(['IS NOT', 'url_otchet', null])->all(); foreach ($models as $model) { /* @var $model ParseKsk */ echo ' ' . $model->url_otchet . "\n"; $saw = new NokogiriHelper(file_get_contents($model->url_otchet)); $ok = $saved; foreach ($saw->get('.col_f_content') as $forum_name) { $h4s = $forum_name['h4']; if (isset($forum_name['span'][0]['span'])) { $posted_at = $forum_name['span'][0]['span'][0]['#text'][0]; } else { $posted_at = $forum_name['span'][1]['span'][0]['#text'][0]; } foreach ($h4s as $h4) { $a = $h4['a'][0]; $name = trim($a['span'][0]['#text'][0]); $url = $a['href']; $model_otchet = ParseOtchet::find()->where(['name' => $name])->one(); if (is_null($model_otchet)) { $model_otchet = new ParseOtchet(); $model_otchet->parse_ksk_id = $model->id; $model_otchet->name = $name; $model_otchet->url_otchet = $url; $model_otchet->posted_at = date('Y-m-d H:i:s', strtotime($posted_at)); $model_otchet->updated_at = new \yii\db\Expression('utc_timestamp()'); $model_otchet->save() ? $saved++ : ($errors[] = $model_otchet->errors); } } } if ($ok < $saved) { $model = ParseKsk::findOne($model->id); $model->updated_at = new \yii\db\Expression('utc_timestamp()'); $model->save(); } } if ($saved > 0) { $region = ParseRegion::findOne($region->id); $region->updated_at = new \yii\db\Expression('utc_timestamp()'); $region->save(); } echo "saved - {$saved}\n"; } }