1
|
|
|
<?php namespace Arcanesoft\Tracker\ViewComposers\Dashboard; |
2
|
|
|
|
3
|
|
|
use Arcanesoft\Tracker\Support\DateRange; |
4
|
|
|
use Arcanesoft\Tracker\ViewComposers\AbstractViewComposer; |
5
|
|
|
use Illuminate\Contracts\View\View; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Class AuthenticatedVisitorsRatioComposer |
9
|
|
|
* |
10
|
|
|
* @package Arcanesoft\Tracker\ViewComposers\Dashboard |
11
|
|
|
* @author ARCANEDEV <[email protected]> |
12
|
|
|
*/ |
13
|
|
|
class AuthenticatedVisitorsRatioComposer extends AbstractViewComposer |
14
|
|
|
{ |
15
|
|
|
/* ----------------------------------------------------------------- |
16
|
|
|
| Constants |
17
|
|
|
| ----------------------------------------------------------------- |
18
|
|
|
*/ |
19
|
|
|
|
20
|
|
|
const VIEW = 'tracker::admin._composers.dashboard.authenticated-visitors-ratio-chart'; |
21
|
|
|
|
22
|
|
|
/* ----------------------------------------------------------------- |
23
|
|
|
| Main Methods |
24
|
|
|
| ----------------------------------------------------------------- |
25
|
|
|
*/ |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Compose the view. |
29
|
|
|
* |
30
|
|
|
* @param \Illuminate\Contracts\View\View $view |
31
|
|
|
*/ |
32
|
|
|
public function compose(View $view) |
33
|
|
|
{ |
34
|
|
|
/** |
35
|
|
|
* @var \Carbon\Carbon $start |
36
|
|
|
* @var \Carbon\Carbon $end |
37
|
|
|
* @var \Illuminate\Support\Collection $range |
38
|
|
|
*/ |
39
|
|
|
extract(DateRange::getCurrentMonthDaysRange()); |
|
|
|
|
40
|
|
|
|
41
|
|
|
$view->with('authenticatedVisitorsRatio', $this->getAuthenticatedVisitorsRatio( |
42
|
|
|
$this->getVisitorsFilteredByDateRange($start, $end) |
43
|
|
|
)); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/* ----------------------------------------------------------------- |
47
|
|
|
| Other Methods |
48
|
|
|
| ----------------------------------------------------------------- |
49
|
|
|
*/ |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Get the authenticated visitors ratio. |
53
|
|
|
* |
54
|
|
|
* @param \Illuminate\Support\Collection $visitors |
55
|
|
|
* |
56
|
|
|
* @return \Illuminate\Support\Collection |
57
|
|
|
*/ |
58
|
|
|
private function getAuthenticatedVisitorsRatio($visitors) |
59
|
|
|
{ |
60
|
|
|
$ratio = [ |
61
|
|
|
'authenticated' => 0, |
62
|
|
|
'guest' => 0, |
63
|
|
|
]; |
64
|
|
|
|
65
|
|
|
foreach ($visitors as $visitor) { |
66
|
|
|
$visitor->hasUser() ? $ratio['authenticated'] += 1 : $ratio['guest'] += 1; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
return collect($ratio)->transform(function ($count, $key) { |
70
|
|
|
return [ |
71
|
|
|
'name' => trans("tracker::visitors.$key"), |
72
|
|
|
'count' => $count, |
73
|
|
|
]; |
74
|
|
|
}); |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|