1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Sfneal\Tracking\Actions; |
4
|
|
|
|
5
|
|
|
use Illuminate\Database\Eloquent\Model; |
6
|
|
|
use Sfneal\Actions\AbstractAction; |
7
|
|
|
use Sfneal\Tracking\Models\TrackActivity; |
8
|
|
|
|
9
|
|
|
class TrackActivityAction extends AbstractAction |
10
|
|
|
{ |
11
|
|
|
public $model; |
12
|
|
|
public $request_token; |
13
|
|
|
public $user_id; |
14
|
|
|
public $route; |
15
|
|
|
public $model_changes; |
16
|
|
|
public $description; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Track a user's action. |
20
|
|
|
* |
21
|
|
|
* @param Model $model |
22
|
|
|
* @param string|null $request_token |
23
|
|
|
* @param int $user_id |
24
|
|
|
* @param string|null $route |
25
|
|
|
* @param array $model_changes |
26
|
|
|
* @param string|null $description |
27
|
|
|
*/ |
28
|
|
|
public function __construct( |
29
|
|
|
Model $model, |
30
|
|
|
string $request_token = null, |
31
|
|
|
int $user_id = 0, |
32
|
|
|
string $route = null, |
33
|
|
|
array $model_changes = [], |
34
|
|
|
string $description = null |
35
|
|
|
) { |
36
|
|
|
$this->model = $model; |
37
|
|
|
$this->request_token = $request_token; |
38
|
|
|
$this->user_id = $user_id; |
39
|
|
|
$this->route = $route; |
40
|
|
|
$this->model_changes = $model_changes; |
41
|
|
|
$this->description = $description; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Track a user's activity/actions. |
46
|
|
|
* |
47
|
|
|
* @return void |
48
|
|
|
*/ |
49
|
|
|
public function execute() |
50
|
|
|
{ |
51
|
|
|
TrackActivity::query()->create([ |
52
|
|
|
'user_id' => $this->user_id, |
53
|
|
|
'route' => $this->route, |
54
|
|
|
'description' => $this->description, |
55
|
|
|
'model_table' => $this->model->getTable(), |
56
|
|
|
'model_key' => $this->model->getKey(), |
57
|
|
|
'model_changes' => $this->model_changes, |
58
|
|
|
'request_token' => $this->request_token, |
59
|
|
|
]); |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|