Repository navigation
Expand file tree
/
Copy pathEvents.php
More file actions
67 lines (58 loc) · 2.02 KB
/
Copy pathEvents.php
File metadata and controls
67 lines (58 loc) · 2.02 KB
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
<?php
/**
* User Location Map
*
* @package humhub.modules.usermap
* @author KeudellCoding
*/
namespace humhub\modules\usermap;
use humhub\modules\ui\menu\MenuLink;
use humhub\modules\usermap\jobs\GeocodeAddress;
use humhub\modules\usermap\widgets\MapView;
use Yii;
use yii\helpers\Url;
use yii\queue\ExecEvent;
class Events
{
public static function onTopMenuInit($event): void
{
$module = Yii::$app->getModule('usermap');
if (Yii::$app->user->isGuest || $module->getMapWidgetLocation() !== 'top_menu') {
return;
}
$controller = Yii::$app->controller;
$event->sender->addEntry(new MenuLink([
'label' => Yii::t('UsermapModule.base', 'Usermap'),
'url' => ['/usermap/map'],
'icon' => 'map-marker',
'isActive' => $controller && $controller->module->id === 'usermap' && $controller->id === 'map',
'sortOrder' => (int) $module->settings->get('map_widget_location_sort_order', 400),
]));
}
public static function onDashboardSidebarInit($event): void
{
$module = Yii::$app->getModule('usermap');
if (Yii::$app->user->isGuest || $module->getMapWidgetLocation() !== 'dashboard_sidebar') {
return;
}
$event->sender->addWidget(MapView::class, [
'id' => 'usermap-dashboard-map',
'height' => '20em',
'showAsPanel' => true,
'link' => Url::to(['/usermap/map']),
], ['sortOrder' => (int) $module->settings->get('map_widget_location_sort_order', 400)]);
}
public static function onAfterUpdate($event): void
{
if ($event->moduleId === 'usermap') {
$module = Yii::$app->getModule('usermap');
$module->settings->set('map_widget_location', $module->getMapWidgetLocation());
}
}
public static function onQueueAfterExec(ExecEvent $event): void
{
if ($event->job instanceof GeocodeAddress) {
$event->job->releaseReservation($event->id);
}
}
}