public function actionGet($path) { $entity = Entity::findOne(['path' => '/' . $path]); if (!$entity) { throw new NotFoundHttpException(\Yii::t('yii', 'Page not found.')); } $storage = $this->module->getStorage($entity->entity->storage); if (!$storage) { throw new InvalidConfigException("Medialib storage \"{$entity->entity->storage}\" not found"); } $url = strtr($storage[0], ['{path}' => $entity->entity->path, '{host}' => Yii::$app->request->serverName]); return $this->redirect($url); }
public function actionIndex($path) { $entity = Entity::findOne(['path' => '/' . $path]); if (!$entity) { throw new NotFoundHttpException(\Yii::t('yii', 'Page not found.')); } $storage = $this->module->getStorage($entity->entity->storage); if (!$storage) { throw new InvalidConfigException("Medialib storage \"{$entity->entity->storage}\" not found"); } $version = $_SERVER['QUERY_STRING'] ? $_SERVER['QUERY_STRING'] : 'origin'; $url = $this->module->getStorage($entity->entity->storage)->genUrl($entity->entity->hash, $version); return $this->redirect($url); }
public function actionDownload($path) { if ($path !== '/') { $item = Entity::find()->where(['path' => $path])->one(); } else { $item = new Entity(['id' => 0, 'ownerid' => \Yii::$app->user->id, 'entityid' => 0, 'type' => 'folder', 'isfolder' => 1, 'path' => '/', 'name' => 'root']); } if (!$item) { die("not found"); } //var_dump(Url::toRoute(['/medialib/direct', 'storage' => $item->entity->storage, 'fn'=>$item->entity->path])); return $this->redirect(['/medialib/direct', 'storage' => $item->entity->storage, 'fn' => $item->entity->path]); die; return $folder; }
/** * Finds the Entity model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Entity the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Entity::find()->where(['id' => $id])->one()) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function getFiles() { return $this->hasMany(Entity::className(), ['parentid' => 'id'])->orderBy(['isfolder' => SORT_DESC, 'name' => SORT_ASC]); }
public function add($file, $path) { // var_dump($file);die(); $folder = $this->entity($path); $new = new Entity(['ownerid' => \Yii::$app->user->id, 'type' => $file->type, 'name' => $file->name, 'parentid' => $folder->id, 'entityid' => $file->id, 'path' => $folder->path . $file->name, 'size' => $file->size, 'sizefull' => $file->sizefull, 'mimetype' => $file->mimetype]); $i = 0; while ($this->entity($new->path)) { $i++; $new->path = $folder->path . $file->name . '_' . $i; } if ($i) { $new->name .= '_' . $i; } if (!$new->save()) { var_dump($new->errors); } return ['Path' => $folder->path, 'Name' => $new->name, 'Error' => '', 'Code' => 0]; }