1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Sfneal\Tracking\Queries; |
4
|
|
|
|
5
|
|
|
use Illuminate\Http\Request; |
6
|
|
|
use Sfneal\Helpers\Time\TimePeriods; |
7
|
|
|
use Sfneal\Queries\AbstractQueryStatic; |
8
|
|
|
use Sfneal\Queries\Traits\ParamGetter; |
9
|
|
|
use Sfneal\Tracking\Builders\TrackActionBuilder; |
10
|
|
|
use Sfneal\Tracking\Models\TrackAction; |
11
|
|
|
|
12
|
|
|
class TrackActionQuery extends AbstractQueryStatic |
13
|
|
|
{ |
14
|
|
|
use ParamGetter; |
15
|
|
|
|
16
|
|
|
// todo: add to config |
17
|
|
|
/** |
18
|
|
|
* Relationships that should be eager loaded by default. |
19
|
|
|
*/ |
20
|
|
|
private const DEFAULT_RELATIONSHIPS = [ |
21
|
|
|
'plan', |
22
|
|
|
'planManagement', |
23
|
|
|
'planManagement.plan', |
24
|
|
|
'project', |
25
|
|
|
'task', |
26
|
|
|
'task.project', |
27
|
|
|
'taskRecord', |
28
|
|
|
'taskRecord.task', |
29
|
|
|
'taskRecord.task.project', |
30
|
|
|
]; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Retrieve a TrackActivity by table query result set. |
34
|
|
|
* |
35
|
|
|
* @param Request|null $request |
36
|
|
|
* @param array $parameters |
37
|
|
|
* @param array|null $relationships |
38
|
|
|
* |
39
|
|
|
* @return TrackActionBuilder |
40
|
|
|
*/ |
41
|
|
|
public static function execute(Request $request = null, array $parameters = [], array $relationships = null): TrackActionBuilder |
42
|
|
|
{ |
43
|
|
|
$tracking = TrackAction::query() |
44
|
|
|
->with($relationships ?? self::DEFAULT_RELATIONSHIPS); |
45
|
|
|
|
46
|
|
|
// Table |
47
|
|
|
if ($table = self::getParam($request, $parameters, 'table')) { |
48
|
|
|
$tracking->whereModelTable($table); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
// Key |
52
|
|
|
if ($model_keys = self::getParam($request, $parameters, 'key')) { |
53
|
|
|
$tracking->whereModelKey($model_keys); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
// Time Period |
57
|
|
|
if ($period = self::getParam($request, $parameters, 'period')) { |
58
|
|
|
if (is_string($period)) { |
59
|
|
|
$period = TimePeriods::timePeriod($period); |
60
|
|
|
} |
61
|
|
|
$tracking->whereBetween('created_at', $period); |
|
|
|
|
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
return $tracking; |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|