From dfeb2d10be99e9c778eee8412e4a22334e45f475 Mon Sep 17 00:00:00 2001 From: Mihail Date: Thu, 3 Sep 2015 17:01:56 +0300 Subject: [PATCH] edit universal csv parser --- backend/components/parsers/CsvParser.php | 33 ++++++++++++++++----------------- backend/views/parser/results.php | 4 ++++ 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/backend/components/parsers/CsvParser.php b/backend/components/parsers/CsvParser.php index 739c73c..7a5ab32 100644 --- a/backend/components/parsers/CsvParser.php +++ b/backend/components/parsers/CsvParser.php @@ -35,7 +35,7 @@ class CsvParser implements \IteratorAggregate { /** @var array - array of headers values */ private $keys; - public function setup( $file, $first_line, $first_column, $hasHeaderRow = TRUE, $delimiter = ';') + public function setup( $file, $first_line, $first_column, $hasHeaderRow = false, $delimiter = ';') { $this->first_line = $first_line; @@ -57,15 +57,7 @@ class CsvParser implements \IteratorAggregate { return new \ArrayIterator($this->read()); } - /** - * @return array - * @throws InvalidFileException - * @deprecated Use ::read instead. - */ - public function parseAll() - { - return $this->read(); - } + /** * @return array @@ -106,22 +98,29 @@ class CsvParser implements \IteratorAggregate { } - private function closeHandler() + protected function closeHandler() { $this->file = NULL; } - private function readRow() + protected function readRow() // @todo add comments { - $dirt_value_arr = $this->file->fgetcsv( ); - $dirt_value_arr = array_slice( $dirt_value_arr, $this->first_column ); - $clear_arr = Encoder::encodeArray( $this->in_charset, $this->out_charset, $dirt_value_arr ); + + $row = $this->file->fgetcsv( ); + // + if (is_array($row)) { + $row = array_slice( $row, $this->first_column ); + $row = Encoder::encodeArray( $this->in_charset, $this->out_charset, $row ); + } else{ + $row = false; + } + // if ($this->keys !== NULL) -// @$clear_arr[3] = ValueFilter::pricefilter($clear_arr[3]); +// @$clear_arr[3] = ValueFilter::pricefilter($clear_arr[3]);{}{}{} - return $clear_arr; + return $row; } diff --git a/backend/views/parser/results.php b/backend/views/parser/results.php index b220e2c..ac8e56d 100644 --- a/backend/views/parser/results.php +++ b/backend/views/parser/results.php @@ -2,6 +2,7 @@ use yii\helpers\Html; use yii\grid\GridView; +use yii\grid\SerialColumn; /* @var $this yii\web\View */ /* @var $searchModel backend\models\CatalogSearch */ @@ -19,6 +20,9 @@ $this->params['breadcrumbs'][] = $this->title; $dataProvider, + 'columns' => [['class' => SerialColumn::className()], + '1', + '2',] ]); ?> 'btn btn-primary', 'name' => 'Return',]) ?> -- libgit2 0.21.4