Blame view

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