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 | 26 | public function behaviors() |
27 | 27 | { |
28 | 28 | return [ |
29 | - 'verbs' => [ | |
29 | + 'verbs' => [ | |
30 | 30 | 'class' => VerbFilter::className(), |
31 | 31 | 'actions' => [ |
32 | 32 | 'personal' => [ 'post' ], |
... | ... | @@ -38,7 +38,7 @@ |
38 | 38 | 'rules' => [ |
39 | 39 | [ |
40 | 40 | 'allow' => true, |
41 | - 'roles' => ['@'], | |
41 | + 'roles' => [ '@' ], | |
42 | 42 | ], |
43 | 43 | ], |
44 | 44 | ], |
... | ... | @@ -63,12 +63,11 @@ |
63 | 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 | 71 | ->all(); |
73 | 72 | |
74 | 73 | return $this->render( |
... | ... | @@ -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 | 85 | $newRecord = false; |
87 | 86 | if ($id) { |
... | ... | @@ -127,12 +126,11 @@ |
127 | 126 | |
128 | 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 | 134 | ->all(); |
137 | 135 | return $this->render( |
138 | 136 | 'list', |
... | ... | @@ -157,17 +155,33 @@ |
157 | 155 | |
158 | 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 | 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 | 185 | return $this->render( |
172 | 186 | 'users', |
173 | 187 | [ |
... | ... | @@ -279,7 +293,7 @@ |
279 | 293 | $response = \Yii::$app->response; |
280 | 294 | $response->format = $response::FORMAT_JSON; |
281 | 295 | |
282 | - if (!empty( $request->post('id') )) { | |
296 | + if (!empty($request->post('id'))) { | |
283 | 297 | $role = IntellectualProperty::findOne($request->post('id')); |
284 | 298 | if ($role->delete()) { |
285 | 299 | return [ |
... | ... | @@ -320,15 +334,15 @@ |
320 | 334 | ]; |
321 | 335 | } |
322 | 336 | } |
323 | - | |
337 | + | |
324 | 338 | public function actionUpdateRole() |
325 | 339 | { |
326 | 340 | $request = \Yii::$app->request; |
327 | 341 | $response = \Yii::$app->response; |
328 | 342 | $response->format = $response::FORMAT_JSON; |
329 | - | |
343 | + | |
330 | 344 | $role = CreativeRole::findOne($request->get('id')); |
331 | - | |
345 | + | |
332 | 346 | if ($role->load($request->post()) && $role->save()) { |
333 | 347 | return [ |
334 | 348 | 'success' => true, |
... | ... | @@ -341,17 +355,17 @@ |
341 | 355 | ]; |
342 | 356 | } |
343 | 357 | } |
344 | - | |
358 | + | |
345 | 359 | public function actionGetRoleForm() |
346 | 360 | { |
347 | 361 | $request = \Yii::$app->request; |
348 | 362 | $response = \Yii::$app->response; |
349 | 363 | $response->format = $response::FORMAT_JSON; |
350 | - | |
364 | + | |
351 | 365 | $model = CreativeRole::findOne($request->post('id')); |
352 | 366 | |
353 | 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 | 375 | $response = \Yii::$app->response; |
362 | 376 | $response->format = $response::FORMAT_JSON; |
363 | 377 | |
364 | - if (!empty( $request->post('id') )) { | |
378 | + if (!empty($request->post('id'))) { | |
365 | 379 | $role = CreativeRole::findOne($request->post('id')); |
366 | 380 | if ($role->delete()) { |
367 | 381 | return [ |
... | ... | @@ -385,7 +399,7 @@ |
385 | 399 | public function findProperty($id) |
386 | 400 | { |
387 | 401 | $model = IntellectualProperty::findOne($id); |
388 | - if (empty( $model )) { | |
402 | + if (empty($model)) { | |
389 | 403 | throw new NotFoundHttpException(); |
390 | 404 | } |
391 | 405 | return $model; | ... | ... |
frontend/views/cabinet/users.php
1 | 1 | <?php |
2 | + use common\models\User; | |
2 | 3 | use frontend\models\IntellectualProperty; |
3 | 4 | use frontend\models\Report; |
4 | 5 | use yii\helpers\Html; |
... | ... | @@ -9,14 +10,17 @@ |
9 | 10 | /** |
10 | 11 | * @var View $this |
11 | 12 | * @var Report[] $reports |
13 | + * @var User $user | |
12 | 14 | */ |
15 | + | |
16 | + $user = \Yii::$app->user->identity; | |
13 | 17 | ?> |
14 | 18 | <div class="style cab_content_list"> |
15 | 19 | <div class="cab_content_list-dropdown"> |
16 | 20 | <div class="style table-forms tables-1"> |
17 | 21 | <div class="title_forms">Звіт про загальну суму винагороди (у розрізі користувачів)</div> |
18 | 22 | <div class="btn-submit-blue"> |
19 | - <?php echo Html::button( | |
23 | + <?php if ($user->isAdmin()) echo Html::button( | |
20 | 24 | 'Добавить', |
21 | 25 | [ |
22 | 26 | 'type' => 'button', |
... | ... | @@ -56,7 +60,7 @@ |
56 | 60 | <?php |
57 | 61 | echo Html::tag('td', ++$index); |
58 | 62 | echo Html::tag('td', $report->user); |
59 | - echo Html::tag('td', $report->artist); | |
63 | + echo Html::tag('td', ''); | |
60 | 64 | echo Html::tag('td', $report->intellectualProperty->title); |
61 | 65 | echo Html::tag('td', $report->count); |
62 | 66 | echo Html::tag('td', $report->sum); |
... | ... | @@ -98,7 +102,7 @@ |
98 | 102 | <?php |
99 | 103 | echo $form->field($report, 'user') |
100 | 104 | ->textInput(); |
101 | - echo $form->field($report, 'artist'); | |
105 | +// echo $form->field($report, 'artist'); | |
102 | 106 | echo $form->field($report, 'intellectual_property_id') |
103 | 107 | ->dropDownList( |
104 | 108 | IntellectualProperty::find() | ... | ... |