From 6efcd4fab59ac2fff8fad9d6b85f0c4ae8c3f49f Mon Sep 17 00:00:00 2001 From: Mihail Date: Thu, 27 Aug 2015 14:22:48 +0300 Subject: [PATCH] edit csv parser - work with first line attribute --- backend/components/parsers/CsvParser.php | 6 +++--- backend/controllers/ParserController.php | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/backend/components/parsers/CsvParser.php b/backend/components/parsers/CsvParser.php index 8ffc4a7..af6322b 100644 --- a/backend/components/parsers/CsvParser.php +++ b/backend/components/parsers/CsvParser.php @@ -30,13 +30,15 @@ class CsvParser implements \IteratorAggregate { public function setup( $file, $first_line, $hasHeaderRow = TRUE, $delimiter = ';') { + $this->first_line = $first_line; + $this->file = $file; $this->file->setCsvControl($delimiter); $this->file->setFlags(\SplFileObject::READ_CSV); $this->file->seek( $this->first_line ); - $this->first_line = $first_line; + $this->in_charset = 'windows-1251'; $this->hasHeaderRow = $hasHeaderRow; } @@ -104,10 +106,8 @@ class CsvParser implements \IteratorAggregate { // @todo add comments { $dirt_value_arr = $this->file->fgetcsv( ); - $dirt_value_arr = array_slice( $dirt_value_arr, 2 ); $clear_arr = Encoder::encodeArray( $this->in_charset, $this->out_charset, $dirt_value_arr ); - return $clear_arr; } diff --git a/backend/controllers/ParserController.php b/backend/controllers/ParserController.php index 676913e..ecc266c 100644 --- a/backend/controllers/ParserController.php +++ b/backend/controllers/ParserController.php @@ -63,7 +63,7 @@ class ParserController extends Controller $filePath = Yii::getAlias('@webroot') . '/uploads/' . $model->file->baseName . '.' . $model->file->extension; $model->file->saveAs( $filePath ); - $parser = new ParserHandler( $filePath, 2 ); + $parser = new ParserHandler( $filePath, 1 ); $data = $parser->run(); if( !is_array($data) ){ -- libgit2 0.21.4