Esempio n. 1
0
 /**
  * Finds the File model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return File the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = File::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Esempio n. 2
0
 public function assignFileToRecord($fileId, $recordId, $record_video_type)
 {
     $file = File::findOne($fileId);
     if (!$file) {
         throw new HttpException(500, 'No file found');
     }
     $file->record_id = $recordId;
     $file->record_file_type = $record_video_type;
     return $file->save(false);
 }
 public function actionFile($id)
 {
     $model = File::findOne(['id' => $id]);
     if ($model === NULL) {
         throw new HttpException(403, 'You are not allowed to perform this action.');
     }
     if (file_exists($model->filepath)) {
         //Check to see if the user has permissions
         $ffgs = FileFileGroup::find()->where(['file_id' => $id])->all();
         $ffgs_list = [];
         $found = 0;
         foreach ($ffgs as $f) {
             $ufg = UserFileGroup::find()->where(['file_group_id' => $f->group_id, 'user_id' => \Yii::$app->user->identity->id]);
             if ($ufg !== NULL) {
                 $found = 1;
                 break;
             }
         }
         if ($found == 1) {
             $user = User::findOne(['id' => \Yii::$app->user->identity->id]);
             $dl = new DownloadLog();
             $dl->username = $user->username;
             $dl->email = $user->email;
             $dl->filepath = $model->filepath;
             $dl->download_time = date("Y-m-d H:i:s");
             $dl->filename = $model->filename;
             $dl->user_id = $user->id;
             $dl->save();
             return \Yii::$app->response->sendFile($model->filepath);
         } else {
             throw new HttpException(403, 'You are not allowed to perform this action.');
         }
     } else {
         return $this->redirect(['/site/error']);
     }
 }
Esempio n. 4
0
 protected function findModel($id)
 {
     if (($model = File::findOne($id)) !== null) {
         if ($model->user_id != Yii::$app->user->id) {
             throw new \yii\web\ForbiddenHttpException();
         }
         return $model;
     } else {
         throw new \yii\web\NotFoundHttpException('The requested page does not exist.');
     }
 }
 /**
  * Permissions to files from roles
  */
 public function actionPermission($id)
 {
     if (!Yii::$app->user->can("admin")) {
         throw new HttpException(403, 'You are not allowed to perform this action.');
     }
     $file = File::findOne($id);
     $fg = FileGroup::find()->where(['is_deleted' => 0])->all();
     $sufg = FileFileGroup::find()->where(['file_id' => $id])->all();
     if (Yii::$app->request->post()) {
         $post = Yii::$app->request->post();
         FileFileGroup::deleteAll(['file_id' => $id]);
         if (isset($post['Post']['permission'])) {
             foreach ($post['Post']['permission'] as $perm) {
                 $ffg = new FileFileGroup();
                 $ffg->group_id = $perm;
                 $ffg->file_id = $id;
                 $ffg->save();
             }
         }
         return $this->redirect(['file/view', 'id' => $id]);
     } else {
         return $this->render('permission', ['filemodel' => $file, 'filegroups' => $fg, 'selectedfg' => $sufg]);
     }
 }