forked from KeudellCoding/HumHub-Modules-UserMap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEvents.php
81 lines (72 loc) · 2.65 KB
/
Events.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
/**
* User Location Map
*
* @package humhub.modules.usermap
* @author KeudellCoding
*/
namespace humhub\modules\usermap;
use Yii;
use yii\helpers\Url;
use humhub\modules\usermap\widgets\MapView;
class Events {
public static function onTopMenuInit($event) {
try {
$settings = Yii::$app->getModule('usermap')->settings;
if ($settings->get('map_widget_location') !== 'top_menu') {
return;
}
$currentIdentity = Yii::$app->user->identity;
if ($currentIdentity === null || Yii::$app->user->isGuest) {
return;
}
$event->sender->addItem([
'label' => 'Usermap',
'url' => Url::to(['/usermap/map']),
'htmlOptions' => [],
'icon' => '<i class="fa fa-map-marker"></i>',
'isActive' => (Yii::$app->controller->module
&& Yii::$app->controller->module->id === 'usermap'
&& Yii::$app->controller->id === 'map'),
'sortOrder' => $settings->get('map_widget_location_sort_order', 400),
]);
} catch (\Throwable $e) {
Yii::error($e);
}
}
public static function onDashboardSidebarInit($event) {
try {
$settings = Yii::$app->getModule('usermap')->settings;
if ($settings->get('map_widget_location') !== 'dashboard_sidebar') {
return;
}
$currentIdentity = Yii::$app->user->identity;
if ($currentIdentity === null || Yii::$app->user->isGuest) {
return;
}
$event->sender->addWidget(
MapView::class,
[
'height' => '20em',
'showAsPanel' => true,
'link' => Url::to(['/usermap/map'])
],
['sortOrder' => $settings->get('map_widget_location_sort_order', 400)]
);
} catch (\Throwable $e) {
Yii::error($e);
}
}
public static function onAfterUpdate($event) {
if ($event->moduleId === 'usermap'){
try {
$settings = Yii::$app->getModule('usermap')->settings;
if ($settings->get('map_widget_location') === 'directory_menu' && version_compare(Yii::$app->version, '1.9.0', 'ge')) {
$settings->set('map_widget_location', 'top_menu');
}
} catch (\Throwable $e) {
Yii::error($e);
}
}
}
}