Commit 9ef73019cc3241e1a4613f27275294b4bb1ed019

Authored by Mihail
1 parent 2772f19c

parser

backend/components/parsers/ParserHandler.php
... ... @@ -22,7 +22,7 @@ class ParserHandler {
22 22 $this->run();
23 23 }
24 24  
25   - private function run(){
  25 + public function run(){
26 26 if ($this->extension = '.csv'){
27 27 $csvParser = new Reader( $this->filePath );
28 28 return $csvParser->read();
... ...
backend/controllers/ParserController.php
... ... @@ -63,10 +63,12 @@ class ParserController extends Controller
63 63 $filePath = Yii::getAlias('@webroot') . '/uploads/' . $model->file->baseName . '.' . $model->file->extension;
64 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 72 $provider = new ArrayDataProvider([
71 73 'allModels' => $data,
72 74 'pagination' => [
... ... @@ -78,7 +80,7 @@ class ParserController extends Controller
78 80 ]);
79 81  
80 82 return $this->render('results',
81   - ['model' => $model,
  83 + ['model' => $data,
82 84 'dataProvider' => $provider]);
83 85 }
84 86 }
... ...
backend/views/parser/index.php
1 1 <?php
2 2 use yii\widgets\ActiveForm;
3 3 ?>
4   -
  4 + <div class="catalog-view">
5 5 <?php $form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']]) ?>
6 6  
7 7 <?= $form->field($model, 'file')->fileInput() ?>
8 8  
9 9 <button>Прочитать</button>
10 10  
11   -<?php ActiveForm::end() ?>
12 11 \ No newline at end of file
  12 +<?php ActiveForm::end() ?>
  13 + </div>
13 14 \ No newline at end of file
... ...
backend/views/parser/results.php
... ... @@ -4,43 +4,21 @@ use yii\helpers\Html;
4 4 use yii\grid\GridView;
5 5  
6 6 /* @var $this yii\web\View */
7   -/* @var $searchModel backend\models\ArticlesSearch */
  7 +/* @var $searchModel backend\models\CatalogSearch */
8 8 /* @var $dataProvider yii\data\ActiveDataProvider */
9 9  
10 10 $this->title = 'Results';
11 11 $this->params['breadcrumbs'][] = $this->title;
12 12 ?>
13   -<div class="articles-index">
  13 +<div class="catalog-index">
14 14  
15 15 <h1><?= Html::encode($this->title) ?></h1>
16 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 20 <?= GridView::widget([
23 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 24 </div>
47 25 \ No newline at end of file
... ...
vendor/hranicka/csv/src/Reader.php
... ... @@ -41,7 +41,7 @@ class Reader implements \IteratorAggregate
41 41 * @param string $escape
42 42 * @return $this
43 43 */
44   - public function setup($delimiter = ',', $enclosure = '"', $escape = '\')
  44 + public function setup($delimiter = ';', $enclosure = '"', $escape = '\')
45 45 {
46 46 $this->delimiter = $delimiter;
47 47 $this->enclosure = $enclosure;
... ... @@ -93,8 +93,8 @@ class Reader implements \IteratorAggregate
93 93 // var_dump($return);
94 94 // echo "</pre>";
95 95 // die;
96   -// throw new InvalidFileException("Invalid columns detected on line #$line .");
97   - return $return;
  96 + throw new InvalidFileException("Invalid columns detected on line #$line .");
  97 + // return $return;
98 98 }
99 99  
100 100 $return[] = array_combine($keys, $row);
... ...