Esempio n. 1
0
 /**
  * @inheritdoc
  * @throws InvalidConfigException
  */
 public function init()
 {
     parent::init();
     if (!$this->hasModel()) {
         throw new InvalidConfigException('Params $model and $attribute are required for ' . get_class($this) . '.');
     }
     $model = $this->model;
     $file = Html::getAttributeValue($model, $this->attribute);
     if (!$file instanceof File) {
         throw new InvalidConfigException("Attribute {$this->attribute} of " . get_class($model) . ' must be an instance of ' . File::className() . ' for usage in ' . get_class($this) . '.');
     }
 }
Esempio n. 2
0
 /**
  * Converts File object to array for returning in json responses.
  * @param \flexibuild\file\File $file the file object.
  * @param boolean $scheme scheme value that will be used for getting file urls.
  * @return array array of file data that will be return in response.
  */
 public static function convertFileToArray($file, $scheme = false)
 {
     $formats = [];
     foreach ($file->getFormatList() as $format) {
         $formats[$format] = $file->getUrl($format, $scheme);
     }
     $result = ['value' => $file->getData(), 'url' => $file->getUrl(null, $scheme), 'formats' => $formats, 'name' => $file->getName(), 'size' => $file->getSize(), 'ext' => $file->getExtension(), 'type' => $file->getType()];
     return $result;
 }
Esempio n. 3
0
 /**
  * @inheritdoc
  * @throws InvalidConfigException
  */
 public function init()
 {
     parent::init();
     if (!$this->hasModel()) {
         throw new InvalidConfigException('Params $model and $attribute are required for ' . get_class($this) . '.');
     }
     $model = $this->model;
     $file = Html::getAttributeValue($model, $this->attribute);
     if (!$file instanceof File) {
         throw new InvalidConfigException("Attribute {$this->attribute} of " . get_class($model) . ' must be an instance of ' . File::className() . ' for usage in ' . get_class($this) . '.');
     }
     if (!isset($this->fileInputOptions['id'])) {
         $this->fileInputOptions['id'] = $this->options['id'] . static::ID_FILE_INPUT_SUFFIX;
     }
     if (!isset($this->hiddenInputOptions['id'])) {
         $this->hiddenInputOptions['id'] = $this->options['id'] . static::ID_HIDDEN_INPUT_SUFFIX;
     }
     if (!isset($this->previewContainerOptions['id'])) {
         $this->previewContainerOptions['id'] = $this->options['id'] . static::ID_PREVIEW_CONTAINER_SUFFIX;
     }
     $this->initClientOptions();
 }