mode ) { // автозагрузка, проставим сценарий $this->scenario = 'auto'; } } public function rules() { return [ ['importer_id', 'required', 'message' => 'Не указан поставщик!' ], ['file', 'required', 'message' => 'Не выбран файл!' ], [['file'], 'file', 'extensions' => ['csv', 'xlsx'], 'checkExtensionByMimeType'=>false ], ['importer_id', 'integer','max' => 999999, 'min' => 0 ], [['action','delete_prefix', 'delete_price', 'success'], 'boolean', 'except' => 'auto' ], // только для ручной загрузки ['delimiter', 'string', 'max' => 1], [['mode','record_id'], 'safe'], ['delimiter', 'default', 'value' => ';'], [ 'success', 'default', 'value' => false] ]; } public function attributeLabels() { return [ 'file' => Yii::t('app', 'Источник'), 'importer_id' => Yii::t('app', 'Поставщик'), 'delimiter' => Yii::t('app', 'Разделитель'), ]; } public function readFile( $options = [] ){ $data = Yii::$app->multiparser->parse( $this->file_path, $options ); if( !is_array( $data ) || count($data) == 0 ){ throw new ErrorException("Ошибка чтения из файла прайса {$this->file_path}"); } // файл больше не нужен - данные прочитаны и сохранены в кеш if( file_exists($this->file_path) ) //@ todo - перестало работать - нет доступа на удалениев этом сеансе, в следующем - файл удаляется - разобраться //unlink( $this->file_path ); return $data; } public function fields() { return [ 'importer_id', 'delimiter', 'delete_price', 'delete_prefix', 'file_path', // id записи таблицы ImportersFiles, // 'id' => 'record_id', ]; } }