1
|
|
|
<?php namespace VojtaSvoboda\UserAccessLog; |
2
|
|
|
|
3
|
|
|
use Backend; |
4
|
|
|
use Event; |
5
|
|
|
use System\Classes\PluginBase; |
6
|
|
|
use System\Classes\SettingsManager; |
7
|
|
|
use VojtaSvoboda\UserAccessLog\Models\AccessLog; |
8
|
|
|
use VojtaSvoboda\UserAccessLog\Models\Settings; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* UserAccessLog Plugin Information File |
12
|
|
|
*/ |
13
|
|
|
class Plugin extends PluginBase |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* @var array Plugin dependencies |
17
|
|
|
*/ |
18
|
|
|
public $require = [ |
19
|
|
|
'RainLab.User', |
20
|
|
|
]; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Returns information about this plugin. |
24
|
|
|
* |
25
|
|
|
* @return array |
26
|
|
|
*/ |
27
|
|
|
public function pluginDetails() |
28
|
|
|
{ |
29
|
|
|
return [ |
30
|
|
|
'name' => 'vojtasvoboda.useraccesslog::lang.plugin.name', |
31
|
|
|
'description' => 'vojtasvoboda.useraccesslog::lang.plugin.description', |
32
|
|
|
'author' => 'Vojta Svoboda', |
33
|
|
|
'icon' => 'icon-user', |
34
|
|
|
'homepage' => 'https://github.com/vojtasvoboda/oc-useraccesslog-plugin' |
35
|
|
|
]; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function boot() |
39
|
|
|
{ |
40
|
|
|
// log user after login |
41
|
|
|
Event::listen('rainlab.user.login', function ($user) { |
42
|
|
|
AccessLog::add($user); |
43
|
|
|
}); |
44
|
|
|
|
45
|
|
|
// extend users side-menu with User Access log |
46
|
|
|
if (!empty(Settings::get('show_access_log_listing', false))) { |
47
|
|
|
Event::listen('backend.menu.extendItems', function ($manager) { |
48
|
|
|
$manager->addSideMenuItem('RainLab.User', 'user', 'access_log', [ |
49
|
|
|
'label' => 'backend::lang.access_log.menu_label', |
50
|
|
|
'url' => Backend::url('vojtasvoboda/useraccesslog/log'), |
51
|
|
|
'icon' => 'icon-list', |
52
|
|
|
'order' => 300, |
53
|
|
|
]); |
54
|
|
|
}); |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function registerReportWidgets() |
59
|
|
|
{ |
60
|
|
|
return [ |
61
|
|
|
'VojtaSvoboda\UserAccessLog\ReportWidgets\AccessLogStatistics' => [ |
62
|
|
|
'label' => 'vojtasvoboda.useraccesslog::lang.reportwidgets.statistics.label', |
63
|
|
|
'context' => 'dashboard', |
64
|
|
|
], |
65
|
|
|
'VojtaSvoboda\UserAccessLog\ReportWidgets\AccessLogChartLine' => [ |
66
|
|
|
'label' => 'vojtasvoboda.useraccesslog::lang.reportwidgets.chartline.label', |
67
|
|
|
'context' => 'dashboard', |
68
|
|
|
], |
69
|
|
|
'VojtaSvoboda\UserAccessLog\ReportWidgets\AccessLogChartLineAggregated' => [ |
70
|
|
|
'label' => 'vojtasvoboda.useraccesslog::lang.reportwidgets.chartlineaggregated.label', |
71
|
|
|
'context' => 'dashboard', |
72
|
|
|
], |
73
|
|
|
'VojtaSvoboda\UserAccessLog\ReportWidgets\Registrations' => [ |
74
|
|
|
'label' => 'vojtasvoboda.useraccesslog::lang.reportwidgets.registrations.label', |
75
|
|
|
'context' => 'dashboard', |
76
|
|
|
], |
77
|
|
|
]; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
public function registerSettings() |
81
|
|
|
{ |
82
|
|
|
return [ |
83
|
|
|
'config' => [ |
84
|
|
|
'label' => 'vojtasvoboda.useraccesslog::lang.settings.label', |
85
|
|
|
'category' => SettingsManager::CATEGORY_USERS, |
86
|
|
|
'icon' => 'icon-cog', |
87
|
|
|
'description' => 'vojtasvoboda.useraccesslog::lang.settings.description', |
88
|
|
|
'class' => Settings::class, |
89
|
|
|
'permissions' => ['vojtasvoboda.useraccesslog.*'], |
90
|
|
|
'order' => 600, |
91
|
|
|
] |
92
|
|
|
]; |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|