|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Xetaravel\Http\Controllers\Admin; |
|
6
|
|
|
|
|
7
|
|
|
use Illuminate\Contracts\View\Factory; |
|
8
|
|
|
use Illuminate\Contracts\View\View; |
|
9
|
|
|
use Illuminate\Foundation\Application; |
|
10
|
|
|
use Illuminate\Support\Facades\App; |
|
11
|
|
|
use Illuminate\Support\Facades\Cache; |
|
12
|
|
|
use Psr\Container\ContainerExceptionInterface; |
|
13
|
|
|
use Psr\Container\NotFoundExceptionInterface; |
|
14
|
|
|
use Xetaravel\Http\Components\AnalyticsComponent; |
|
15
|
|
|
use Xetaravel\Models\BlogArticle; |
|
16
|
|
|
use Xetaravel\Models\BlogComment; |
|
17
|
|
|
use Xetaravel\Models\User; |
|
18
|
|
|
|
|
19
|
|
|
class PageController extends Controller |
|
20
|
|
|
{ |
|
21
|
|
|
use AnalyticsComponent; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Show the application dashboard. |
|
25
|
|
|
* |
|
26
|
|
|
* @return Factory|View|Application|\Illuminate\View\View|object |
|
27
|
|
|
* |
|
28
|
|
|
* @throws ContainerExceptionInterface |
|
29
|
|
|
* @throws NotFoundExceptionInterface |
|
30
|
|
|
*/ |
|
31
|
|
|
public function index() |
|
32
|
|
|
{ |
|
33
|
|
|
$minutes = config('analytics.cache_lifetime_in_minutes'); |
|
34
|
|
|
|
|
35
|
|
|
$viewDatas = []; |
|
36
|
|
|
|
|
37
|
|
|
if (!App::environment('testing') && settings('analytics_enabled')) { |
|
38
|
|
|
|
|
39
|
|
|
$visitorsData = Cache::remember('Analytics.visitors', $minutes, function () { |
|
40
|
|
|
return $this->buildVisitorsGraph(); |
|
41
|
|
|
}); |
|
42
|
|
|
$viewDatas[] = 'visitorsData'; |
|
43
|
|
|
|
|
44
|
|
|
$browsersData = Cache::remember('Analytics.browsers', $minutes, function () { |
|
45
|
|
|
return $this->buildBrowsersGraph(); |
|
46
|
|
|
}); |
|
47
|
|
|
$viewDatas[] = 'browsersData'; |
|
48
|
|
|
|
|
49
|
|
|
$devicesGraph = Cache::remember('Analytics.devices', $minutes, function () { |
|
50
|
|
|
return $this->buildDevicesGraph(); |
|
51
|
|
|
}); |
|
52
|
|
|
$viewDatas[] = 'devicesGraph'; |
|
53
|
|
|
|
|
54
|
|
|
$operatingSystemGraph = Cache::remember('Analytics.operatingsystem', $minutes, function () { |
|
55
|
|
|
return $this->buildOperatingSystemGraph(); |
|
56
|
|
|
}); |
|
57
|
|
|
$viewDatas[] = 'operatingSystemGraph'; |
|
58
|
|
|
|
|
59
|
|
|
$yesterdayVisitors = Cache::remember('Analytics.yesterdayvisitors', $minutes, function () { |
|
60
|
|
|
return $this->buildYesterdayVisitors(); |
|
61
|
|
|
}); |
|
62
|
|
|
$viewDatas[] = 'yesterdayVisitors'; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
$usersCount = Cache::remember('Analytics.users.count', $minutes, function () { |
|
66
|
|
|
return User::count(); |
|
67
|
|
|
}); |
|
68
|
|
|
$viewDatas[] = 'usersCount'; |
|
69
|
|
|
|
|
70
|
|
|
$articlesCount = Cache::remember('Analytics.articles.count', $minutes, function () { |
|
71
|
|
|
return BlogArticle::count(); |
|
72
|
|
|
}); |
|
73
|
|
|
$viewDatas[] = 'articlesCount'; |
|
74
|
|
|
|
|
75
|
|
|
$commentsCount = Cache::remember('Analytics.comments.count', $minutes, function () { |
|
76
|
|
|
return BlogComment::count(); |
|
77
|
|
|
}); |
|
78
|
|
|
$viewDatas[] = 'commentsCount'; |
|
79
|
|
|
|
|
80
|
|
|
$breadcrumbs = $this->breadcrumbs; |
|
81
|
|
|
$viewDatas[] = 'breadcrumbs'; |
|
82
|
|
|
|
|
83
|
|
|
return view( |
|
84
|
|
|
'Admin.page.index', |
|
85
|
|
|
compact($viewDatas) |
|
86
|
|
|
); |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
|