|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Sfneal\Tracking\Actions; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Database\Eloquent\Model; |
|
6
|
|
|
use Sfneal\Actions\Action; |
|
7
|
|
|
use Sfneal\Tracking\Models\TrackActivity; |
|
8
|
|
|
use Sfneal\Tracking\Utils\ModelAdapter; |
|
9
|
|
|
|
|
10
|
|
|
class TrackActivityAction extends Action |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* @var Model |
|
14
|
|
|
*/ |
|
15
|
|
|
public $model; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @var string|null |
|
19
|
|
|
*/ |
|
20
|
|
|
public $request_token; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @var int |
|
24
|
|
|
*/ |
|
25
|
|
|
public $user_id; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @var string|null |
|
29
|
|
|
*/ |
|
30
|
|
|
public $route; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @var array |
|
34
|
|
|
*/ |
|
35
|
|
|
public $model_changes; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @var string|null |
|
39
|
|
|
*/ |
|
40
|
|
|
public $description; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Track a user's action. |
|
44
|
|
|
* |
|
45
|
|
|
* @param Model $model |
|
46
|
|
|
* @param string|null $request_token |
|
47
|
|
|
* @param int $user_id |
|
48
|
|
|
* @param string|null $route |
|
49
|
|
|
* @param array $model_changes |
|
50
|
|
|
* @param string|null $description |
|
51
|
|
|
*/ |
|
52
|
|
|
public function __construct( |
|
53
|
|
|
Model $model, |
|
54
|
|
|
string $request_token = null, |
|
55
|
|
|
int $user_id = 0, |
|
56
|
|
|
string $route = null, |
|
57
|
|
|
array $model_changes = [], |
|
58
|
|
|
string $description = null |
|
59
|
|
|
) { |
|
60
|
|
|
$this->model = $model; |
|
61
|
|
|
$this->request_token = $request_token; |
|
62
|
|
|
$this->user_id = $user_id; |
|
63
|
|
|
$this->route = $route; |
|
64
|
|
|
$this->model_changes = $model_changes; |
|
65
|
|
|
$this->description = $description; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Track a user's activity/actions. |
|
70
|
|
|
* |
|
71
|
|
|
* @return TrackActivity|Model |
|
72
|
|
|
*/ |
|
73
|
|
|
public function execute(): TrackActivity |
|
74
|
|
|
{ |
|
75
|
|
|
return ModelAdapter::TrackActivity()::query()->create([ |
|
76
|
|
|
'user_id' => $this->user_id, |
|
77
|
|
|
'route' => $this->route, |
|
78
|
|
|
'description' => $this->description, |
|
79
|
|
|
'model_changes' => $this->model_changes, |
|
80
|
|
|
'request_token' => $this->request_token, |
|
81
|
|
|
'trackable_id' => $this->model->getKey(), |
|
82
|
|
|
'trackable_type' => get_class($this->model), |
|
83
|
|
|
]); |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|