-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathEvents.php
More file actions
65 lines (52 loc) · 1.89 KB
/
Copy pathEvents.php
File metadata and controls
65 lines (52 loc) · 1.89 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
<?php
namespace humhub\modules\share_events;
use Yii;
use humhub\modules\user\models\User;
use humhub\modules\calendar\models\CalendarEntry;
use humhub\modules\share\models\ShareEntry;
use humhub\modules\share\widgets\ShareLink;
/**
* MentionSpacesEvents
*/
class Events extends \yii\base\Object
{
public static function onCalendarGetTypes($event)
{
$event->addType('share', [
'title' => 'Shared event',
'icon' => 'fa-share-alt',
]);
}
static function toCalendarItem($entry)
{
// wtf? we need this, because returning $entry directly fucks up with
// modal loading and return getFullCalendarArray fucks up on stream
// view because start isn't a date.
$item = $entry->fullCalendarArray;
$item['start'] = $entry->getStartDateTime();
$item['end'] = $entry->getEndDateTime();
return $item;
}
public static function onCalendarFindItems($event)
{
$contentContainer = $event->contentContainer;
if(!$contentContainer || !$contentContainer->isModuleEnabled('calendar'))
return;
$share_entries = ShareEntry::find()
->join('join', 'content', 'content.object_id = share_entry.id')
->where([
'content.object_model' => ShareEntry::className(),
'content.contentcontainer_id' => $contentContainer->contentcontainer_id
]);
$calendar = CalendarEntry::find()
->join('join', 'content', 'content.object_id = calendar_entry.id')
->innerJoin(['share' => $share_entries], 'share.entry = content.id')
->where([
'content.object_model' => CalendarEntry::className(),
]);
$event->addItems('share', array_map(
function($entry) { return Events::toCalendarItem($entry); },
$calendar->all()
));
}
}