Commit 0eff1ddcdedc5d7b5fcbd16dcf51e21e56b8ba94
Merge remote-tracking branch 'origin/master'
Showing
3 changed files
with
84 additions
and
13 deletions
Show diff stats
frontend/controllers/CabinetController.php
| @@ -88,7 +88,11 @@ | @@ -88,7 +88,11 @@ | ||
| 88 | if ($id) { | 88 | if ($id) { |
| 89 | $property = $this->findProperty($id); | 89 | $property = $this->findProperty($id); |
| 90 | } else { | 90 | } else { |
| 91 | - $property = new IntellectualProperty(); | 91 | + $property = new IntellectualProperty( |
| 92 | + [ | ||
| 93 | + 'user_id' => \Yii::$app->user->id, | ||
| 94 | + ] | ||
| 95 | + ); | ||
| 92 | $newRecord = true; | 96 | $newRecord = true; |
| 93 | } | 97 | } |
| 94 | if ($property->load(\Yii::$app->request->post()) && $property->save()) { | 98 | if ($property->load(\Yii::$app->request->post()) && $property->save()) { |
| @@ -129,11 +133,11 @@ | @@ -129,11 +133,11 @@ | ||
| 129 | public function actionList() | 133 | public function actionList() |
| 130 | { | 134 | { |
| 131 | $table = IntellectualProperty::find() | 135 | $table = IntellectualProperty::find() |
| 132 | -// ->where( | ||
| 133 | -// [ | ||
| 134 | -// 'user_id' => \Yii::$app->user->identity->id, | ||
| 135 | -// ] | ||
| 136 | -// ) | 136 | + ->where( |
| 137 | + [ | ||
| 138 | + 'user_id' => \Yii::$app->user->id, | ||
| 139 | + ] | ||
| 140 | + ) | ||
| 137 | ->all(); | 141 | ->all(); |
| 138 | return $this->render( | 142 | return $this->render( |
| 139 | 'list', | 143 | 'list', |
| @@ -424,8 +428,15 @@ | @@ -424,8 +428,15 @@ | ||
| 424 | 428 | ||
| 425 | public function findProperty($id) | 429 | public function findProperty($id) |
| 426 | { | 430 | { |
| 427 | - $model = IntellectualProperty::findOne($id); | ||
| 428 | - if (empty($model)) { | 431 | + $model = IntellectualProperty::find() |
| 432 | + ->where( | ||
| 433 | + [ | ||
| 434 | + 'id' => $id, | ||
| 435 | + 'user_id' => \Yii::$app->user->id, | ||
| 436 | + ] | ||
| 437 | + ) | ||
| 438 | + ->one(); | ||
| 439 | + if (empty( $model )) { | ||
| 429 | throw new NotFoundHttpException(); | 440 | throw new NotFoundHttpException(); |
| 430 | } | 441 | } |
| 431 | return $model; | 442 | return $model; |
frontend/models/IntellectualProperty.php
| @@ -17,6 +17,7 @@ | @@ -17,6 +17,7 @@ | ||
| 17 | * @property string $contract | 17 | * @property string $contract |
| 18 | * @property string $type | 18 | * @property string $type |
| 19 | * @property CreativeRole[] $creativeRoles | 19 | * @property CreativeRole[] $creativeRoles |
| 20 | + * @property CreativeRole $creativeRole | ||
| 20 | * @property User $user | 21 | * @property User $user |
| 21 | * @property Report[] $reports | 22 | * @property Report[] $reports |
| 22 | */ | 23 | */ |
| @@ -93,6 +94,12 @@ | @@ -93,6 +94,12 @@ | ||
| 93 | return $this->hasMany(CreativeRole::className(), [ 'intellectual_property_id' => 'id' ]); | 94 | return $this->hasMany(CreativeRole::className(), [ 'intellectual_property_id' => 'id' ]); |
| 94 | } | 95 | } |
| 95 | 96 | ||
| 97 | + public function getCreativeRole() | ||
| 98 | + { | ||
| 99 | + return $this->hasOne(CreativeRole::className(), [ 'intellectual_property_id' => 'id' ]) | ||
| 100 | + ->where([ 'user_id' => \Yii::$app->user->id ]); | ||
| 101 | + } | ||
| 102 | + | ||
| 96 | /** | 103 | /** |
| 97 | * @return \yii\db\ActiveQuery | 104 | * @return \yii\db\ActiveQuery |
| 98 | */ | 105 | */ |
frontend/views/cabinet/index.php
| @@ -7,6 +7,7 @@ | @@ -7,6 +7,7 @@ | ||
| 7 | * @var IntellectualProperty[] $table | 7 | * @var IntellectualProperty[] $table |
| 8 | */ | 8 | */ |
| 9 | 9 | ||
| 10 | + use common\models\User; | ||
| 10 | use frontend\models\UserData; | 11 | use frontend\models\UserData; |
| 11 | use frontend\models\UserPassport; | 12 | use frontend\models\UserPassport; |
| 12 | use frontend\models\IntellectualProperty; | 13 | use frontend\models\IntellectualProperty; |
| @@ -15,6 +16,10 @@ | @@ -15,6 +16,10 @@ | ||
| 15 | use yii\widgets\Pjax; | 16 | use yii\widgets\Pjax; |
| 16 | 17 | ||
| 17 | $this->title = 'My Yii Application'; | 18 | $this->title = 'My Yii Application'; |
| 19 | + /** | ||
| 20 | + * @var User $user | ||
| 21 | + */ | ||
| 22 | + $user = \Yii::$app->user->identity; | ||
| 18 | ?> | 23 | ?> |
| 19 | <div class="style cab_content_list active-cab"> | 24 | <div class="style cab_content_list active-cab"> |
| 20 | <?php | 25 | <?php |
| @@ -68,13 +73,61 @@ | @@ -68,13 +73,61 @@ | ||
| 68 | ?> | 73 | ?> |
| 69 | <tr> | 74 | <tr> |
| 70 | <td><?= $i; ?></td> | 75 | <td><?= $i; ?></td> |
| 71 | - <td><?php echo Html::a($row->title, ['sales', 'id' => $row->id])?></td> | 76 | + <td> |
| 77 | + <?php | ||
| 78 | + if($row->user_id == $user->id) { | ||
| 79 | + echo Html::a($row->title, ['sales', 'id' => $row->id]); | ||
| 80 | + } else { | ||
| 81 | + echo $row->title; | ||
| 82 | + } | ||
| 83 | + ?> | ||
| 84 | + </td> | ||
| 72 | <td><?= $row->registration_date ?></td> | 85 | <td><?= $row->registration_date ?></td> |
| 73 | <td><?= $row->genre ?></td> | 86 | <td><?= $row->genre ?></td> |
| 74 | - <td><?= $row->author_role ?></td> | ||
| 75 | - <td></td> | ||
| 76 | - <td></td> | ||
| 77 | - <td></td> | 87 | + <td> |
| 88 | + <?php | ||
| 89 | + if(!empty($row->creativeRole)) { | ||
| 90 | + echo $row->creativeRole->title; | ||
| 91 | + } elseif($user->isAdmin()) { | ||
| 92 | + echo '-'; | ||
| 93 | + } else { | ||
| 94 | + echo 'У Вас немає ролі в даному ОІВ'; | ||
| 95 | + } | ||
| 96 | + ?> | ||
| 97 | + </td> | ||
| 98 | + <td> | ||
| 99 | + <?php | ||
| 100 | + if(!empty($row->creativeRole)) { | ||
| 101 | + echo $row->creativeRole->part.'%'; | ||
| 102 | + } else { | ||
| 103 | + echo '-'; | ||
| 104 | + } | ||
| 105 | + ?> | ||
| 106 | + </td> | ||
| 107 | + <td> | ||
| 108 | + <?php | ||
| 109 | + if(!empty($row->creativeRole)) { | ||
| 110 | + $sum = 0; | ||
| 111 | + foreach ($row->reports as $report) { | ||
| 112 | + $sum += $report->sum; | ||
| 113 | + } | ||
| 114 | + echo ($sum * $row->creativeRole->part / 100); | ||
| 115 | + unset($sum); | ||
| 116 | + } else { | ||
| 117 | + echo '-'; | ||
| 118 | + } | ||
| 119 | + ?> | ||
| 120 | + </td> | ||
| 121 | + <td> | ||
| 122 | + <?php | ||
| 123 | + $sum = 0; | ||
| 124 | + foreach ($row->reports as $report) { | ||
| 125 | + $sum += $report->count; | ||
| 126 | + } | ||
| 127 | + echo $sum; | ||
| 128 | + unset($sum); | ||
| 129 | + ?> | ||
| 130 | + </td> | ||
| 78 | </tr> | 131 | </tr> |
| 79 | <?php | 132 | <?php |
| 80 | $i++; | 133 | $i++; |