-
Notifications
You must be signed in to change notification settings - Fork 14
/
Events.php
112 lines (94 loc) · 3.17 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php
namespace humhub\modules\external_calendar;
use Yii;
use yii\helpers\Url;
use yii\base\BaseObject;
use humhub\modules\external_calendar\models\ExternalCalendarEntry;
use humhub\modules\external_calendar\integration\calendar\CalendarExtension;
use humhub\modules\external_calendar\jobs\SyncHourly;
use humhub\modules\external_calendar\jobs\SyncDaily;
use humhub\modules\external_calendar\widgets\DownloadIcsLink;
class Events extends BaseObject
{
/**
* @param $event \humhub\modules\calendar\interfaces\CalendarItemTypesEvent
* @return mixed
*/
public static function onGetCalendarItemTypes($event)
{
$contentContainer = $event->contentContainer;
if (!$contentContainer || $contentContainer->isModuleEnabled('external_calendar')) {
CalendarExtension::addItemTypes($event);
}
}
/**
* @param $event
*/
public static function onFindCalendarItems($event)
{
$contentContainer = $event->contentContainer;
if (!$contentContainer || $contentContainer->isModuleEnabled('external_calendar')) {
CalendarExtension::addItems($event);
}
}
/**
* Defines what to do if admin menu is initialized.
*
* @param $event
*/
public static function onAdminMenuInit($event)
{
$event->sender->addItem(array(
'label' => "external_calendar",
'url' => Url::to(['/external_calendar/admin']),
'group' => 'manage',
'icon' => '<i class="fa fa-certificate" style="color: #6fdbe8;"></i>',
'isActive' => (Yii::$app->controller->module && Yii::$app->controller->module->id == 'external_calendar' && Yii::$app->controller->id == 'admin'),
'sortOrder' => 99999,
));
}
/**
* Defines what to do if hourly cron runs.
*
* @param $event
* @return void
*/
public static function onCronHourlyRun($event)
{
Yii::$app->queue->push( new SyncHourly());
}
/**
* Defines what to do if daily cron runs.
*
* @param $event
* @return void
*/
public static function onCronDailyRun($event)
{
Yii::$app->queue->push( new SyncDaily());
}
/**
* Callback to validate module database records.
*
* @param Event $event
* @throws \Exception
*/
public static function onIntegrityCheck($event)
{
$integrityController = $event->sender;
$integrityController->showTestHeadline("External Calendar Module - Entries (" . ExternalCalendarEntry::find()->count() . " entries)");
foreach (ExternalCalendarEntry::find()->joinWith('calendar')->all() as $entry) {
if ($entry->calendar === null) {
if ($integrityController->showFix("Deleting external calendar entry id " . $entry->id . " without existing calendar!")) {
$entry->delete();
}
}
}
}
public static function onWallEntryLinks($event)
{
if ($event->sender->object instanceof ExternalCalendarEntry) {
$event->sender->addWidget(DownloadIcsLink::class, ['calendarEntry' => $event->sender->object]);
}
}
}