Commit 48829d222ed6f4827fc9db5d96051d944a0336dc
1 parent
da63a578
parser
Showing
4 changed files
with
14 additions
and
33 deletions
Show diff stats
backend/components/parsers/ParserHandler.php
@@ -22,7 +22,7 @@ class ParserHandler { | @@ -22,7 +22,7 @@ class ParserHandler { | ||
22 | $this->run(); | 22 | $this->run(); |
23 | } | 23 | } |
24 | 24 | ||
25 | - private function run(){ | 25 | + public function run(){ |
26 | if ($this->extension = '.csv'){ | 26 | if ($this->extension = '.csv'){ |
27 | $csvParser = new Reader( $this->filePath ); | 27 | $csvParser = new Reader( $this->filePath ); |
28 | return $csvParser->read(); | 28 | return $csvParser->read(); |
backend/controllers/ParserController.php
@@ -63,10 +63,12 @@ class ParserController extends Controller | @@ -63,10 +63,12 @@ class ParserController extends Controller | ||
63 | $filePath = Yii::getAlias('@webroot') . '/uploads/' . $model->file->baseName . '.' . $model->file->extension; | 63 | $filePath = Yii::getAlias('@webroot') . '/uploads/' . $model->file->baseName . '.' . $model->file->extension; |
64 | $model->file->saveAs( $filePath ); | 64 | $model->file->saveAs( $filePath ); |
65 | 65 | ||
66 | - $data = new ParserHandler( $filePath ); | ||
67 | -// echo "<pre>"; | ||
68 | -// var_dump($data); | ||
69 | -// echo "</pre>"; | 66 | + $parser = new ParserHandler( $filePath ); |
67 | + $data = $parser->run(); | ||
68 | + | ||
69 | + if( !is_array($data) ){ | ||
70 | + $data = ['No results']; | ||
71 | + } | ||
70 | $provider = new ArrayDataProvider([ | 72 | $provider = new ArrayDataProvider([ |
71 | 'allModels' => $data, | 73 | 'allModels' => $data, |
72 | 'pagination' => [ | 74 | 'pagination' => [ |
@@ -78,7 +80,7 @@ class ParserController extends Controller | @@ -78,7 +80,7 @@ class ParserController extends Controller | ||
78 | ]); | 80 | ]); |
79 | 81 | ||
80 | return $this->render('results', | 82 | return $this->render('results', |
81 | - ['model' => $model, | 83 | + ['model' => $data, |
82 | 'dataProvider' => $provider]); | 84 | 'dataProvider' => $provider]); |
83 | } | 85 | } |
84 | } | 86 | } |
backend/views/parser/index.php
1 | <?php | 1 | <?php |
2 | use yii\widgets\ActiveForm; | 2 | use yii\widgets\ActiveForm; |
3 | ?> | 3 | ?> |
4 | - | 4 | + <div class="catalog-view"> |
5 | <?php $form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']]) ?> | 5 | <?php $form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']]) ?> |
6 | 6 | ||
7 | <?= $form->field($model, 'file')->fileInput() ?> | 7 | <?= $form->field($model, 'file')->fileInput() ?> |
8 | 8 | ||
9 | <button>Прочитать</button> | 9 | <button>Прочитать</button> |
10 | 10 | ||
11 | -<?php ActiveForm::end() ?> | ||
12 | \ No newline at end of file | 11 | \ No newline at end of file |
12 | +<?php ActiveForm::end() ?> | ||
13 | + </div> | ||
13 | \ No newline at end of file | 14 | \ No newline at end of file |
backend/views/parser/results.php
@@ -4,43 +4,21 @@ use yii\helpers\Html; | @@ -4,43 +4,21 @@ use yii\helpers\Html; | ||
4 | use yii\grid\GridView; | 4 | use yii\grid\GridView; |
5 | 5 | ||
6 | /* @var $this yii\web\View */ | 6 | /* @var $this yii\web\View */ |
7 | -/* @var $searchModel backend\models\ArticlesSearch */ | 7 | +/* @var $searchModel backend\models\CatalogSearch */ |
8 | /* @var $dataProvider yii\data\ActiveDataProvider */ | 8 | /* @var $dataProvider yii\data\ActiveDataProvider */ |
9 | 9 | ||
10 | $this->title = 'Results'; | 10 | $this->title = 'Results'; |
11 | $this->params['breadcrumbs'][] = $this->title; | 11 | $this->params['breadcrumbs'][] = $this->title; |
12 | ?> | 12 | ?> |
13 | -<div class="articles-index"> | 13 | +<div class="catalog-index"> |
14 | 14 | ||
15 | <h1><?= Html::encode($this->title) ?></h1> | 15 | <h1><?= Html::encode($this->title) ?></h1> |
16 | <?php // echo $this->render('_search', ['model' => $searchModel]); ?> | 16 | <?php // echo $this->render('_search', ['model' => $searchModel]); ?> |
17 | 17 | ||
18 | - <p> | ||
19 | - <?= Html::a('Создать', ['create', 'type' =>$type], ['class' => 'btn btn-success']) ?> | ||
20 | - </p> | 18 | + |
21 | 19 | ||
22 | <?= GridView::widget([ | 20 | <?= GridView::widget([ |
23 | 'dataProvider' => $dataProvider, | 21 | 'dataProvider' => $dataProvider, |
24 | - 'filterModel' => $searchModel, | ||
25 | - 'columns' => [ | ||
26 | - ['class' => 'yii\grid\SerialColumn'], | ||
27 | - | ||
28 | - 'id', | ||
29 | - 'name', | ||
30 | - 'translit', | ||
31 | - 'title', | ||
32 | - [ | ||
33 | - 'format' => 'image', | ||
34 | - 'attribute'=>'image', | ||
35 | - ], | ||
36 | - // 'body:ntext', | ||
37 | - // 'meta_title', | ||
38 | - // 'description', | ||
39 | - // 'h1', | ||
40 | - // 'seo_text:ntext', | ||
41 | - | ||
42 | - ['class' => 'yii\grid\ActionColumn'], | ||
43 | - ], | ||
44 | ]); ?> | 22 | ]); ?> |
45 | 23 | ||
46 | </div> | 24 | </div> |
47 | \ No newline at end of file | 25 | \ No newline at end of file |