3cf42f5c
Mihail
init commit - bas...
|
1
|
<?php
|
b13b1c83
Mihail
final version par...
|
2
|
namespace backend\models;
|
3cf42f5c
Mihail
init commit - bas...
|
3
4
5
|
use yii\base\Model;
use yii\web\UploadedFile;
|
036717a1
Mihail
add error excepti...
|
6
|
use yii\multiparser\ParserHandler;
|
b13b1c83
Mihail
final version par...
|
7
|
use Yii;
|
3663f570
Mihail
draft commit
|
8
|
use common\components\debug\CustomVarDamp;
|
3cf42f5c
Mihail
init commit - bas...
|
9
10
11
12
|
/**
* UploadForm is the model behind the upload form.
*/
|
77422ce3
Mihail
edit upload form
|
13
|
class UploadFileParsingForm extends Model
|
3cf42f5c
Mihail
init commit - bas...
|
14
15
16
17
18
|
{
/**
* @var UploadedFile file attribute
*/
public $file;
|
02359b64
Mihail
add mail parser a...
|
19
20
|
public $importer;
public $action;
|
3663f570
Mihail
draft commit
|
21
22
23
|
public $delimiter;
public $delete_price;
public $delete_prefix;
|
e774f057
Mihail
work with custome...
|
24
|
public $first;
|
3cf42f5c
Mihail
init commit - bas...
|
25
26
27
28
29
30
31
|
/**
* @return array the validation rules.
*/
public function rules()
{
return [
|
3663f570
Mihail
draft commit
|
32
33
34
|
['importer', 'required', 'message' => 'Не указан поставщик!' ],
['file', 'required', 'message' => 'Не выбран файл!' ],
//@todo - not working this file validator!!! - fixed
|
36b545ad
Mihail
final upload form...
|
35
|
[['file'], 'file'],// 'extensions' => ['csv', 'xml'] ],
|
3663f570
Mihail
draft commit
|
36
37
38
39
|
// 'wrongMimeType' => 'Указан неподдерживаемый тип файла. Можно выбирать csv, xml файлы.' ],
['importer', 'integer','max' => 999999, 'min' => 0 ],
[['action','delete_prefix', 'delete_price'], 'boolean'],
['delimiter', 'string', 'max' => 1],
|
e774f057
Mihail
work with custome...
|
40
41
|
['delimiter', 'default', 'value' => ';'],
['first', 'safe']
|
02359b64
Mihail
add mail parser a...
|
42
|
|
b13b1c83
Mihail
final version par...
|
43
44
45
46
47
48
49
|
];
}
public function attributeLabels()
{
return [
'file' => Yii::t('app', 'Источник'),
|
3663f570
Mihail
draft commit
|
50
51
|
'importer' => Yii::t('app', 'Поставщик'),
'delimiter' => Yii::t('app', 'Разделитель'),
|
3cf42f5c
Mihail
init commit - bas...
|
52
53
|
];
}
|
500b481a
Administrator
JSON
|
54
55
|
public function readFile($filePath){
|
036717a1
Mihail
add error excepti...
|
56
|
|
d10eb153
Mihail
add multiparser y...
|
57
|
$data = Yii::$app->multiparser->parse($filePath);
|
e774f057
Mihail
work with custome...
|
58
|
// \common\components\CustomVarDamp::dumpAndDie($data);
|
500b481a
Administrator
JSON
|
59
60
61
62
63
|
if( !is_array($data) ){
$data = ['No results'];
}
return $data;
}
|
3cf42f5c
Mihail
init commit - bas...
|
64
|
}
|