Commit 8458d742441b29dd80d0e0a0543b358790e626af
Merge remote-tracking branch 'origin/master'
Showing
2 changed files
with
41 additions
and
29 deletions
Show diff stats
frontend/controllers/CabinetController.php
@@ -82,7 +82,7 @@ | @@ -82,7 +82,7 @@ | ||
82 | ); | 82 | ); |
83 | } | 83 | } |
84 | 84 | ||
85 | - public function actionSales($id = NULL) | 85 | + public function actionSales($id = null) |
86 | { | 86 | { |
87 | $newRecord = false; | 87 | $newRecord = false; |
88 | if ($id) { | 88 | if ($id) { |
@@ -132,13 +132,19 @@ | @@ -132,13 +132,19 @@ | ||
132 | 132 | ||
133 | public function actionList() | 133 | public function actionList() |
134 | { | 134 | { |
135 | - $table = IntellectualProperty::find() | ||
136 | - ->where( | ||
137 | - [ | ||
138 | - 'user_id' => \Yii::$app->user->id, | ||
139 | - ] | ||
140 | - ) | ||
141 | - ->all(); | 135 | + /** |
136 | + * @var User $user | ||
137 | + */ | ||
138 | + $user = \Yii::$app->user->identity; | ||
139 | + $tableQuery = IntellectualProperty::find(); | ||
140 | + if (!$user->isAdmin()) { | ||
141 | + $tableQuery->where( | ||
142 | + [ | ||
143 | + 'user_id' => \Yii::$app->user->id, | ||
144 | + ] | ||
145 | + ); | ||
146 | + } | ||
147 | + $table = $tableQuery->all(); | ||
142 | return $this->render( | 148 | return $this->render( |
143 | 'list', | 149 | 'list', |
144 | [ | 150 | [ |
@@ -155,13 +161,13 @@ | @@ -155,13 +161,13 @@ | ||
155 | $user = \Yii::$app->user->identity; | 161 | $user = \Yii::$app->user->identity; |
156 | if ($user->isAdmin()) { | 162 | if ($user->isAdmin()) { |
157 | $reports = Report::find() | 163 | $reports = Report::find() |
158 | - ->with('intellectualProperty') | ||
159 | - ->all(); | 164 | + ->with('intellectualProperty') |
165 | + ->all(); | ||
160 | } else { | 166 | } else { |
161 | $reports = Report::find() | 167 | $reports = Report::find() |
162 | - ->joinWith('intellectualProperty.creativeRoles') | ||
163 | - ->where([ 'creative_role.user_id' => $user->id ]) | ||
164 | - ->all(); | 168 | + ->joinWith('intellectualProperty.creativeRoles') |
169 | + ->where([ 'creative_role.user_id' => $user->id ]) | ||
170 | + ->all(); | ||
165 | } | 171 | } |
166 | return $this->render( | 172 | return $this->render( |
167 | 'arrivals', | 173 | 'arrivals', |
@@ -179,13 +185,13 @@ | @@ -179,13 +185,13 @@ | ||
179 | $user = \Yii::$app->user->identity; | 185 | $user = \Yii::$app->user->identity; |
180 | if ($user->isAdmin()) { | 186 | if ($user->isAdmin()) { |
181 | $table = Report::find() | 187 | $table = Report::find() |
182 | - ->with('intellectualProperty') | ||
183 | - ->all(); | 188 | + ->with('intellectualProperty') |
189 | + ->all(); | ||
184 | } else { | 190 | } else { |
185 | $table = Report::find() | 191 | $table = Report::find() |
186 | - ->joinWith('intellectualProperty.creativeRoles') | ||
187 | - ->where([ 'creative_role.user_id' => $user->id ]) | ||
188 | - ->all(); | 192 | + ->joinWith('intellectualProperty.creativeRoles') |
193 | + ->where([ 'creative_role.user_id' => $user->id ]) | ||
194 | + ->all(); | ||
189 | } | 195 | } |
190 | return $this->render( | 196 | return $this->render( |
191 | 'notifications', | 197 | 'notifications', |
@@ -323,7 +329,7 @@ | @@ -323,7 +329,7 @@ | ||
323 | $response = \Yii::$app->response; | 329 | $response = \Yii::$app->response; |
324 | $response->format = $response::FORMAT_JSON; | 330 | $response->format = $response::FORMAT_JSON; |
325 | 331 | ||
326 | - if (!empty($request->post('id'))) { | 332 | + if (!empty( $request->post('id') )) { |
327 | $role = IntellectualProperty::findOne($request->post('id')); | 333 | $role = IntellectualProperty::findOne($request->post('id')); |
328 | if ($role->delete()) { | 334 | if ($role->delete()) { |
329 | return [ | 335 | return [ |
@@ -405,7 +411,7 @@ | @@ -405,7 +411,7 @@ | ||
405 | $response = \Yii::$app->response; | 411 | $response = \Yii::$app->response; |
406 | $response->format = $response::FORMAT_JSON; | 412 | $response->format = $response::FORMAT_JSON; |
407 | 413 | ||
408 | - if (!empty($request->post('id'))) { | 414 | + if (!empty( $request->post('id') )) { |
409 | $role = CreativeRole::findOne($request->post('id')); | 415 | $role = CreativeRole::findOne($request->post('id')); |
410 | if ($role->delete()) { | 416 | if ($role->delete()) { |
411 | return [ | 417 | return [ |
@@ -428,14 +434,20 @@ | @@ -428,14 +434,20 @@ | ||
428 | 434 | ||
429 | public function findProperty($id) | 435 | public function findProperty($id) |
430 | { | 436 | { |
431 | - $model = IntellectualProperty::find() | ||
432 | - ->where( | ||
433 | - [ | ||
434 | - 'id' => $id, | ||
435 | - 'user_id' => \Yii::$app->user->id, | ||
436 | - ] | ||
437 | - ) | ||
438 | - ->one(); | 437 | + /** |
438 | + * @var User $user | ||
439 | + */ | ||
440 | + $user = \Yii::$app->user->identity; | ||
441 | + $modelQuery = IntellectualProperty::find(); | ||
442 | + if (!$user->isAdmin()) { | ||
443 | + $modelQuery->where( | ||
444 | + [ | ||
445 | + 'id' => $id, | ||
446 | + 'user_id' => \Yii::$app->user->id, | ||
447 | + ] | ||
448 | + ); | ||
449 | + } | ||
450 | + $model = $modelQuery->one(); | ||
439 | if (empty( $model )) { | 451 | if (empty( $model )) { |
440 | throw new NotFoundHttpException(); | 452 | throw new NotFoundHttpException(); |
441 | } | 453 | } |
frontend/views/cabinet/index.php
@@ -75,7 +75,7 @@ | @@ -75,7 +75,7 @@ | ||
75 | <td><?= $i; ?></td> | 75 | <td><?= $i; ?></td> |
76 | <td> | 76 | <td> |
77 | <?php | 77 | <?php |
78 | - if($row->user_id == $user->id) { | 78 | + if($user->isAdmin() || $row->user_id == $user->id) { |
79 | echo Html::a($row->title, ['sales', 'id' => $row->id]); | 79 | echo Html::a($row->title, ['sales', 'id' => $row->id]); |
80 | } else { | 80 | } else { |
81 | echo $row->title; | 81 | echo $row->title; |