|
1
|
|
|
<?php namespace Arcanesoft\Tracker\ViewComposers\Dashboard; |
|
2
|
|
|
|
|
3
|
|
|
use Arcanesoft\Tracker\Models\Session; |
|
4
|
|
|
use Arcanesoft\Tracker\Support\DateRange; |
|
5
|
|
|
use Arcanesoft\Tracker\ViewComposers\AbstractViewComposer; |
|
6
|
|
|
use Illuminate\Contracts\View\View; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Class AuthenticatedVisitorsRatioComposer |
|
10
|
|
|
* |
|
11
|
|
|
* @package Arcanesoft\Tracker\ViewComposers\Dashboard |
|
12
|
|
|
* @author ARCANEDEV <[email protected]> |
|
13
|
|
|
*/ |
|
14
|
|
|
class AuthenticatedVisitorsRatioComposer extends AbstractViewComposer |
|
15
|
|
|
{ |
|
16
|
|
|
/* ------------------------------------------------------------------------------------------------ |
|
17
|
|
|
| Constants |
|
18
|
|
|
| ------------------------------------------------------------------------------------------------ |
|
19
|
|
|
*/ |
|
20
|
|
|
const VIEW = 'tracker::foundation._composers.dashboard.authenticated-visitors-ratio-chart'; |
|
21
|
|
|
|
|
22
|
|
|
/* ------------------------------------------------------------------------------------------------ |
|
23
|
|
|
| Main Functions |
|
24
|
|
|
| ------------------------------------------------------------------------------------------------ |
|
25
|
|
|
*/ |
|
26
|
|
|
/** |
|
27
|
|
|
* Compose the view. |
|
28
|
|
|
* |
|
29
|
|
|
* @param \Illuminate\Contracts\View\View $view |
|
30
|
|
|
*/ |
|
31
|
|
|
public function compose(View $view) |
|
32
|
|
|
{ |
|
33
|
|
|
/** |
|
34
|
|
|
* @var \Carbon\Carbon $start |
|
35
|
|
|
* @var \Carbon\Carbon $end |
|
36
|
|
|
* @var \Illuminate\Support\Collection $range |
|
37
|
|
|
*/ |
|
38
|
|
|
extract(DateRange::getCurrentMonthDaysRange()); |
|
|
|
|
|
|
39
|
|
|
|
|
40
|
|
|
$view->with( |
|
41
|
|
|
'authenticatedVisitors', |
|
42
|
|
|
$this->getAuthenticatedVisitors($start, $end) |
|
43
|
|
|
); |
|
44
|
|
|
|
|
45
|
|
|
$view->with( |
|
46
|
|
|
'guestVisitors', |
|
47
|
|
|
$this->getGuestVisitors($start, $end) |
|
48
|
|
|
); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/* ------------------------------------------------------------------------------------------------ |
|
52
|
|
|
| Other Functions |
|
53
|
|
|
| ------------------------------------------------------------------------------------------------ |
|
54
|
|
|
*/ |
|
55
|
|
|
/** |
|
56
|
|
|
* Get the authenticated visitors. |
|
57
|
|
|
* |
|
58
|
|
|
* @param \Carbon\Carbon $start |
|
59
|
|
|
* @param \Carbon\Carbon $end |
|
60
|
|
|
* |
|
61
|
|
|
* @return \Illuminate\Support\Collection |
|
62
|
|
|
*/ |
|
63
|
|
|
private function getAuthenticatedVisitors($start, $end) |
|
64
|
|
|
{ |
|
65
|
|
|
return $this->getCachedVisitors() |
|
66
|
|
|
->filter(function (Session $session) use ($start, $end) { |
|
67
|
|
|
return $session->updated_at->between($start, $end); |
|
68
|
|
|
}) |
|
69
|
|
|
->filter(function (Session $session) use ($start, $end) { |
|
70
|
|
|
return $session->hasUser(); |
|
71
|
|
|
}); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Get the guest visitors. |
|
76
|
|
|
* |
|
77
|
|
|
* @param \Carbon\Carbon $start |
|
78
|
|
|
* @param \Carbon\Carbon $end |
|
79
|
|
|
* |
|
80
|
|
|
* @return \Illuminate\Support\Collection |
|
81
|
|
|
*/ |
|
82
|
|
|
private function getGuestVisitors($start, $end) |
|
83
|
|
|
{ |
|
84
|
|
|
return $this->getCachedVisitors() |
|
85
|
|
|
->filter(function (Session $session) use ($start, $end) { |
|
86
|
|
|
return $session->updated_at->between($start, $end); |
|
87
|
|
|
}) |
|
88
|
|
|
->filter(function (Session $session) use ($start, $end) { |
|
89
|
|
|
return ! $session->hasUser(); |
|
90
|
|
|
}); |
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
|
|
|