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 Carbon\Carbon; |
7
|
|
|
use Illuminate\Contracts\View\View; |
8
|
|
|
use Illuminate\Support\Collection; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class DevicesRatioComposer |
12
|
|
|
* |
13
|
|
|
* @package Arcanesoft\Tracker\ViewComposers\Dashboard |
14
|
|
|
* @author ARCANEDEV <[email protected]> |
15
|
|
|
*/ |
16
|
|
|
class DevicesRatioComposer extends AbstractViewComposer |
17
|
|
|
{ |
18
|
|
|
/* ------------------------------------------------------------------------------------------------ |
19
|
|
|
| Constants |
20
|
|
|
| ------------------------------------------------------------------------------------------------ |
21
|
|
|
*/ |
22
|
|
|
const VIEW = 'tracker::foundation._composers.dashboard.devices-ratio-chart'; |
23
|
|
|
|
24
|
|
|
/* ------------------------------------------------------------------------------------------------ |
25
|
|
|
| Main Functions |
26
|
|
|
| ------------------------------------------------------------------------------------------------ |
27
|
|
|
*/ |
28
|
|
|
/** |
29
|
|
|
* Compose the view. |
30
|
|
|
* |
31
|
|
|
* @param \Illuminate\Contracts\View\View $view |
32
|
|
|
*/ |
33
|
|
|
public function compose(View $view) |
34
|
|
|
{ |
35
|
|
|
/** |
36
|
|
|
* @var \Carbon\Carbon $start |
37
|
|
|
* @var \Carbon\Carbon $end |
38
|
|
|
* @var \Illuminate\Support\Collection $range |
39
|
|
|
*/ |
40
|
|
|
extract(DateRange::getCurrentMonthDaysRange()); |
|
|
|
|
41
|
|
|
|
42
|
|
|
$view->with('devicesRatio', $this->getDevicesFromSessions($start, $end)); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/* ------------------------------------------------------------------------------------------------ |
46
|
|
|
| Other Functions |
47
|
|
|
| ------------------------------------------------------------------------------------------------ |
48
|
|
|
*/ |
49
|
|
|
/** |
50
|
|
|
* Get the devices from sessions. |
51
|
|
|
* |
52
|
|
|
* @param \Carbon\Carbon $start |
53
|
|
|
* @param \Carbon\Carbon $end |
54
|
|
|
* |
55
|
|
|
* @return \Illuminate\Support\Collection |
56
|
|
|
*/ |
57
|
|
|
protected function getDevicesFromSessions(Carbon $start, Carbon $end) |
58
|
|
|
{ |
59
|
|
|
return $this->getVisitorsFilteredByDateRange($start, $end) |
60
|
|
|
->filter(function (Session $session) { |
61
|
|
|
return $session->hasDevice(); |
62
|
|
|
}) |
63
|
|
|
->transform(function (Session $session) { |
64
|
|
|
return $session->device; |
65
|
|
|
}) |
66
|
|
|
->groupBy('kind') |
67
|
|
|
->transform(function (Collection $items, $key) { |
68
|
|
|
return [ |
69
|
|
|
'kind' => trans("tracker::devices.kinds.$key"), |
70
|
|
|
'count' => $items->count(), |
71
|
|
|
]; |
72
|
|
|
}); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|