Example #1
0
 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;
 }
Example #2
0
 /**
  * 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.');
     }
 }
Example #3
0
 public function getFolder($path)
 {
     $folder = $this->entity($path);
     if ($path == '/') {
         $items = $this->getRootItems();
     } else {
         $q = Entity::find()->where(['parentid' => $folder->id]);
         if (!\Yii::$app->getUser()->can('medialib.admin')) {
             $q->andWhere(['ownerid' => [\Yii::$app->user->id, 0]]);
         }
         $items = $q->indexBy('path')->all();
     }
     $res = [];
     foreach ($items as $item) {
         if ($item->isfolder) {
             $filetype = 'dir';
             if ($item->type == 'folder') {
                 $preview = $this->_assets . '/images/fileicons/folder.png';
             } else {
                 $preview = $this->_assets . '/images/fileicons/folder-' . $item->type . '.png';
             }
         } else {
             $filetype = isset($this->aviableFileTypes[$item->mimetype]) ? $this->aviableFileTypes[$item->mimetype] : 'file';
             $preview = $item->entity->preview;
             if (!$preview) {
                 $preview = '%/images/fileicons/' . $filetype . '.png';
             }
             $preview = strtr($preview, ['%' => $this->_assets]);
         }
         //$item->isfolder?'dir': (isset($this->aviableFileTypes[$item->mimetype]) ? $this->aviableFileTypes[$item->mimetype] : 'file'),
         $r = ['Path' => '/' . $this->mediaFolder . $item->path, 'Filename' => $item->name, 'File Type' => $filetype, 'Protected' => 0, 'Preview' => $preview, 'Properties' => $item->properties, 'Error' => '', 'Code' => 0];
         $res[$item->path] = $r;
     }
     return $res;
 }