|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Model; |
|
4
|
|
|
|
|
5
|
|
|
use App\Classes\Interfaces\Linkable; |
|
6
|
|
|
use App\Classes\Interfaces\Linker; |
|
7
|
|
|
use Illuminate\Database\Eloquent\Model; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Class Activity |
|
11
|
|
|
* |
|
12
|
|
|
* @property string $message |
|
13
|
|
|
* @property int $event |
|
14
|
|
|
* |
|
15
|
|
|
* @property Linkable $model |
|
16
|
|
|
* @property Account $account |
|
17
|
|
|
* |
|
18
|
|
|
* @package App |
|
19
|
|
|
*/ |
|
20
|
|
|
class Activity extends Model |
|
21
|
|
|
{ |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @var int |
|
25
|
|
|
*/ |
|
26
|
|
|
public static $deleted = 0; |
|
27
|
|
|
/** |
|
28
|
|
|
* @var int |
|
29
|
|
|
*/ |
|
30
|
|
|
public static $created = 1; |
|
31
|
|
|
/** |
|
32
|
|
|
* @var int |
|
33
|
|
|
*/ |
|
34
|
|
|
public static $updated = 2; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* The table associated with the model. |
|
38
|
|
|
* |
|
39
|
|
|
* @var string |
|
40
|
|
|
*/ |
|
41
|
|
|
protected $table = 'activity'; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* The attributes that are not mass assignable. |
|
45
|
|
|
* |
|
46
|
|
|
* @var array |
|
47
|
|
|
*/ |
|
48
|
|
|
protected $guarded = []; |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @return bool|string |
|
|
|
|
|
|
52
|
|
|
*/ |
|
53
|
|
|
public function eventName() |
|
54
|
|
|
{ |
|
55
|
|
|
switch ($this->event) |
|
56
|
|
|
{ |
|
57
|
|
|
case self::$deleted : return 'deleted'; |
|
|
|
|
|
|
58
|
|
|
case self::$created : return 'created'; |
|
|
|
|
|
|
59
|
|
|
case self::$updated : return 'updated'; |
|
|
|
|
|
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
return false; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
|
67
|
|
|
*/ |
|
68
|
|
|
public function account() |
|
69
|
|
|
{ |
|
70
|
|
|
return $this->belongsTo(Account::class, 'account_id', 'id'); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* @return Linker |
|
75
|
|
|
*/ |
|
76
|
|
|
public function model() |
|
77
|
|
|
{ |
|
78
|
|
|
return $this->morphTo()->withTrashed(); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* @param int $action |
|
83
|
|
|
* @param Model $model |
|
84
|
|
|
* @param Account|null $account |
|
85
|
|
|
* @return mixed |
|
|
|
|
|
|
86
|
|
|
*/ |
|
87
|
|
|
public function log(int $action, Model $model, Account $account = null) |
|
88
|
|
|
{ |
|
89
|
|
|
$this->setAttribute('event', $action); |
|
90
|
|
|
|
|
91
|
|
|
$this->setAttribute('model_id', $model->getKey()); |
|
92
|
|
|
|
|
93
|
|
|
$this->setAttribute('model_type', $model->getMorphClass()); |
|
94
|
|
|
|
|
95
|
|
|
$this->setAttribute('account_id', $account->getKey()); |
|
|
|
|
|
|
96
|
|
|
|
|
97
|
|
|
return $this->save(); |
|
98
|
|
|
} |
|
99
|
|
|
} |
|
100
|
|
|
|
This check looks for the generic type
arrayas a return type and suggests a more specific type. This type is inferred from the actual code.