From d2cf06c70fedf38a24f935c89b69f1a16daa9d23 Mon Sep 17 00:00:00 2001 From: yarik Date: Wed, 28 Dec 2016 13:21:25 +0200 Subject: [PATCH] Counts --- frontend/models/IntellectualProperty.php | 9 +++++++-- frontend/models/Report.php | 13 ++++++++++--- 2 files changed, 17 insertions(+), 5 deletions(-) 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