コード例 #1
0
 /**
  * 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]);
     }
 }
コード例 #2
0
 /**
  * Deletes an existing File model.
  * If deletion is successful, the browser will be redirected to the 'index' page.
  * @param integer $id
  * @return mixed
  */
 public function actionDelete($id)
 {
     if (!Yii::$app->user->can("admin")) {
         throw new HttpException(403, 'You are not allowed to perform this action.');
     }
     FileFileGroup::deleteAll(['file_id' => $id]);
     $this->findModel($id)->delete();
     return $this->redirect(['index']);
 }