UploadFileParsingForm.php
1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
namespace backend\models;
use yii\base\Model;
use yii\web\UploadedFile;
use backend\components\ParserHandler;
use Yii;
/**
* UploadForm is the model behind the upload form.
*/
class UploadFileParsingForm extends Model
{
/**
* @var UploadedFile file attribute
*/
public $file;
public $first_line;
public $first_column;
/**
* @return array the validation rules.
*/
public function rules()
{
return [
[['file'], 'file', 'extensions' => ['csv', 'xml'] ],
['first_line', 'integer'],
['first_column', 'integer']
];
}
public function attributeLabels()
{
return [
'file' => Yii::t('app', 'Источник'),
'first_line' => Yii::t('app', 'Первая значимая строка'),
'first_column' => Yii::t('app', 'Первый значимый столбец'),
];
}
public function readFile($filePath){
$parser = new ParserHandler( $filePath, $this );
$data = $parser->run();
if( !is_array($data) ){
$data = ['No results'];
}
return $data;
}
}