1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use AshPowell\APAnalytics\APAnalytics; |
4
|
|
|
use Illuminate\Support\Carbon; |
5
|
|
|
use MongoDB\BSON\UTCDateTime; |
6
|
|
|
|
7
|
|
|
if (! function_exists('analytics')) { |
8
|
|
|
function analytics(): APAnalytics |
9
|
|
|
{ |
10
|
|
|
return app(APAnalytics::class); |
11
|
|
|
} |
12
|
|
|
} |
13
|
|
|
|
14
|
|
|
if (! function_exists('trackEvent')) { |
15
|
|
|
/** |
16
|
|
|
* Access event dispatch of event tracker direct. |
17
|
|
|
* @param mixed $event |
18
|
|
|
* @param mixed $collection |
19
|
|
|
* @param mixed $items |
20
|
|
|
* @param mixed $params |
21
|
|
|
* @param null|mixed $userId |
22
|
|
|
*/ |
23
|
|
|
function trackEvent($collection, $items, $userId = null, $params = []) |
|
|
|
|
24
|
|
|
{ |
25
|
|
|
return analytics()->track($collection, $items, $userId, $params); |
|
|
|
|
26
|
|
|
} |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
if (! function_exists('showEvents')) { |
30
|
|
|
/** |
31
|
|
|
* Access event dispatch of event tracker direct. |
32
|
|
|
* @param mixed $event |
33
|
|
|
* @param mixed $collection |
34
|
|
|
* @param mixed $items |
35
|
|
|
* @param mixed $params |
36
|
|
|
* @param null|mixed $userId |
37
|
|
|
* @param null|mixed $timeframe |
38
|
|
|
* @param null|mixed $filters |
39
|
|
|
* @param mixed $interval |
40
|
|
|
*/ |
41
|
|
|
function showEvents($collection, $interval = 'count', $timeframe = null, $filters = null) |
42
|
|
|
{ |
43
|
|
|
return analytics()->show($collection, $interval, $timeframe, $filters); |
44
|
|
|
} |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
if (! function_exists('is_countable')) { |
48
|
|
|
function is_countable($c) |
49
|
|
|
{ |
50
|
|
|
return is_array($c) || $c instanceof Countable; |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
if (! function_exists('mongoTime')) { |
55
|
|
|
/** |
56
|
|
|
* Returns time in MongoDb Time. |
57
|
|
|
* @param null|mixed $time |
58
|
|
|
*/ |
59
|
|
|
function mongoTime($time = null) |
60
|
|
|
{ |
61
|
|
|
$time = ($time) ? Carbon::parse($time) : now(); |
62
|
|
|
|
63
|
|
|
return new UTCDateTime($time); |
|
|
|
|
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
if (! function_exists('valid_json')) { |
68
|
|
|
function valid_json($value) |
69
|
|
|
{ |
70
|
|
|
if (! is_string($value)) { |
71
|
|
|
return false; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
json_decode($value); |
75
|
|
|
|
76
|
|
|
return json_last_error() === JSON_ERROR_NONE; |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.