Commit d2cf06c70fedf38a24f935c89b69f1a16daa9d23

Authored by Yarik
1 parent e5923f6e

Counts

frontend/models/IntellectualProperty.php
@@ -44,6 +44,13 @@ @@ -44,6 +44,13 @@
44 ], 44 ],
45 [ 45 [
46 [ 46 [
  47 + 'percent',
  48 + 'calculated',
  49 + ],
  50 + 'number',
  51 + ],
  52 + [
  53 + [
47 'creation_date', 54 'creation_date',
48 'registration_date', 55 'registration_date',
49 'title', 56 'title',
@@ -52,8 +59,6 @@ @@ -52,8 +59,6 @@
52 'contract', 59 'contract',
53 'type', 60 'type',
54 'author_role', 61 'author_role',
55 - 'percent',  
56 - 'calculated',  
57 'play_count', 62 'play_count',
58 ], 63 ],
59 'string', 64 'string',
frontend/models/Report.php
@@ -104,13 +104,20 @@ @@ -104,13 +104,20 @@
104 public function afterSave($insert, $changedAttributes) 104 public function afterSave($insert, $changedAttributes)
105 { 105 {
106 if (!empty( $property = IntellectualProperty::findOne($this->intellectual_property_id) )) { 106 if (!empty( $property = IntellectualProperty::findOne($this->intellectual_property_id) )) {
107 - var_dump($property); die();  
108 $sum = 0; 107 $sum = 0;
  108 + $count = 0;
109 foreach ($property->reports as $report) { 109 foreach ($property->reports as $report) {
110 $sum += $report->sum; 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 parent::afterSave($insert, $changedAttributes); 122 parent::afterSave($insert, $changedAttributes);
116 } 123 }