Blame view

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