diff --git a/frontend/models/IntellectualProperty.php b/frontend/models/IntellectualProperty.php index 9597c86..7b27dcc 100755 --- a/frontend/models/IntellectualProperty.php +++ b/frontend/models/IntellectualProperty.php @@ -44,6 +44,13 @@ ], [ [ + 'percent', + 'calculated', + ], + 'number', + ], + [ + [ 'creation_date', 'registration_date', 'title', @@ -52,8 +59,6 @@ 'contract', 'type', 'author_role', - 'percent', - 'calculated', 'play_count', ], 'string', diff --git a/frontend/models/Report.php b/frontend/models/Report.php index 533901b..f0eb92e 100755 --- a/frontend/models/Report.php +++ b/frontend/models/Report.php @@ -104,13 +104,20 @@ public function afterSave($insert, $changedAttributes) { if (!empty( $property = IntellectualProperty::findOne($this->intellectual_property_id) )) { - var_dump($property); die(); $sum = 0; + $count = 0; foreach ($property->reports as $report) { $sum += $report->sum; + $count += $report->count; } - $property->calculated = $property->percent * $sum / 100; - $property->save(true, [ 'calculated' ]); + $property->calculated = ( (float) $property->percent ) * $sum / 100; + $property->play_count = $count; + $property->save(true, + [ + 'calculated', + 'play_count', + ] + ); } parent::afterSave($insert, $changedAttributes); } -- libgit2 0.21.4