UploadFileParsingForm.php
1.7 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
52
53
54
55
56
57
58
59
60
61
62
<?php
namespace backend\models;
use yii\base\Model;
use yii\web\UploadedFile;
use Yii;
use common\components\CustomVarDamp;
/**
* UploadForm is the model behind the upload form.
*/
class UploadFileParsingForm extends Model
{
/**
* @var UploadedFile file attribute
*/
public $file;
public $importer_id;
public $action;
public $delimiter;
public $delete_price;
public $delete_prefix;
/**
* @return array the validation rules.
*/
public function rules()
{
return [
['importer_id', 'required', 'message' => 'Не указан поставщик!' ],
['file', 'required', 'message' => 'Не выбран файл!' ],
//@todo - not working this file validator!!! - fixed
[['file'], 'file'],// 'extensions' => ['csv', 'xml'] ],
// 'wrongMimeType' => 'Указан неподдерживаемый тип файла. Можно выбирать csv, xml файлы.' ],
['importer_id', 'integer','max' => 999999, 'min' => 0 ],
[['action','delete_prefix', 'delete_price'], 'boolean'],
['delimiter', 'string', 'max' => 1],
['delimiter', 'default', 'value' => ';']
];
}
public function attributeLabels()
{
return [
'file' => Yii::t('app', 'Источник'),
'importer_id' => Yii::t('app', 'Поставщик'),
'delimiter' => Yii::t('app', 'Разделитель'),
];
}
public function readFile($filePath){
$data = Yii::$app->multiparser->parse($filePath);
if( !is_array($data) ){
$data = ['No results'];
}
return $data;
}
}