コード例 #1
0
 /**
  * After insert event.
  */
 public function afterInsert()
 {
     foreach ($this->attributes as $attribute => $storageConfig) {
         if ($this->_files[$attribute] instanceof UploadedFile) {
             if ($filePath = $this->saveFile($this->_files[$attribute], $storageConfig)) {
                 $this->owner->updateAttributes([$attribute => pathinfo($filePath, PATHINFO_BASENAME)]);
             }
         } elseif (is_array($this->_files[$attribute]) && !empty($this->_files[$attribute])) {
             $paths = $this->saveFiles((array) $this->_files[$attribute], $storageConfig);
             if ($paths) {
                 foreach ($paths as $key => $path) {
                     $paths[$key] = pathinfo($path, PATHINFO_BASENAME);
                 }
                 $this->owner->updateAttributes([$attribute => json_encode($paths)]);
             }
         }
     }
 }
コード例 #2
0
 /**
  * @param integer $fileId
  * @return int
  * @throws Exception
  */
 protected function updateOwner($fileId)
 {
     $this->owner->updateAttributes([$this->attribute => $fileId]);
     $sql = "\n            UPDATE " . $this->owner->tableName() . "\n            SET " . $this->attribute . " = :file\n            WHERE id = :id\n        ";
     return Yii::$app->db->createCommand($sql)->bindValue(':file', $fileId)->bindValue(':id', $this->owner->primaryKey)->execute();
 }
コード例 #3
0
 /**
  * Updates attributes for the given model.
  *
  * @param ActiveRecord $model model instance.
  * @param array $attributes model attributes.
  * @return boolean the result.
  */
 protected function updateAttributesInternal(ActiveRecord $model, array $attributes)
 {
     return $model->updateAttributes($attributes) !== 0;
 }