diff --git a/console/migrations/m161230_101523_big_migration.php b/console/migrations/m161230_101523_big_migration.php new file mode 100644 index 0000000..0f68347 --- /dev/null +++ b/console/migrations/m161230_101523_big_migration.php @@ -0,0 +1,51 @@ +truncateTable('creative_role'); + $this->dropColumn('creative_role', 'name'); + $this->addColumn( + 'creative_role', + 'user_id', + $this->integer() + ->notNull() + ); + $this->addForeignKey( + 'creative_role_user_fk', + 'creative_role', + 'user_id', + 'user', + 'id', + 'CASCADE', + 'CASCADE' + ); + + // Intellectual property + $this->dropColumn('intellectual_property', 'percent'); + $this->dropColumn('intellectual_property', 'calculated'); + $this->dropColumn('intellectual_property', 'play_count'); + + // Report + $this->dropColumn('report', 'artist'); + } + + public function safeDown() + { + // Creative role + $this->addColumn('creative_role', 'name', $this->string()); + $this->dropColumn('creative_role', 'user_id'); + + // Intellectual property + $this->addColumn('intellectual_property', 'percent', $this->decimal()); + $this->addColumn('intellectual_property', 'calculated', $this->decimal()); + $this->addColumn('intellectual_property', 'play_count', $this->integer()); + + // Report + $this->addColumn('report', 'artist', $this->string()); + } + } diff --git a/frontend/models/CreativeRole.php b/frontend/models/CreativeRole.php index 1f60580..df97526 100755 --- a/frontend/models/CreativeRole.php +++ b/frontend/models/CreativeRole.php @@ -2,18 +2,21 @@ namespace frontend\models; + use common\models\User; + /** * This is the model class for table "creative_role". * * @property integer $id * @property integer $intellectual_property_id * @property string $title - * @property string $name * @property double $part * @property string $code * @property string $iri + * @property integer $user_id * @property string $society * @property IntellectualProperty $intellectualProperty + * @property User $user */ class CreativeRole extends \yii\db\ActiveRecord { @@ -32,7 +35,10 @@ { return [ [ - [ 'intellectual_property_id' ], + [ + 'intellectual_property_id', + 'user_id', + ], 'integer', ], [ @@ -42,7 +48,6 @@ [ [ 'title', - 'name', 'code', 'iri', 'society', @@ -57,6 +62,13 @@ 'targetClass' => IntellectualProperty::className(), 'targetAttribute' => [ 'intellectual_property_id' => 'id' ], ], + [ + [ 'user_id' ], + 'exist', + 'skipOnError' => true, + 'targetClass' => User::className(), + 'targetAttribute' => [ 'user_id' => 'id' ], + ], ]; } @@ -69,11 +81,11 @@ 'id' => 'ID', 'intellectual_property_id' => 'Intellectual Property ID', 'title' => 'Творча роль', - 'name' => 'ПІБ', 'part' => 'Доля %', 'code' => 'Код', 'iri' => 'IPI', 'society' => 'Товариство', + 'user_id' => 'ПІБ', ]; } @@ -84,4 +96,12 @@ { return $this->hasOne(IntellectualProperty::className(), [ 'id' => 'intellectual_property_id' ]); } + + /** + * @return \yii\db\ActiveQuery + */ + public function getUser() + { + return $this->hasOne(User::className(), [ 'id' => 'user_id' ]); + } } diff --git a/frontend/models/IntellectualProperty.php b/frontend/models/IntellectualProperty.php index 95a161c..b1d4b33 100755 --- a/frontend/models/IntellectualProperty.php +++ b/frontend/models/IntellectualProperty.php @@ -39,19 +39,11 @@ [ [ 'user_id', - 'play_count', ], 'integer', ], [ [ - 'percent', - 'calculated', - ], - 'number', - ], - [ - [ 'creation_date', 'registration_date', 'title', @@ -90,9 +82,6 @@ 'contract' => 'Договір', 'type' => 'Тип', 'author_role' => 'Роль автора', - 'percent' => 'Процент долі автора', - 'calculated' => 'Нараховано', - 'play_count' => 'К-ть відтворень', ]; } diff --git a/frontend/models/Report.php b/frontend/models/Report.php index 3257a65..2f1d371 100755 --- a/frontend/models/Report.php +++ b/frontend/models/Report.php @@ -8,7 +8,6 @@ * @property integer $id * @property integer $intellectual_property_id * @property string $title - * @property string $artist * @property string $music_author * @property string $text_author * @property integer $time @@ -54,7 +53,6 @@ [ [ 'title', - 'artist', 'music_author', 'text_author', 'user', @@ -81,7 +79,6 @@ 'id' => 'ID', 'intellectual_property_id' => 'Твір', 'title' => 'Title', - 'artist' => 'Виконавець', 'music_author' => 'Music Author', 'text_author' => 'Text Author', 'time' => 'Time', @@ -101,28 +98,6 @@ return $this->hasOne(IntellectualProperty::className(), [ 'id' => 'intellectual_property_id' ]); } - public function afterSave($insert, $changedAttributes) - { - if (!empty( $property = IntellectualProperty::findOne($this->intellectual_property_id) )) { - $sum = 0; - $count = 0; - foreach ($property->reports as $report) { - $sum += $report->sum; - $count += $report->count; - } - $property->calculated = ( (float) $property->percent ) * $sum / 100; - $property->play_count = $count; - $property->save(true, - [ - 'calculated', - 'play_count', - ] - ); - - } - parent::afterSave($insert, $changedAttributes); - } - public function beforeSave($insert) { $this->royalty = $this->sum * 0.8 * 0.805; -- libgit2 0.21.4