Commit 2a4daadd20a5f110d749e21aad2af9e929bae721
1 parent
b6741a94
Migration
Showing
4 changed files
with
75 additions
and
40 deletions
Show diff stats
console/migrations/m161230_101523_big_migration.php
0 → 100644
| 1 | +<?php | ||
| 2 | + | ||
| 3 | + use yii\db\Migration; | ||
| 4 | + | ||
| 5 | + class m161230_101523_big_migration extends Migration | ||
| 6 | + { | ||
| 7 | + public function safeUp() | ||
| 8 | + { | ||
| 9 | + // Creative role | ||
| 10 | + $this->truncateTable('creative_role'); | ||
| 11 | + $this->dropColumn('creative_role', 'name'); | ||
| 12 | + $this->addColumn( | ||
| 13 | + 'creative_role', | ||
| 14 | + 'user_id', | ||
| 15 | + $this->integer() | ||
| 16 | + ->notNull() | ||
| 17 | + ); | ||
| 18 | + $this->addForeignKey( | ||
| 19 | + 'creative_role_user_fk', | ||
| 20 | + 'creative_role', | ||
| 21 | + 'user_id', | ||
| 22 | + 'user', | ||
| 23 | + 'id', | ||
| 24 | + 'CASCADE', | ||
| 25 | + 'CASCADE' | ||
| 26 | + ); | ||
| 27 | + | ||
| 28 | + // Intellectual property | ||
| 29 | + $this->dropColumn('intellectual_property', 'percent'); | ||
| 30 | + $this->dropColumn('intellectual_property', 'calculated'); | ||
| 31 | + $this->dropColumn('intellectual_property', 'play_count'); | ||
| 32 | + | ||
| 33 | + // Report | ||
| 34 | + $this->dropColumn('report', 'artist'); | ||
| 35 | + } | ||
| 36 | + | ||
| 37 | + public function safeDown() | ||
| 38 | + { | ||
| 39 | + // Creative role | ||
| 40 | + $this->addColumn('creative_role', 'name', $this->string()); | ||
| 41 | + $this->dropColumn('creative_role', 'user_id'); | ||
| 42 | + | ||
| 43 | + // Intellectual property | ||
| 44 | + $this->addColumn('intellectual_property', 'percent', $this->decimal()); | ||
| 45 | + $this->addColumn('intellectual_property', 'calculated', $this->decimal()); | ||
| 46 | + $this->addColumn('intellectual_property', 'play_count', $this->integer()); | ||
| 47 | + | ||
| 48 | + // Report | ||
| 49 | + $this->addColumn('report', 'artist', $this->string()); | ||
| 50 | + } | ||
| 51 | + } |
frontend/models/CreativeRole.php
| @@ -2,18 +2,21 @@ | @@ -2,18 +2,21 @@ | ||
| 2 | 2 | ||
| 3 | namespace frontend\models; | 3 | namespace frontend\models; |
| 4 | 4 | ||
| 5 | + use common\models\User; | ||
| 6 | + | ||
| 5 | /** | 7 | /** |
| 6 | * This is the model class for table "creative_role". | 8 | * This is the model class for table "creative_role". |
| 7 | * | 9 | * |
| 8 | * @property integer $id | 10 | * @property integer $id |
| 9 | * @property integer $intellectual_property_id | 11 | * @property integer $intellectual_property_id |
| 10 | * @property string $title | 12 | * @property string $title |
| 11 | - * @property string $name | ||
| 12 | * @property double $part | 13 | * @property double $part |
| 13 | * @property string $code | 14 | * @property string $code |
| 14 | * @property string $iri | 15 | * @property string $iri |
| 16 | + * @property integer $user_id | ||
| 15 | * @property string $society | 17 | * @property string $society |
| 16 | * @property IntellectualProperty $intellectualProperty | 18 | * @property IntellectualProperty $intellectualProperty |
| 19 | + * @property User $user | ||
| 17 | */ | 20 | */ |
| 18 | class CreativeRole extends \yii\db\ActiveRecord | 21 | class CreativeRole extends \yii\db\ActiveRecord |
| 19 | { | 22 | { |
| @@ -32,7 +35,10 @@ | @@ -32,7 +35,10 @@ | ||
| 32 | { | 35 | { |
| 33 | return [ | 36 | return [ |
| 34 | [ | 37 | [ |
| 35 | - [ 'intellectual_property_id' ], | 38 | + [ |
| 39 | + 'intellectual_property_id', | ||
| 40 | + 'user_id', | ||
| 41 | + ], | ||
| 36 | 'integer', | 42 | 'integer', |
| 37 | ], | 43 | ], |
| 38 | [ | 44 | [ |
| @@ -42,7 +48,6 @@ | @@ -42,7 +48,6 @@ | ||
| 42 | [ | 48 | [ |
| 43 | [ | 49 | [ |
| 44 | 'title', | 50 | 'title', |
| 45 | - 'name', | ||
| 46 | 'code', | 51 | 'code', |
| 47 | 'iri', | 52 | 'iri', |
| 48 | 'society', | 53 | 'society', |
| @@ -57,6 +62,13 @@ | @@ -57,6 +62,13 @@ | ||
| 57 | 'targetClass' => IntellectualProperty::className(), | 62 | 'targetClass' => IntellectualProperty::className(), |
| 58 | 'targetAttribute' => [ 'intellectual_property_id' => 'id' ], | 63 | 'targetAttribute' => [ 'intellectual_property_id' => 'id' ], |
| 59 | ], | 64 | ], |
| 65 | + [ | ||
| 66 | + [ 'user_id' ], | ||
| 67 | + 'exist', | ||
| 68 | + 'skipOnError' => true, | ||
| 69 | + 'targetClass' => User::className(), | ||
| 70 | + 'targetAttribute' => [ 'user_id' => 'id' ], | ||
| 71 | + ], | ||
| 60 | ]; | 72 | ]; |
| 61 | } | 73 | } |
| 62 | 74 | ||
| @@ -69,11 +81,11 @@ | @@ -69,11 +81,11 @@ | ||
| 69 | 'id' => 'ID', | 81 | 'id' => 'ID', |
| 70 | 'intellectual_property_id' => 'Intellectual Property ID', | 82 | 'intellectual_property_id' => 'Intellectual Property ID', |
| 71 | 'title' => 'Творча роль', | 83 | 'title' => 'Творча роль', |
| 72 | - 'name' => 'ПІБ', | ||
| 73 | 'part' => 'Доля %', | 84 | 'part' => 'Доля %', |
| 74 | 'code' => 'Код', | 85 | 'code' => 'Код', |
| 75 | 'iri' => 'IPI', | 86 | 'iri' => 'IPI', |
| 76 | 'society' => 'Товариство', | 87 | 'society' => 'Товариство', |
| 88 | + 'user_id' => 'ПІБ', | ||
| 77 | ]; | 89 | ]; |
| 78 | } | 90 | } |
| 79 | 91 | ||
| @@ -84,4 +96,12 @@ | @@ -84,4 +96,12 @@ | ||
| 84 | { | 96 | { |
| 85 | return $this->hasOne(IntellectualProperty::className(), [ 'id' => 'intellectual_property_id' ]); | 97 | return $this->hasOne(IntellectualProperty::className(), [ 'id' => 'intellectual_property_id' ]); |
| 86 | } | 98 | } |
| 99 | + | ||
| 100 | + /** | ||
| 101 | + * @return \yii\db\ActiveQuery | ||
| 102 | + */ | ||
| 103 | + public function getUser() | ||
| 104 | + { | ||
| 105 | + return $this->hasOne(User::className(), [ 'id' => 'user_id' ]); | ||
| 106 | + } | ||
| 87 | } | 107 | } |
frontend/models/IntellectualProperty.php
| @@ -39,19 +39,11 @@ | @@ -39,19 +39,11 @@ | ||
| 39 | [ | 39 | [ |
| 40 | [ | 40 | [ |
| 41 | 'user_id', | 41 | 'user_id', |
| 42 | - 'play_count', | ||
| 43 | ], | 42 | ], |
| 44 | 'integer', | 43 | 'integer', |
| 45 | ], | 44 | ], |
| 46 | [ | 45 | [ |
| 47 | [ | 46 | [ |
| 48 | - 'percent', | ||
| 49 | - 'calculated', | ||
| 50 | - ], | ||
| 51 | - 'number', | ||
| 52 | - ], | ||
| 53 | - [ | ||
| 54 | - [ | ||
| 55 | 'creation_date', | 47 | 'creation_date', |
| 56 | 'registration_date', | 48 | 'registration_date', |
| 57 | 'title', | 49 | 'title', |
| @@ -90,9 +82,6 @@ | @@ -90,9 +82,6 @@ | ||
| 90 | 'contract' => 'Договір', | 82 | 'contract' => 'Договір', |
| 91 | 'type' => 'Тип', | 83 | 'type' => 'Тип', |
| 92 | 'author_role' => 'Роль автора', | 84 | 'author_role' => 'Роль автора', |
| 93 | - 'percent' => 'Процент долі автора', | ||
| 94 | - 'calculated' => 'Нараховано', | ||
| 95 | - 'play_count' => 'К-ть відтворень', | ||
| 96 | ]; | 85 | ]; |
| 97 | } | 86 | } |
| 98 | 87 |
frontend/models/Report.php
| @@ -8,7 +8,6 @@ | @@ -8,7 +8,6 @@ | ||
| 8 | * @property integer $id | 8 | * @property integer $id |
| 9 | * @property integer $intellectual_property_id | 9 | * @property integer $intellectual_property_id |
| 10 | * @property string $title | 10 | * @property string $title |
| 11 | - * @property string $artist | ||
| 12 | * @property string $music_author | 11 | * @property string $music_author |
| 13 | * @property string $text_author | 12 | * @property string $text_author |
| 14 | * @property integer $time | 13 | * @property integer $time |
| @@ -54,7 +53,6 @@ | @@ -54,7 +53,6 @@ | ||
| 54 | [ | 53 | [ |
| 55 | [ | 54 | [ |
| 56 | 'title', | 55 | 'title', |
| 57 | - 'artist', | ||
| 58 | 'music_author', | 56 | 'music_author', |
| 59 | 'text_author', | 57 | 'text_author', |
| 60 | 'user', | 58 | 'user', |
| @@ -81,7 +79,6 @@ | @@ -81,7 +79,6 @@ | ||
| 81 | 'id' => 'ID', | 79 | 'id' => 'ID', |
| 82 | 'intellectual_property_id' => 'Твір', | 80 | 'intellectual_property_id' => 'Твір', |
| 83 | 'title' => 'Title', | 81 | 'title' => 'Title', |
| 84 | - 'artist' => 'Виконавець', | ||
| 85 | 'music_author' => 'Music Author', | 82 | 'music_author' => 'Music Author', |
| 86 | 'text_author' => 'Text Author', | 83 | 'text_author' => 'Text Author', |
| 87 | 'time' => 'Time', | 84 | 'time' => 'Time', |
| @@ -101,28 +98,6 @@ | @@ -101,28 +98,6 @@ | ||
| 101 | return $this->hasOne(IntellectualProperty::className(), [ 'id' => 'intellectual_property_id' ]); | 98 | return $this->hasOne(IntellectualProperty::className(), [ 'id' => 'intellectual_property_id' ]); |
| 102 | } | 99 | } |
| 103 | 100 | ||
| 104 | - public function afterSave($insert, $changedAttributes) | ||
| 105 | - { | ||
| 106 | - if (!empty( $property = IntellectualProperty::findOne($this->intellectual_property_id) )) { | ||
| 107 | - $sum = 0; | ||
| 108 | - $count = 0; | ||
| 109 | - foreach ($property->reports as $report) { | ||
| 110 | - $sum += $report->sum; | ||
| 111 | - $count += $report->count; | ||
| 112 | - } | ||
| 113 | - $property->calculated = ( (float) $property->percent ) * $sum / 100; | ||
| 114 | - $property->play_count = $count; | ||
| 115 | - $property->save(true, | ||
| 116 | - [ | ||
| 117 | - 'calculated', | ||
| 118 | - 'play_count', | ||
| 119 | - ] | ||
| 120 | - ); | ||
| 121 | - | ||
| 122 | - } | ||
| 123 | - parent::afterSave($insert, $changedAttributes); | ||
| 124 | - } | ||
| 125 | - | ||
| 126 | public function beforeSave($insert) | 101 | public function beforeSave($insert) |
| 127 | { | 102 | { |
| 128 | $this->royalty = $this->sum * 0.8 * 0.805; | 103 | $this->royalty = $this->sum * 0.8 * 0.805; |