Commit 6efcd4fab59ac2fff8fad9d6b85f0c4ae8c3f49f

Authored by Mihail
1 parent 8b105e42

edit csv parser - work with first line attribute

backend/components/parsers/CsvParser.php
... ... @@ -30,13 +30,15 @@ class CsvParser implements \IteratorAggregate {
30 30 public function setup( $file, $first_line, $hasHeaderRow = TRUE, $delimiter = ';')
31 31 {
32 32  
  33 + $this->first_line = $first_line;
  34 +
33 35 $this->file = $file;
34 36  
35 37 $this->file->setCsvControl($delimiter);
36 38 $this->file->setFlags(\SplFileObject::READ_CSV);
37 39 $this->file->seek( $this->first_line );
38 40  
39   - $this->first_line = $first_line;
  41 +
40 42 $this->in_charset = 'windows-1251';
41 43 $this->hasHeaderRow = $hasHeaderRow;
42 44 }
... ... @@ -104,10 +106,8 @@ class CsvParser implements \IteratorAggregate {
104 106 // @todo add comments
105 107 {
106 108 $dirt_value_arr = $this->file->fgetcsv( );
107   -
108 109 $dirt_value_arr = array_slice( $dirt_value_arr, 2 );
109 110 $clear_arr = Encoder::encodeArray( $this->in_charset, $this->out_charset, $dirt_value_arr );
110   -
111 111 return $clear_arr;
112 112  
113 113 }
... ...
backend/controllers/ParserController.php
... ... @@ -63,7 +63,7 @@ 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   - $parser = new ParserHandler( $filePath, 2 );
  66 + $parser = new ParserHandler( $filePath, 1 );
67 67 $data = $parser->run();
68 68  
69 69 if( !is_array($data) ){
... ...