|
1
|
|
|
<?php |
|
2
|
|
|
namespace Xetaravel\Http\Controllers\Admin; |
|
3
|
|
|
|
|
4
|
|
|
use Carbon\Carbon; |
|
5
|
|
|
use Illuminate\Http\Request; |
|
6
|
|
|
use Illuminate\Support\Facades\Cache; |
|
7
|
|
|
use Xetaravel\Http\Components\AnalyticsComponent; |
|
8
|
|
|
use Xetaravel\Models\Article; |
|
9
|
|
|
use Xetaravel\Models\Comment; |
|
10
|
|
|
use Xetaravel\Models\User; |
|
11
|
|
|
|
|
12
|
|
|
class PageController extends Controller |
|
13
|
|
|
{ |
|
14
|
|
|
use AnalyticsComponent; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Constructor |
|
18
|
|
|
*/ |
|
19
|
|
|
public function __construct() |
|
20
|
|
|
{ |
|
21
|
|
|
parent::__construct(); |
|
22
|
|
|
|
|
23
|
|
|
$this->endDate = Carbon::now()->subDay(); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Show the application dashboard. |
|
28
|
|
|
* |
|
29
|
|
|
* @return \Illuminate\Http\Response |
|
|
|
|
|
|
30
|
|
|
*/ |
|
31
|
|
|
public function index() |
|
32
|
|
|
{ |
|
33
|
|
|
$minutes = config('analytics.cache_lifetime_in_minutes'); |
|
34
|
|
|
|
|
35
|
|
|
if (config('analytics.enabled')) { |
|
36
|
|
|
// @codeCoverageIgnoreStart |
|
37
|
|
|
$visitorsData = Cache::remember('Analytics.visitors', $minutes, function () { |
|
38
|
|
|
return $this->buildVisitorsGraph(); |
|
39
|
|
|
}); |
|
40
|
|
|
|
|
41
|
|
|
$browsersData = Cache::remember('Analytics.browsers', $minutes, function () { |
|
42
|
|
|
return $this->buildBrowsersGraph(); |
|
43
|
|
|
}); |
|
44
|
|
|
|
|
45
|
|
|
$countriesData = Cache::remember('Analytics.countries', $minutes, function () { |
|
46
|
|
|
return $this->buildCountriesGraph(); |
|
47
|
|
|
}); |
|
48
|
|
|
|
|
49
|
|
|
$devicesGraph = Cache::remember('Analytics.devices', $minutes, function () { |
|
50
|
|
|
return $this->buildDevicesGraph(); |
|
51
|
|
|
}); |
|
52
|
|
|
|
|
53
|
|
|
$topCountries = array_slice($countriesData->rows, 0, 3); |
|
54
|
|
|
|
|
55
|
|
|
$operatingSystemGraph = Cache::remember('Analytics.operatingsystem', $minutes, function () { |
|
56
|
|
|
return $this->buildOperatingSytemGraph(); |
|
57
|
|
|
}); |
|
58
|
|
|
|
|
59
|
|
|
$todayVisitors = Cache::remember('Analytics.todayvisitors', $minutes, function () { |
|
60
|
|
|
return $this->buildTodayVisitors(); |
|
61
|
|
|
}); |
|
62
|
|
|
// @codeCoverageIgnoreEnd |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
$usersCount = Cache::remember('Analytics.users.count', $minutes, function () { |
|
66
|
|
|
return User::count(); |
|
67
|
|
|
}); |
|
68
|
|
|
|
|
69
|
|
|
$articlesCount = Cache::remember('Analytics.articles.count', $minutes, function () { |
|
70
|
|
|
return Article::count(); |
|
71
|
|
|
}); |
|
72
|
|
|
|
|
73
|
|
|
$commentsCount = Cache::remember('Analytics.comments.count', $minutes, function () { |
|
74
|
|
|
return Comment::count(); |
|
75
|
|
|
}); |
|
76
|
|
|
|
|
77
|
|
|
$breadcrumbs = $this->breadcrumbs; |
|
|
|
|
|
|
78
|
|
|
|
|
79
|
|
|
return view( |
|
80
|
|
|
'Admin::page.index', |
|
81
|
|
|
compact( |
|
82
|
|
|
'breadcrumbs', |
|
83
|
|
|
'visitorsData', |
|
84
|
|
|
'browsersData', |
|
85
|
|
|
'countriesData', |
|
86
|
|
|
'topCountries', |
|
87
|
|
|
'devicesGraph', |
|
88
|
|
|
'operatingSystemGraph', |
|
89
|
|
|
'usersCount', |
|
90
|
|
|
'articlesCount', |
|
91
|
|
|
'commentsCount', |
|
92
|
|
|
'todayVisitors' |
|
93
|
|
|
) |
|
94
|
|
|
); |
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
|
This check compares the return type specified in the
@returnannotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.