From aa22879e911355c65cdcb25daf09ea340ac2f3ff Mon Sep 17 00:00:00 2001 From: yarik Date: Fri, 30 Dec 2016 15:06:15 +0200 Subject: [PATCH] Admin --- frontend/controllers/CabinetController.php | 68 ++++++++++++++++++++++++++++++++++++++++---------------------------- frontend/views/cabinet/index.php | 2 +- 2 files changed, 41 insertions(+), 29 deletions(-) diff --git a/frontend/controllers/CabinetController.php b/frontend/controllers/CabinetController.php index 389d594..d35a5f9 100755 --- a/frontend/controllers/CabinetController.php +++ b/frontend/controllers/CabinetController.php @@ -82,7 +82,7 @@ ); } - public function actionSales($id = NULL) + public function actionSales($id = null) { $newRecord = false; if ($id) { @@ -132,13 +132,19 @@ public function actionList() { - $table = IntellectualProperty::find() - ->where( - [ - 'user_id' => \Yii::$app->user->id, - ] - ) - ->all(); + /** + * @var User $user + */ + $user = \Yii::$app->user->identity; + $tableQuery = IntellectualProperty::find(); + if (!$user->isAdmin()) { + $tableQuery->where( + [ + 'user_id' => \Yii::$app->user->id, + ] + ); + } + $table = $tableQuery->all(); return $this->render( 'list', [ @@ -155,13 +161,13 @@ $user = \Yii::$app->user->identity; if ($user->isAdmin()) { $reports = Report::find() - ->with('intellectualProperty') - ->all(); + ->with('intellectualProperty') + ->all(); } else { $reports = Report::find() - ->joinWith('intellectualProperty.creativeRoles') - ->where([ 'creative_role.user_id' => $user->id ]) - ->all(); + ->joinWith('intellectualProperty.creativeRoles') + ->where([ 'creative_role.user_id' => $user->id ]) + ->all(); } return $this->render( 'arrivals', @@ -179,13 +185,13 @@ $user = \Yii::$app->user->identity; if ($user->isAdmin()) { $table = Report::find() - ->with('intellectualProperty') - ->all(); + ->with('intellectualProperty') + ->all(); } else { $table = Report::find() - ->joinWith('intellectualProperty.creativeRoles') - ->where([ 'creative_role.user_id' => $user->id ]) - ->all(); + ->joinWith('intellectualProperty.creativeRoles') + ->where([ 'creative_role.user_id' => $user->id ]) + ->all(); } return $this->render( 'notifications', @@ -323,7 +329,7 @@ $response = \Yii::$app->response; $response->format = $response::FORMAT_JSON; - if (!empty($request->post('id'))) { + if (!empty( $request->post('id') )) { $role = IntellectualProperty::findOne($request->post('id')); if ($role->delete()) { return [ @@ -405,7 +411,7 @@ $response = \Yii::$app->response; $response->format = $response::FORMAT_JSON; - if (!empty($request->post('id'))) { + if (!empty( $request->post('id') )) { $role = CreativeRole::findOne($request->post('id')); if ($role->delete()) { return [ @@ -428,14 +434,20 @@ public function findProperty($id) { - $model = IntellectualProperty::find() - ->where( - [ - 'id' => $id, - 'user_id' => \Yii::$app->user->id, - ] - ) - ->one(); + /** + * @var User $user + */ + $user = \Yii::$app->user->identity; + $modelQuery = IntellectualProperty::find(); + if (!$user->isAdmin()) { + $modelQuery->where( + [ + 'id' => $id, + 'user_id' => \Yii::$app->user->id, + ] + ); + } + $model = $modelQuery->one(); if (empty( $model )) { throw new NotFoundHttpException(); } diff --git a/frontend/views/cabinet/index.php b/frontend/views/cabinet/index.php index 0bbe0d7..0dbcf75 100755 --- a/frontend/views/cabinet/index.php +++ b/frontend/views/cabinet/index.php @@ -75,7 +75,7 @@ user_id == $user->id) { + if($user->isAdmin() || $row->user_id == $user->id) { echo Html::a($row->title, ['sales', 'id' => $row->id]); } else { echo $row->title; -- libgit2 0.21.4