/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = ParseOtchetFile::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, 'parse_otchet_id' => $this->parse_otchet_id]); $query->andFilterWhere(['like', 'file_name', $this->file_name])->andFilterWhere(['like', 'path', $this->path]); return $dataProvider; }
/** * Finds the ParseOtchetFile model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return ParseOtchetFile the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = ParseOtchetFile::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function actionUpdateReportFile() { return; $this->checkPath(); $count = 0; $files = 0; foreach (ParseOtchet::find()->limit(10)->all() as $model) { if (ParseOtchetFile::findOne(['parse_otchet_id' => $model->id]) === null && $model->url_otchet !== null && $model->text === null) { $saw = new NokogiriHelper(file_get_contents($model->url_otchet)); $text = []; foreach ($saw->get('div.post p') as $p) { if (isset($p['a'])) { foreach ($p['a'] as $a) { echo $a['href'] . "\n\n"; $file = file_get_contents($a['href']); $url_base = "C:/OpenServer/domains/yii2-papa/statics/web/ksk/otchet/{$model->id}"; $this->checkPath($url_base); $size = sizeof(scandir($url_base)); if (file_put_contents("{$url_base}/{$size}.jpg", $file) !== false) { $modelFile = new ParseOtchetFile(); $modelFile->file_name = $a['title']; $modelFile->path = "{$url_base}/{$size}.jpg"; $modelFile->parse_otchet_id = $model->id; if ($modelFile->save()) { $files++; echo str_pad("otchet-{$model->id}", 15) . str_pad("{$modelFile->path}", 50) . str_pad("SUCCESS", 15) . "\n"; } else { echo str_pad("otchet-{$model->id}", 15) . str_pad(Json::encode($modelFile->errors), 50) . str_pad("ERROR MODEL", 15) . "\n"; } } else { echo str_pad("otchet-{$model->id}", 15) . str_pad("{$url_base}/{$size}.jpg", 50) . str_pad("ERROR FILE", 15) . "\n"; } } } !isset($p['#text']) ?: ($text[] = $p['#text']); } $model = ParseOtchet::findOne($model->id); $model->text = $this->formatText($text); $model->save(); $count++; } } echo "updated - {$count}\ncreated files - {$files}\n"; }