1 2
<?php /**
3
4
*/
5
namespace yii\multiparser;
6
use common\components\CustomVarDamp;
7
8
9 10 11
/** * Class CsvParser * @package yii\multiparser
12
* @todo - перевести на анг. яз.
13
14
class CsvParser extends TableParser
15
{
16
/** @var string - разделитель csv */
17
public $delimiter = ';';
18
19
20
21
/**
22
* метод устанвливает нужные настройки объекта SplFileObject, для работы с csv
23
24 25
public function setup() {
26
27 28 29
$this->file->setCsvControl($this->delimiter); $this->file->setFlags(\SplFileObject::READ_CSV); $this->file->setFlags(\SplFileObject::SKIP_EMPTY);
30
31
parent::setup();
32
33
}
34
35 36
public function read() {
37
parent::read();
38
39
return $this->result;
40
41
42
43
protected function readRow( )
44
45 46
$this->row = $this->file->fgetcsv(); }
47
48
protected function isEmptyRow(){
49
50
$is_empty = false;
51
52 53 54
if ($this->row === false || $this->row === NULL ) { return true; }
55
56 57
$j = 0; for ($i = 1; $i <= count( $this->row ); $i++) {
58
59 60
if ( $this->isEmptyColumn( $this->row[$i - 1] ) ) { $j++;
61
62
63 64 65 66 67
if ( $j >= $this->min_column_quantity ) { $is_empty = true; break; } }
68
69
return $is_empty;
70 71
72 73 74
protected function isEmptyColumn( $val ){ return $val == ''; }
75