forked from DallasMuseumArt/OctoberFriends
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRating.php
58 lines (41 loc) · 982 Bytes
/
Rating.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php namespace DMA\Friends\Models;
use Model;
use RainLab\User\Models\User;
/**
* ActivityRating Model
*
*/
class Rating extends Model
{
/**
* @var string The database table used by the model.
*/
public $table = 'dma_friends_ratings';
/**
* @var array Guarded fields
*/
protected $guarded = ['*'];
/**
* @var array Fillable fields
*/
protected $fillable = [];
public $rules = [];
public $morphTo = [
'object' => ['id' => 'object_id'],
];
/**
* @var array Relations
*/
public $hasMany = [
'rates' => ['DMA\Friends\Models\UserRate', 'table' => 'dma_friends_user_rates'],
];
/**
* Recalculate ratings stats ( total and average )
*/
public function reCalculateRating()
{
$this->total = $this->rates()->count();
$this->average = $this->rates()->avg('rate');
$this->save();
}
}