forked from ColdTrick/event_manager
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEntity.php
More file actions
182 lines (151 loc) · 4.86 KB
/
Entity.php
File metadata and controls
182 lines (151 loc) · 4.86 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
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
<?php
namespace ColdTrick\EventManager\Menus;
use Elgg\Menu\MenuItems;
/**
* Entity menu related callbacks
*/
class Entity {
/**
* Register mail attendees to the entity menu
*
* @param \Elgg\Event $event 'register', 'menu:entity'
*
* @return null|MenuItems
*/
public static function registerMailAttendees(\Elgg\Event $event): ?MenuItems {
$entity = $event->getEntityParam();
if (!$entity instanceof \Event || !$entity->canEdit()) {
return null;
}
if (!elgg_get_plugin_setting('event_mail', 'event_manager')) {
return null;
}
$result = $event->getValue();
$result[] = \ElggMenuItem::factory([
'name' => 'event_mail',
'icon' => 'envelope',
'text' => elgg_echo('event_manager:menu:mail'),
'href' => elgg_generate_entity_url($entity, 'mail'),
]);
return $result;
}
/**
* Adds menu items to the attendees entity menu
*
* @param \Elgg\Event $elgg_event 'register', 'menu:entity'
*
* @return null|MenuItems
*/
public static function registerAttendeeActions(\Elgg\Event $elgg_event): ?MenuItems {
$entity = $elgg_event->getEntityParam();
if (!$entity instanceof \ElggUser && !$entity instanceof \EventRegistration) {
return null;
}
$route = _elgg_services()->request->getRoute();
if (!$route || ($route->getName() !== 'collection:object:event:attendees') && (elgg_extract('segments', $route->getMatchedParameters()) !== 'view/event_manager/event/attendees_list')) {
return null;
}
$event = get_entity((int) elgg_extract('guid', $route->getMatchedParameters(), get_input('guid')));
if (!$event instanceof \Event) {
return null;
}
if (!$event->canEdit()) {
return null;
}
$result = $elgg_event->getValue();
// no delete menu item
$result->remove('delete');
// kick from event (assumes users listed on the view page of an event)
$result[] = \ElggMenuItem::factory([
'name' => 'event_manager_kick',
'icon' => 'user-times',
'text' => elgg_echo('event_manager:event:relationship:kick'),
'href' => elgg_generate_action_url('event_manager/event/rsvp', [
'guid' => $event->guid,
'user' => $entity->guid,
'type' => EVENT_MANAGER_RELATION_UNDO,
]),
'section' => 'action',
]);
$user_relationship = $event->getRelationshipByUser($entity->guid);
if ($user_relationship === EVENT_MANAGER_RELATION_ATTENDING_PENDING) {
$result[] = \ElggMenuItem::factory([
'name' => 'event_manager_resend_confirmation',
'icon' => 'user-times',
'text' => elgg_echo('event_manager:event:menu:user_hover:resend_confirmation'),
'href' => elgg_generate_action_url('event_manager/event/resend_confirmation', [
'guid' => $event->guid,
'user' => $entity->guid,
]),
'section' => 'action',
]);
}
if (in_array($user_relationship, [EVENT_MANAGER_RELATION_ATTENDING_PENDING, EVENT_MANAGER_RELATION_ATTENDING_WAITINGLIST])) {
$result[] = \ElggMenuItem::factory([
'name' => 'event_manager_move_to_attendees',
'icon' => 'user-times',
'text' => elgg_echo('event_manager:event:menu:user_hover:move_to_attendees'),
'href' => elgg_generate_action_url('event_manager/attendees/move_to_attendees', [
'guid' => $event->guid,
'user' => $entity->guid,
]),
'section' => 'action',
]);
}
return $result;
}
/**
* Adds menu items to the event entity menu for non logged in users
*
* @param \Elgg\Event $event 'register', 'menu:entity'
*
* @return null|MenuItems
*/
public static function registerEventUnsubscribe(\Elgg\Event $event): ?MenuItems {
$entity = $event->getEntityParam();
if (!$entity instanceof \Event) {
return null;
}
if (elgg_is_logged_in() || !$entity->register_nologin) {
return null;
}
// show an unregister link for non logged in users
$result = $event->getValue();
$result[] = \ElggMenuItem::factory([
'name' => 'unsubscribe',
'icon' => 'sign-out-alt',
'text' => elgg_echo('event_manager:menu:unsubscribe'),
'href' => elgg_generate_url('default:object:event:unsubscribe:request', [
'guid' => $entity->guid,
]),
'priority' => 300,
]);
return $result;
}
/**
* Adds menu items to the event entity menu for exporting it to ical
*
* @param \Elgg\Event $event 'register', 'menu:entity'
*
* @return null|MenuItems
*/
public static function registerICalExport(\Elgg\Event $event): ?MenuItems {
$entity = $event->getEntityParam();
if (!$entity instanceof \Event) {
return null;
}
if (!elgg_get_plugin_setting('ical_direct', 'event_manager')) {
return null;
}
// show an ical export link
$result = $event->getValue();
$result[] = \ElggMenuItem::factory([
'name' => 'ical-export',
'icon' => 'calendar-plus',
'text' => elgg_echo('event_manager:ical_direct:export'),
'href' => elgg_generate_action_url('event_manager/export/ical', ['event_id' => $entity->guid]),
'priority' => 300,
]);
return $result;
}
}