Commit 3ebbbaa9a6142eab82c48a1191f5c40e4ddadefd
1 parent
0687eb9b
-Reports
Showing
2 changed files
with
52 additions
and
34 deletions
Show diff stats
frontend/controllers/CabinetController.php
| @@ -26,7 +26,7 @@ | @@ -26,7 +26,7 @@ | ||
| 26 | public function behaviors() | 26 | public function behaviors() |
| 27 | { | 27 | { |
| 28 | return [ | 28 | return [ |
| 29 | - 'verbs' => [ | 29 | + 'verbs' => [ |
| 30 | 'class' => VerbFilter::className(), | 30 | 'class' => VerbFilter::className(), |
| 31 | 'actions' => [ | 31 | 'actions' => [ |
| 32 | 'personal' => [ 'post' ], | 32 | 'personal' => [ 'post' ], |
| @@ -38,7 +38,7 @@ | @@ -38,7 +38,7 @@ | ||
| 38 | 'rules' => [ | 38 | 'rules' => [ |
| 39 | [ | 39 | [ |
| 40 | 'allow' => true, | 40 | 'allow' => true, |
| 41 | - 'roles' => ['@'], | 41 | + 'roles' => [ '@' ], |
| 42 | ], | 42 | ], |
| 43 | ], | 43 | ], |
| 44 | ], | 44 | ], |
| @@ -63,12 +63,11 @@ | @@ -63,12 +63,11 @@ | ||
| 63 | $userPassport = new UserPassport(); | 63 | $userPassport = new UserPassport(); |
| 64 | } | 64 | } |
| 65 | 65 | ||
| 66 | - $table = IntellectualProperty::find() | ||
| 67 | -// ->where( | ||
| 68 | -// [ | ||
| 69 | -// 'user_id' => \Yii::$app->user->identity->id, | ||
| 70 | -// ] | ||
| 71 | -// ) | 66 | + $table = IntellectualProperty::find()// ->where( |
| 67 | + // [ | ||
| 68 | + // 'user_id' => \Yii::$app->user->identity->id, | ||
| 69 | + // ] | ||
| 70 | + // ) | ||
| 72 | ->all(); | 71 | ->all(); |
| 73 | 72 | ||
| 74 | return $this->render( | 73 | return $this->render( |
| @@ -81,7 +80,7 @@ | @@ -81,7 +80,7 @@ | ||
| 81 | ); | 80 | ); |
| 82 | } | 81 | } |
| 83 | 82 | ||
| 84 | - public function actionSales($id = null) | 83 | + public function actionSales($id = NULL) |
| 85 | { | 84 | { |
| 86 | $newRecord = false; | 85 | $newRecord = false; |
| 87 | if ($id) { | 86 | if ($id) { |
| @@ -127,12 +126,11 @@ | @@ -127,12 +126,11 @@ | ||
| 127 | 126 | ||
| 128 | public function actionList() | 127 | public function actionList() |
| 129 | { | 128 | { |
| 130 | - $table = IntellectualProperty::find() | ||
| 131 | -// ->where( | ||
| 132 | -// [ | ||
| 133 | -// 'user_id' => \Yii::$app->user->identity->id, | ||
| 134 | -// ] | ||
| 135 | -// ) | 129 | + $table = IntellectualProperty::find()// ->where( |
| 130 | + // [ | ||
| 131 | + // 'user_id' => \Yii::$app->user->identity->id, | ||
| 132 | + // ] | ||
| 133 | + // ) | ||
| 136 | ->all(); | 134 | ->all(); |
| 137 | return $this->render( | 135 | return $this->render( |
| 138 | 'list', | 136 | 'list', |
| @@ -157,17 +155,33 @@ | @@ -157,17 +155,33 @@ | ||
| 157 | 155 | ||
| 158 | public function actionNotifications() | 156 | public function actionNotifications() |
| 159 | { | 157 | { |
| 160 | - $table = Report::find()->all(); | ||
| 161 | - return $this->render('notifications', [ | ||
| 162 | - 'table' => $table, | ||
| 163 | - ]); | 158 | + $table = Report::find() |
| 159 | + ->all(); | ||
| 160 | + return $this->render( | ||
| 161 | + 'notifications', | ||
| 162 | + [ | ||
| 163 | + 'table' => $table, | ||
| 164 | + ] | ||
| 165 | + ); | ||
| 164 | } | 166 | } |
| 165 | 167 | ||
| 166 | public function actionUsers() | 168 | public function actionUsers() |
| 167 | { | 169 | { |
| 168 | - $reports = Report::find() | ||
| 169 | - ->with('intellectualProperty') | ||
| 170 | - ->all(); | 170 | + /** |
| 171 | + * @var User $user | ||
| 172 | + */ | ||
| 173 | + $user = \Yii::$app->user->identity; | ||
| 174 | + if ($user->isAdmin()) { | ||
| 175 | + $reports = Report::find() | ||
| 176 | + ->with('intellectualProperty') | ||
| 177 | + ->all(); | ||
| 178 | + } else { | ||
| 179 | + $reports = Report::find() | ||
| 180 | + ->joinWith('intellectualProperty.creativeRoles') | ||
| 181 | + ->where([ 'creative_role.user_id' => $user->id ]) | ||
| 182 | + ->all(); | ||
| 183 | + } | ||
| 184 | + | ||
| 171 | return $this->render( | 185 | return $this->render( |
| 172 | 'users', | 186 | 'users', |
| 173 | [ | 187 | [ |
| @@ -279,7 +293,7 @@ | @@ -279,7 +293,7 @@ | ||
| 279 | $response = \Yii::$app->response; | 293 | $response = \Yii::$app->response; |
| 280 | $response->format = $response::FORMAT_JSON; | 294 | $response->format = $response::FORMAT_JSON; |
| 281 | 295 | ||
| 282 | - if (!empty( $request->post('id') )) { | 296 | + if (!empty($request->post('id'))) { |
| 283 | $role = IntellectualProperty::findOne($request->post('id')); | 297 | $role = IntellectualProperty::findOne($request->post('id')); |
| 284 | if ($role->delete()) { | 298 | if ($role->delete()) { |
| 285 | return [ | 299 | return [ |
| @@ -320,15 +334,15 @@ | @@ -320,15 +334,15 @@ | ||
| 320 | ]; | 334 | ]; |
| 321 | } | 335 | } |
| 322 | } | 336 | } |
| 323 | - | 337 | + |
| 324 | public function actionUpdateRole() | 338 | public function actionUpdateRole() |
| 325 | { | 339 | { |
| 326 | $request = \Yii::$app->request; | 340 | $request = \Yii::$app->request; |
| 327 | $response = \Yii::$app->response; | 341 | $response = \Yii::$app->response; |
| 328 | $response->format = $response::FORMAT_JSON; | 342 | $response->format = $response::FORMAT_JSON; |
| 329 | - | 343 | + |
| 330 | $role = CreativeRole::findOne($request->get('id')); | 344 | $role = CreativeRole::findOne($request->get('id')); |
| 331 | - | 345 | + |
| 332 | if ($role->load($request->post()) && $role->save()) { | 346 | if ($role->load($request->post()) && $role->save()) { |
| 333 | return [ | 347 | return [ |
| 334 | 'success' => true, | 348 | 'success' => true, |
| @@ -341,17 +355,17 @@ | @@ -341,17 +355,17 @@ | ||
| 341 | ]; | 355 | ]; |
| 342 | } | 356 | } |
| 343 | } | 357 | } |
| 344 | - | 358 | + |
| 345 | public function actionGetRoleForm() | 359 | public function actionGetRoleForm() |
| 346 | { | 360 | { |
| 347 | $request = \Yii::$app->request; | 361 | $request = \Yii::$app->request; |
| 348 | $response = \Yii::$app->response; | 362 | $response = \Yii::$app->response; |
| 349 | $response->format = $response::FORMAT_JSON; | 363 | $response->format = $response::FORMAT_JSON; |
| 350 | - | 364 | + |
| 351 | $model = CreativeRole::findOne($request->post('id')); | 365 | $model = CreativeRole::findOne($request->post('id')); |
| 352 | 366 | ||
| 353 | return [ | 367 | return [ |
| 354 | - 'answer' => $this->renderPartial('_update_form', ['model' => $model]) | 368 | + 'answer' => $this->renderPartial('_update_form', [ 'model' => $model ]), |
| 355 | ]; | 369 | ]; |
| 356 | } | 370 | } |
| 357 | 371 | ||
| @@ -361,7 +375,7 @@ | @@ -361,7 +375,7 @@ | ||
| 361 | $response = \Yii::$app->response; | 375 | $response = \Yii::$app->response; |
| 362 | $response->format = $response::FORMAT_JSON; | 376 | $response->format = $response::FORMAT_JSON; |
| 363 | 377 | ||
| 364 | - if (!empty( $request->post('id') )) { | 378 | + if (!empty($request->post('id'))) { |
| 365 | $role = CreativeRole::findOne($request->post('id')); | 379 | $role = CreativeRole::findOne($request->post('id')); |
| 366 | if ($role->delete()) { | 380 | if ($role->delete()) { |
| 367 | return [ | 381 | return [ |
| @@ -385,7 +399,7 @@ | @@ -385,7 +399,7 @@ | ||
| 385 | public function findProperty($id) | 399 | public function findProperty($id) |
| 386 | { | 400 | { |
| 387 | $model = IntellectualProperty::findOne($id); | 401 | $model = IntellectualProperty::findOne($id); |
| 388 | - if (empty( $model )) { | 402 | + if (empty($model)) { |
| 389 | throw new NotFoundHttpException(); | 403 | throw new NotFoundHttpException(); |
| 390 | } | 404 | } |
| 391 | return $model; | 405 | return $model; |
frontend/views/cabinet/users.php
| 1 | <?php | 1 | <?php |
| 2 | + use common\models\User; | ||
| 2 | use frontend\models\IntellectualProperty; | 3 | use frontend\models\IntellectualProperty; |
| 3 | use frontend\models\Report; | 4 | use frontend\models\Report; |
| 4 | use yii\helpers\Html; | 5 | use yii\helpers\Html; |
| @@ -9,14 +10,17 @@ | @@ -9,14 +10,17 @@ | ||
| 9 | /** | 10 | /** |
| 10 | * @var View $this | 11 | * @var View $this |
| 11 | * @var Report[] $reports | 12 | * @var Report[] $reports |
| 13 | + * @var User $user | ||
| 12 | */ | 14 | */ |
| 15 | + | ||
| 16 | + $user = \Yii::$app->user->identity; | ||
| 13 | ?> | 17 | ?> |
| 14 | <div class="style cab_content_list"> | 18 | <div class="style cab_content_list"> |
| 15 | <div class="cab_content_list-dropdown"> | 19 | <div class="cab_content_list-dropdown"> |
| 16 | <div class="style table-forms tables-1"> | 20 | <div class="style table-forms tables-1"> |
| 17 | <div class="title_forms">Звіт про загальну суму винагороди (у розрізі користувачів)</div> | 21 | <div class="title_forms">Звіт про загальну суму винагороди (у розрізі користувачів)</div> |
| 18 | <div class="btn-submit-blue"> | 22 | <div class="btn-submit-blue"> |
| 19 | - <?php echo Html::button( | 23 | + <?php if ($user->isAdmin()) echo Html::button( |
| 20 | 'Добавить', | 24 | 'Добавить', |
| 21 | [ | 25 | [ |
| 22 | 'type' => 'button', | 26 | 'type' => 'button', |
| @@ -56,7 +60,7 @@ | @@ -56,7 +60,7 @@ | ||
| 56 | <?php | 60 | <?php |
| 57 | echo Html::tag('td', ++$index); | 61 | echo Html::tag('td', ++$index); |
| 58 | echo Html::tag('td', $report->user); | 62 | echo Html::tag('td', $report->user); |
| 59 | - echo Html::tag('td', $report->artist); | 63 | + echo Html::tag('td', ''); |
| 60 | echo Html::tag('td', $report->intellectualProperty->title); | 64 | echo Html::tag('td', $report->intellectualProperty->title); |
| 61 | echo Html::tag('td', $report->count); | 65 | echo Html::tag('td', $report->count); |
| 62 | echo Html::tag('td', $report->sum); | 66 | echo Html::tag('td', $report->sum); |
| @@ -98,7 +102,7 @@ | @@ -98,7 +102,7 @@ | ||
| 98 | <?php | 102 | <?php |
| 99 | echo $form->field($report, 'user') | 103 | echo $form->field($report, 'user') |
| 100 | ->textInput(); | 104 | ->textInput(); |
| 101 | - echo $form->field($report, 'artist'); | 105 | +// echo $form->field($report, 'artist'); |
| 102 | echo $form->field($report, 'intellectual_property_id') | 106 | echo $form->field($report, 'intellectual_property_id') |
| 103 | ->dropDownList( | 107 | ->dropDownList( |
| 104 | IntellectualProperty::find() | 108 | IntellectualProperty::find() |