|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace PragmaRX\Tracker\Vendor\Laravel\Models; |
|
4
|
|
|
|
|
5
|
|
|
class Log extends Base |
|
6
|
|
|
{ |
|
7
|
|
|
protected $table = 'tracker_log'; |
|
8
|
|
|
|
|
9
|
|
|
protected $fillable = [ |
|
10
|
|
|
'session_id', |
|
11
|
|
|
'method', |
|
12
|
|
|
'path_id', |
|
13
|
|
|
'query_id', |
|
14
|
|
|
'route_path_id', |
|
15
|
|
|
'referer_id', |
|
16
|
|
|
'is_ajax', |
|
17
|
|
|
'is_secure', |
|
18
|
|
|
'is_json', |
|
19
|
|
|
'wants_json', |
|
20
|
|
|
'error_id', |
|
21
|
|
|
]; |
|
22
|
|
|
|
|
23
|
|
|
public function session() |
|
24
|
|
|
{ |
|
25
|
|
|
return $this->belongsTo($this->getConfig()->get('session_model')); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public function path() |
|
29
|
|
|
{ |
|
30
|
|
|
return $this->belongsTo($this->getConfig()->get('path_model')); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function error() |
|
34
|
|
|
{ |
|
35
|
|
|
return $this->belongsTo($this->getConfig()->get('error_model')); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function logQuery() |
|
39
|
|
|
{ |
|
40
|
|
|
return $this->belongsTo($this->getConfig()->get('query_model'), 'query_id'); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function routePath() |
|
44
|
|
|
{ |
|
45
|
|
|
return $this->belongsTo($this->getConfig()->get('route_path_model'), 'route_path_id'); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function pageViews($minutes, $results) |
|
49
|
|
|
{ |
|
50
|
|
|
$query = $this->select( |
|
51
|
|
|
$this->getConnection()->raw('DATE(created_at) as date, count(*) as total') |
|
52
|
|
|
)->groupBy( |
|
53
|
|
|
$this->getConnection()->raw('DATE(created_at)') |
|
54
|
|
|
) |
|
55
|
|
|
->period($minutes) |
|
56
|
|
|
->orderBy('date'); |
|
57
|
|
|
|
|
58
|
|
|
if ($results) { |
|
59
|
|
|
return $query->get(); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
return $query; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
public function pageViewsByCountry($minutes, $results) |
|
66
|
|
|
{ |
|
67
|
|
|
$query = |
|
68
|
|
|
$this |
|
69
|
|
|
->select( |
|
70
|
|
|
'tracker_geoip.country_name as label', |
|
71
|
|
|
$this->getConnection()->raw('count(tracker_log.id) as value') |
|
72
|
|
|
) |
|
73
|
|
|
->join('tracker_sessions', 'tracker_log.session_id', '=', 'tracker_sessions.id') |
|
74
|
|
|
->join('tracker_geoip', 'tracker_sessions.geoip_id', '=', 'tracker_geoip.id') |
|
75
|
|
|
->groupBy('tracker_geoip.country_name') |
|
76
|
|
|
->period($minutes, 'tracker_log') |
|
77
|
|
|
->whereNotNull('tracker_sessions.geoip_id') |
|
78
|
|
|
->orderBy('value', 'desc'); |
|
79
|
|
|
|
|
80
|
|
|
if ($results) { |
|
81
|
|
|
return $query->get(); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
return $query; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
public function errors($minutes, $results) |
|
88
|
|
|
{ |
|
89
|
|
|
$query = $this |
|
90
|
|
|
->with('error') |
|
91
|
|
|
->with('session') |
|
92
|
|
|
->with('path') |
|
93
|
|
|
->period($minutes, 'tracker_log') |
|
94
|
|
|
->whereNotNull('error_id') |
|
95
|
|
|
->orderBy('created_at', 'desc'); |
|
96
|
|
|
|
|
97
|
|
|
if ($results) { |
|
98
|
|
|
return $query->get(); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
return $query; |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
public function allByRouteName($name, $minutes = null) |
|
105
|
|
|
{ |
|
106
|
|
|
$result = $this |
|
107
|
|
|
->join('tracker_route_paths', 'tracker_route_paths.id', '=', 'tracker_log.route_path_id') |
|
108
|
|
|
|
|
109
|
|
|
->leftJoin( |
|
110
|
|
|
'tracker_route_path_parameters', |
|
111
|
|
|
'tracker_route_path_parameters.route_path_id', |
|
112
|
|
|
'=', |
|
113
|
|
|
'tracker_route_paths.id' |
|
114
|
|
|
) |
|
115
|
|
|
|
|
116
|
|
|
->join('tracker_routes', 'tracker_routes.id', '=', 'tracker_route_paths.route_id') |
|
117
|
|
|
|
|
118
|
|
|
->where('tracker_routes.name', $name); |
|
119
|
|
|
|
|
120
|
|
|
if ($minutes) { |
|
121
|
|
|
$result->period($minutes, 'tracker_log'); |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
return $result; |
|
125
|
|
|
} |
|
126
|
|
|
} |
|
127
|
|
|
|