Commit 885e52f425959f8c72476d4496f85558aad20218

Authored by Yarik
1 parent 3fd7d43c

Creative roles

frontend/controllers/CabinetController.php
@@ -87,7 +87,11 @@ @@ -87,7 +87,11 @@
87 if ($id) { 87 if ($id) {
88 $property = $this->findProperty($id); 88 $property = $this->findProperty($id);
89 } else { 89 } else {
90 - $property = new IntellectualProperty(); 90 + $property = new IntellectualProperty(
  91 + [
  92 + 'user_id' => \Yii::$app->user->id,
  93 + ]
  94 + );
91 $newRecord = true; 95 $newRecord = true;
92 } 96 }
93 if ($property->load(\Yii::$app->request->post()) && $property->save()) { 97 if ($property->load(\Yii::$app->request->post()) && $property->save()) {
@@ -387,7 +391,14 @@ @@ -387,7 +391,14 @@
387 391
388 public function findProperty($id) 392 public function findProperty($id)
389 { 393 {
390 - $model = IntellectualProperty::findOne($id); 394 + $model = IntellectualProperty::find()
  395 + ->where(
  396 + [
  397 + 'id' => $id,
  398 + 'user_id' => \Yii::$app->user->id,
  399 + ]
  400 + )
  401 + ->one();
391 if (empty( $model )) { 402 if (empty( $model )) {
392 throw new NotFoundHttpException(); 403 throw new NotFoundHttpException();
393 } 404 }
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++;
frontend/views/cabinet/notifications.php
@@ -16,7 +16,6 @@ @@ -16,7 +16,6 @@
16 <tr> 16 <tr>
17 <td>№<br/>п/п</td> 17 <td>№<br/>п/п</td>
18 <td>Назва використаного твору</td> 18 <td>Назва використаного твору</td>
19 - <td>Виконавець — П.І.Б. виконавця (співвиконавців) або назва колективу виконавців</td>  
20 <td>Автор музики (П.І.Б.)</td> 19 <td>Автор музики (П.І.Б.)</td>
21 <td>Автор тексту (П.І.Б.)</td> 20 <td>Автор тексту (П.І.Б.)</td>
22 <td width="150">Тривалість звучання<br/> (год.:хвил.: сек.)<br/>0:00:00</td> 21 <td width="150">Тривалість звучання<br/> (год.:хвил.: сек.)<br/>0:00:00</td>