Commit dfeb2d10be99e9c778eee8412e4a22334e45f475
1 parent
574db870
edit universal csv parser
Showing
2 changed files
with
20 additions
and
17 deletions
Show diff stats
backend/components/parsers/CsvParser.php
@@ -35,7 +35,7 @@ class CsvParser implements \IteratorAggregate { | @@ -35,7 +35,7 @@ class CsvParser implements \IteratorAggregate { | ||
35 | /** @var array - array of headers values */ | 35 | /** @var array - array of headers values */ |
36 | private $keys; | 36 | private $keys; |
37 | 37 | ||
38 | - public function setup( $file, $first_line, $first_column, $hasHeaderRow = TRUE, $delimiter = ';') | 38 | + public function setup( $file, $first_line, $first_column, $hasHeaderRow = false, $delimiter = ';') |
39 | { | 39 | { |
40 | 40 | ||
41 | $this->first_line = $first_line; | 41 | $this->first_line = $first_line; |
@@ -57,15 +57,7 @@ class CsvParser implements \IteratorAggregate { | @@ -57,15 +57,7 @@ class CsvParser implements \IteratorAggregate { | ||
57 | return new \ArrayIterator($this->read()); | 57 | return new \ArrayIterator($this->read()); |
58 | } | 58 | } |
59 | 59 | ||
60 | - /** | ||
61 | - * @return array | ||
62 | - * @throws InvalidFileException | ||
63 | - * @deprecated Use ::read instead. | ||
64 | - */ | ||
65 | - public function parseAll() | ||
66 | - { | ||
67 | - return $this->read(); | ||
68 | - } | 60 | + |
69 | 61 | ||
70 | /** | 62 | /** |
71 | * @return array | 63 | * @return array |
@@ -106,22 +98,29 @@ class CsvParser implements \IteratorAggregate { | @@ -106,22 +98,29 @@ class CsvParser implements \IteratorAggregate { | ||
106 | } | 98 | } |
107 | 99 | ||
108 | 100 | ||
109 | - private function closeHandler() | 101 | + protected function closeHandler() |
110 | { | 102 | { |
111 | $this->file = NULL; | 103 | $this->file = NULL; |
112 | } | 104 | } |
113 | 105 | ||
114 | - private function readRow() | 106 | + protected function readRow() |
115 | // @todo add comments | 107 | // @todo add comments |
116 | { | 108 | { |
117 | - $dirt_value_arr = $this->file->fgetcsv( ); | ||
118 | - $dirt_value_arr = array_slice( $dirt_value_arr, $this->first_column ); | ||
119 | - $clear_arr = Encoder::encodeArray( $this->in_charset, $this->out_charset, $dirt_value_arr ); | 109 | + |
110 | + $row = $this->file->fgetcsv( ); | ||
111 | + // | ||
112 | + if (is_array($row)) { | ||
113 | + $row = array_slice( $row, $this->first_column ); | ||
114 | + $row = Encoder::encodeArray( $this->in_charset, $this->out_charset, $row ); | ||
115 | + } else{ | ||
116 | + $row = false; | ||
117 | + } | ||
118 | + | ||
120 | 119 | ||
121 | // if ($this->keys !== NULL) | 120 | // if ($this->keys !== NULL) |
122 | -// @$clear_arr[3] = ValueFilter::pricefilter($clear_arr[3]); | 121 | +// @$clear_arr[3] = ValueFilter::pricefilter($clear_arr[3]);{}{}{} |
123 | 122 | ||
124 | - return $clear_arr; | 123 | + return $row; |
125 | 124 | ||
126 | } | 125 | } |
127 | 126 |
backend/views/parser/results.php
@@ -2,6 +2,7 @@ | @@ -2,6 +2,7 @@ | ||
2 | 2 | ||
3 | use yii\helpers\Html; | 3 | use yii\helpers\Html; |
4 | use yii\grid\GridView; | 4 | use yii\grid\GridView; |
5 | +use yii\grid\SerialColumn; | ||
5 | 6 | ||
6 | /* @var $this yii\web\View */ | 7 | /* @var $this yii\web\View */ |
7 | /* @var $searchModel backend\models\CatalogSearch */ | 8 | /* @var $searchModel backend\models\CatalogSearch */ |
@@ -19,6 +20,9 @@ $this->params['breadcrumbs'][] = $this->title; | @@ -19,6 +20,9 @@ $this->params['breadcrumbs'][] = $this->title; | ||
19 | 20 | ||
20 | <?= GridView::widget([ | 21 | <?= GridView::widget([ |
21 | 'dataProvider' => $dataProvider, | 22 | 'dataProvider' => $dataProvider, |
23 | + 'columns' => [['class' => SerialColumn::className()], | ||
24 | + '1', | ||
25 | + '2',] | ||
22 | ]); ?> | 26 | ]); ?> |
23 | 27 | ||
24 | <?= Html::a('Вернуться', ['parser/index'], ['class' => 'btn btn-primary', 'name' => 'Return',]) ?> | 28 | <?= Html::a('Вернуться', ['parser/index'], ['class' => 'btn btn-primary', 'name' => 'Return',]) ?> |