Commit d2cf06c70fedf38a24f935c89b69f1a16daa9d23
1 parent
e5923f6e
Counts
Showing
2 changed files
with
17 additions
and
5 deletions
Show diff stats
frontend/models/IntellectualProperty.php
| ... | ... | @@ -44,6 +44,13 @@ |
| 44 | 44 | ], |
| 45 | 45 | [ |
| 46 | 46 | [ |
| 47 | + 'percent', | |
| 48 | + 'calculated', | |
| 49 | + ], | |
| 50 | + 'number', | |
| 51 | + ], | |
| 52 | + [ | |
| 53 | + [ | |
| 47 | 54 | 'creation_date', |
| 48 | 55 | 'registration_date', |
| 49 | 56 | 'title', |
| ... | ... | @@ -52,8 +59,6 @@ |
| 52 | 59 | 'contract', |
| 53 | 60 | 'type', |
| 54 | 61 | 'author_role', |
| 55 | - 'percent', | |
| 56 | - 'calculated', | |
| 57 | 62 | 'play_count', |
| 58 | 63 | ], |
| 59 | 64 | 'string', | ... | ... |
frontend/models/Report.php
| ... | ... | @@ -104,13 +104,20 @@ |
| 104 | 104 | public function afterSave($insert, $changedAttributes) |
| 105 | 105 | { |
| 106 | 106 | if (!empty( $property = IntellectualProperty::findOne($this->intellectual_property_id) )) { |
| 107 | - var_dump($property); die(); | |
| 108 | 107 | $sum = 0; |
| 108 | + $count = 0; | |
| 109 | 109 | foreach ($property->reports as $report) { |
| 110 | 110 | $sum += $report->sum; |
| 111 | + $count += $report->count; | |
| 111 | 112 | } |
| 112 | - $property->calculated = $property->percent * $sum / 100; | |
| 113 | - $property->save(true, [ 'calculated' ]); | |
| 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 | + ); | |
| 114 | 121 | } |
| 115 | 122 | parent::afterSave($insert, $changedAttributes); |
| 116 | 123 | } | ... | ... |