Blame view

backend/models/UploadFileRgForm.php 1.32 KB
293f57f9   Mihail   add upload rg gro...
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
  <?php
  namespace backend\models;
  
  use yii\base\ErrorException;
  use yii\base\Model;
  use yii\web\UploadedFile;
  use Yii;
  use common\components\CustomVarDamp;
  
  /**
   * UploadForm is the model behind the upload form.
   */
  class UploadFileRgForm extends Model
  {
      /**
       * @var UploadedFile file attribute
       */
      // атрибуты формы
      public $file;
      public $file_path;
      public $importer_id;
  
  
  
      public function rules()
      {
          return [
              ['file', 'required', 'message' => 'Не выбран файл!' ],
              ['importer_id', 'required', 'message' => 'Не указан поставщик!' ],
              [['file'], 'file', 'extensions' => 'xlsx', 'checkExtensionByMimeType'=>false ]
          ];
      }
  
      public function attributeLabels()
      {
          return [
              'file' => Yii::t('app', 'Источник'),
              'importer_id' => Yii::t('app', 'Поставщик'),
          ];
      }
  
      public function readFile( $options = [] ){
  
          $data = Yii::$app->multiparser->parse( $this->file_path, $options );
          if( !is_array( $data ) ){
              throw new ErrorException("Ошибка чтения из файла RG групп {$this->file_path}");
          }
  
3942e7a3   Mihail   fixed issue with ...
49
50
          if( file_exists($this->file_path) )
              unlink($this->file_path);
293f57f9   Mihail   add upload rg gro...
51
52
53
54
  
          return $data;
      }
  
293f57f9   Mihail   add upload rg gro...
55
56
57
  
  
  }