Passed
Push — master ( 22cae2...2bd8df )
by Jeroen
09:59
created
mod/groups/start.php 2 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -587,7 +587,7 @@  discard block
 block discarded – undo
587 587
  * @elgg_plugin_hook access_collection:display_name access_collection
588 588
  *
589 589
  * @param \Elgg\Hook $hook Hook
590
- * @return array
590
+ * @return null|string
591 591
  */
592 592
 function groups_set_access_collection_name(\Elgg\Hook $hook) {
593 593
 
@@ -811,7 +811,7 @@  discard block
 block discarded – undo
811 811
 /**
812 812
  * Runs unit tests for groups
813 813
  *
814
- * @return array
814
+ * @return string[]
815 815
  */
816 816
 function groups_test($hook, $type, $value, $params) {
817 817
 	$value[] = elgg_get_plugins_path() . 'groups/tests/write_access.php';
Please login to merge, or discard this patch.
Indentation   +681 added lines, -681 removed lines patch added patch discarded remove patch
@@ -15,91 +15,91 @@  discard block
 block discarded – undo
15 15
  */
16 16
 function groups_init() {
17 17
 
18
-	elgg_register_library('elgg:groups', __DIR__ . '/lib/groups.php');
19
-	elgg_load_library('elgg:groups');
18
+    elgg_register_library('elgg:groups', __DIR__ . '/lib/groups.php');
19
+    elgg_load_library('elgg:groups');
20 20
 	
21
-	// register group entities for search
22
-	elgg_register_entity_type('group', '');
21
+    // register group entities for search
22
+    elgg_register_entity_type('group', '');
23 23
 
24
-	// Set up the menu
25
-	$item = new ElggMenuItem('groups', elgg_echo('groups'), 'groups/all');
26
-	elgg_register_menu_item('site', $item);
24
+    // Set up the menu
25
+    $item = new ElggMenuItem('groups', elgg_echo('groups'), 'groups/all');
26
+    elgg_register_menu_item('site', $item);
27 27
 
28
-	// Register a page handler, so we can have nice URLs
29
-	elgg_register_page_handler('groups', 'groups_page_handler');
28
+    // Register a page handler, so we can have nice URLs
29
+    elgg_register_page_handler('groups', 'groups_page_handler');
30 30
 
31
-	// Register URL handlers for groups
32
-	elgg_register_plugin_hook_handler('entity:url', 'group', 'groups_set_url');
33
-	elgg_register_plugin_hook_handler('entity:icon:sizes', 'group', 'groups_set_icon_sizes');
31
+    // Register URL handlers for groups
32
+    elgg_register_plugin_hook_handler('entity:url', 'group', 'groups_set_url');
33
+    elgg_register_plugin_hook_handler('entity:icon:sizes', 'group', 'groups_set_icon_sizes');
34 34
 
35
-	// add group activity tool option
36
-	if (elgg_get_plugin_setting('allow_activity', 'groups') === 'yes') {
37
-		add_group_tool_option('activity', elgg_echo('groups:enableactivity'), true);
38
-		elgg_extend_view('groups/tool_latest', 'groups/profile/activity_module');
39
-	}
35
+    // add group activity tool option
36
+    if (elgg_get_plugin_setting('allow_activity', 'groups') === 'yes') {
37
+        add_group_tool_option('activity', elgg_echo('groups:enableactivity'), true);
38
+        elgg_extend_view('groups/tool_latest', 'groups/profile/activity_module');
39
+    }
40 40
 
41
-	// add link to owner block
42
-	elgg_register_plugin_hook_handler('register', 'menu:owner_block', 'groups_activity_owner_block_menu');
41
+    // add link to owner block
42
+    elgg_register_plugin_hook_handler('register', 'menu:owner_block', 'groups_activity_owner_block_menu');
43 43
 
44
-	// group entity menu
45
-	elgg_register_plugin_hook_handler('register', 'menu:entity', 'groups_entity_menu_setup');
44
+    // group entity menu
45
+    elgg_register_plugin_hook_handler('register', 'menu:entity', 'groups_entity_menu_setup');
46 46
 
47
-	// group user hover menu
48
-	elgg_register_plugin_hook_handler('register', 'menu:user_hover', 'groups_user_entity_menu_setup');
47
+    // group user hover menu
48
+    elgg_register_plugin_hook_handler('register', 'menu:user_hover', 'groups_user_entity_menu_setup');
49 49
 
50
-	// invitation request actions
51
-	elgg_register_plugin_hook_handler('register', 'menu:invitationrequest', 'groups_invitationrequest_menu_setup');
50
+    // invitation request actions
51
+    elgg_register_plugin_hook_handler('register', 'menu:invitationrequest', 'groups_invitationrequest_menu_setup');
52 52
 
53
-	// group members tabs
54
-	elgg_register_plugin_hook_handler('register', 'menu:groups_members', 'groups_members_menu_setup');
53
+    // group members tabs
54
+    elgg_register_plugin_hook_handler('register', 'menu:groups_members', 'groups_members_menu_setup');
55 55
 
56
-	//extend some views
57
-	elgg_extend_view('elgg.css', 'groups/css');
58
-	if (_elgg_view_may_be_altered('groups/js', __DIR__ . '/views/default/groups/js.php')) {
59
-		elgg_deprecated_notice('groups/js view has been deprecated. Use AMD modules instead', '2.2');
60
-		elgg_extend_view('elgg.js', 'groups/js');
61
-	}
56
+    //extend some views
57
+    elgg_extend_view('elgg.css', 'groups/css');
58
+    if (_elgg_view_may_be_altered('groups/js', __DIR__ . '/views/default/groups/js.php')) {
59
+        elgg_deprecated_notice('groups/js view has been deprecated. Use AMD modules instead', '2.2');
60
+        elgg_extend_view('elgg.js', 'groups/js');
61
+    }
62 62
 
63
-	// Access permissions
64
-	elgg_register_plugin_hook_handler('access:collections:write', 'all', 'groups_write_acl_plugin_hook', 600);
65
-	elgg_register_plugin_hook_handler('default', 'access', 'groups_access_default_override');
66
-	elgg_register_plugin_hook_handler('access_collection:name', 'access_collection', 'groups_set_access_collection_name');
63
+    // Access permissions
64
+    elgg_register_plugin_hook_handler('access:collections:write', 'all', 'groups_write_acl_plugin_hook', 600);
65
+    elgg_register_plugin_hook_handler('default', 'access', 'groups_access_default_override');
66
+    elgg_register_plugin_hook_handler('access_collection:name', 'access_collection', 'groups_set_access_collection_name');
67 67
 
68
-	// Register profile menu hook
69
-	elgg_register_plugin_hook_handler('profile_menu', 'profile', 'activity_profile_menu');
68
+    // Register profile menu hook
69
+    elgg_register_plugin_hook_handler('profile_menu', 'profile', 'activity_profile_menu');
70 70
 
71
-	// allow ecml in profiles
72
-	elgg_register_plugin_hook_handler('get_views', 'ecml', 'groupprofile_ecml_views_hook');
71
+    // allow ecml in profiles
72
+    elgg_register_plugin_hook_handler('get_views', 'ecml', 'groupprofile_ecml_views_hook');
73 73
 
74
-	// Register a handler for create groups
75
-	elgg_register_event_handler('create', 'group', 'groups_create_event_listener');
76
-	elgg_register_event_handler('update:after', 'group', 'groups_update_event_listener');
74
+    // Register a handler for create groups
75
+    elgg_register_event_handler('create', 'group', 'groups_create_event_listener');
76
+    elgg_register_event_handler('update:after', 'group', 'groups_update_event_listener');
77 77
 
78
-	elgg_register_event_handler('join', 'group', 'groups_user_join_event_listener');
79
-	elgg_register_event_handler('leave', 'group', 'groups_user_leave_event_listener');
78
+    elgg_register_event_handler('join', 'group', 'groups_user_join_event_listener');
79
+    elgg_register_event_handler('leave', 'group', 'groups_user_leave_event_listener');
80 80
 
81
-	elgg_register_plugin_hook_handler('access:collections:add_user', 'collection', 'groups_access_collection_override');
81
+    elgg_register_plugin_hook_handler('access:collections:add_user', 'collection', 'groups_access_collection_override');
82 82
 
83
-	elgg_register_event_handler('upgrade', 'system', 'groups_run_upgrades');
83
+    elgg_register_event_handler('upgrade', 'system', 'groups_run_upgrades');
84 84
 
85
-	// Add tests
86
-	elgg_register_plugin_hook_handler('unit_test', 'system', 'groups_test');
85
+    // Add tests
86
+    elgg_register_plugin_hook_handler('unit_test', 'system', 'groups_test');
87 87
 
88
-	// allow to be liked
89
-	elgg_register_plugin_hook_handler('likes:is_likable', 'group:', 'Elgg\Values::getTrue');
88
+    // allow to be liked
89
+    elgg_register_plugin_hook_handler('likes:is_likable', 'group:', 'Elgg\Values::getTrue');
90 90
 
91
-	// prepare profile buttons to be registered in the title menu
92
-	elgg_register_plugin_hook_handler('profile_buttons', 'group', 'groups_prepare_profile_buttons');
91
+    // prepare profile buttons to be registered in the title menu
92
+    elgg_register_plugin_hook_handler('profile_buttons', 'group', 'groups_prepare_profile_buttons');
93 93
 
94
-	// Help core resolve page owner guids from group routes
95
-	// Registered with an earlier priority to be called before default_page_owner_handler()
96
-	elgg_register_plugin_hook_handler('page_owner', 'system', 'groups_default_page_owner_handler', 400);
94
+    // Help core resolve page owner guids from group routes
95
+    // Registered with an earlier priority to be called before default_page_owner_handler()
96
+    elgg_register_plugin_hook_handler('page_owner', 'system', 'groups_default_page_owner_handler', 400);
97 97
 
98
-	// Setup filter tabs on /groups/all page
99
-	elgg_register_plugin_hook_handler('register', 'menu:filter:groups/all', 'groups_setup_filter_tabs');
98
+    // Setup filter tabs on /groups/all page
99
+    elgg_register_plugin_hook_handler('register', 'menu:filter:groups/all', 'groups_setup_filter_tabs');
100 100
 
101
-	elgg_register_plugin_hook_handler('register', 'menu:page', '_groups_page_menu_group_profile');
102
-	elgg_register_plugin_hook_handler('register', 'menu:page', '_groups_page_menu');
101
+    elgg_register_plugin_hook_handler('register', 'menu:page', '_groups_page_menu_group_profile');
102
+    elgg_register_plugin_hook_handler('register', 'menu:page', '_groups_page_menu');
103 103
 }
104 104
 
105 105
 /**
@@ -112,26 +112,26 @@  discard block
 block discarded – undo
112 112
  */
113 113
 function groups_fields_setup() {
114 114
 
115
-	$profile_defaults = [
116
-		'description' => 'longtext',
117
-		'briefdescription' => 'text',
118
-		'interests' => 'tags',
119
-	];
115
+    $profile_defaults = [
116
+        'description' => 'longtext',
117
+        'briefdescription' => 'text',
118
+        'interests' => 'tags',
119
+    ];
120 120
 
121
-	$profile_defaults = elgg_trigger_plugin_hook('profile:fields', 'group', null, $profile_defaults);
121
+    $profile_defaults = elgg_trigger_plugin_hook('profile:fields', 'group', null, $profile_defaults);
122 122
 
123
-	elgg_set_config('group', $profile_defaults);
123
+    elgg_set_config('group', $profile_defaults);
124 124
 
125
-	// register any tag metadata names
126
-	foreach ($profile_defaults as $name => $type) {
127
-		if ($type == 'tags') {
128
-			elgg_register_tag_metadata_name($name);
125
+    // register any tag metadata names
126
+    foreach ($profile_defaults as $name => $type) {
127
+        if ($type == 'tags') {
128
+            elgg_register_tag_metadata_name($name);
129 129
 
130
-			// only shows up in search but why not just set this in en.php as doing it here
131
-			// means you cannot override it in a plugin
132
-			add_translation(get_current_language(), ["tag_names:$name" => elgg_echo("groups:$name")]);
133
-		}
134
-	}
130
+            // only shows up in search but why not just set this in en.php as doing it here
131
+            // means you cannot override it in a plugin
132
+            add_translation(get_current_language(), ["tag_names:$name" => elgg_echo("groups:$name")]);
133
+        }
134
+    }
135 135
 }
136 136
 
137 137
 /**
@@ -149,43 +149,43 @@  discard block
 block discarded – undo
149 149
  */
150 150
 function _groups_page_menu_group_profile($hook, $type, $return, $params) {
151 151
 	
152
-	if (!elgg_in_context('group_profile') || !elgg_is_logged_in()) {
153
-		return;
154
-	}
152
+    if (!elgg_in_context('group_profile') || !elgg_is_logged_in()) {
153
+        return;
154
+    }
155 155
 	
156
-	// Get the page owner entity
157
-	$page_owner = elgg_get_page_owner_entity();
158
-	if (!($page_owner instanceof ElggGroup)) {
159
-		return;
160
-	}
156
+    // Get the page owner entity
157
+    $page_owner = elgg_get_page_owner_entity();
158
+    if (!($page_owner instanceof ElggGroup)) {
159
+        return;
160
+    }
161 161
 	
162
-	if (!$page_owner->canEdit() || $page_owner->isPublicMembership()) {
163
-		return;
164
-	}
162
+    if (!$page_owner->canEdit() || $page_owner->isPublicMembership()) {
163
+        return;
164
+    }
165 165
 	
166
-	$count = elgg_get_entities_from_relationship([
167
-		'type' => 'user',
168
-		'relationship' => 'membership_request',
169
-		'relationship_guid' => $page_owner->guid,
170
-		'inverse_relationship' => true,
171
-		'count' => true,
172
-	]);
173
-
174
-	$text = elgg_echo('groups:membershiprequests');
175
-	$title = $text;
176
-	if ($count) {
177
-		$title = elgg_echo('groups:membershiprequests:pending', [$count]);
178
-	}
166
+    $count = elgg_get_entities_from_relationship([
167
+        'type' => 'user',
168
+        'relationship' => 'membership_request',
169
+        'relationship_guid' => $page_owner->guid,
170
+        'inverse_relationship' => true,
171
+        'count' => true,
172
+    ]);
173
+
174
+    $text = elgg_echo('groups:membershiprequests');
175
+    $title = $text;
176
+    if ($count) {
177
+        $title = elgg_echo('groups:membershiprequests:pending', [$count]);
178
+    }
179 179
 	
180
-	$return[] = \ElggMenuItem::factory([
181
-		'name' => 'membership_requests',
182
-		'text' => $text,
183
-		'badge' => $count ? $count : null,
184
-		'title' => $title,
185
-		'href' => "groups/requests/{$page_owner->guid}",
186
-	]);
180
+    $return[] = \ElggMenuItem::factory([
181
+        'name' => 'membership_requests',
182
+        'text' => $text,
183
+        'badge' => $count ? $count : null,
184
+        'title' => $title,
185
+        'href' => "groups/requests/{$page_owner->guid}",
186
+    ]);
187 187
 	
188
-	return $return;
188
+    return $return;
189 189
 }
190 190
 
191 191
 /**
@@ -203,57 +203,57 @@  discard block
 block discarded – undo
203 203
  */
204 204
 function _groups_page_menu($hook, $type, $return, $params) {
205 205
 	
206
-	if (elgg_get_context() !== 'groups') {
207
-		return;
208
-	}
206
+    if (elgg_get_context() !== 'groups') {
207
+        return;
208
+    }
209 209
 	
210
-	// Get the page owner entity
211
-	$page_owner = elgg_get_page_owner_entity();
212
-	if ($page_owner instanceof ElggGroup) {
213
-		return;
214
-	}
210
+    // Get the page owner entity
211
+    $page_owner = elgg_get_page_owner_entity();
212
+    if ($page_owner instanceof ElggGroup) {
213
+        return;
214
+    }
215 215
 	
216
-	$return[] = \ElggMenuItem::factory([
217
-		'name' => 'groups:all',
218
-		'text' => elgg_echo('groups:all'),
219
-		'href' => 'groups/all',
220
-	]);
221
-
222
-	$user = elgg_get_logged_in_user_entity();
223
-	if (!$user) {
224
-		return $return;
225
-	}
216
+    $return[] = \ElggMenuItem::factory([
217
+        'name' => 'groups:all',
218
+        'text' => elgg_echo('groups:all'),
219
+        'href' => 'groups/all',
220
+    ]);
221
+
222
+    $user = elgg_get_logged_in_user_entity();
223
+    if (!$user) {
224
+        return $return;
225
+    }
226 226
 	
227
-	$return[] = \ElggMenuItem::factory([
228
-		'name' => 'groups:owned',
229
-		'text' => elgg_echo('groups:owned'),
230
-		'href' => "groups/owner/$user->username",
231
-	]);
227
+    $return[] = \ElggMenuItem::factory([
228
+        'name' => 'groups:owned',
229
+        'text' => elgg_echo('groups:owned'),
230
+        'href' => "groups/owner/$user->username",
231
+    ]);
232 232
 	
233
-	$return[] = \ElggMenuItem::factory([
234
-		'name' => 'groups:member',
235
-		'text' => elgg_echo('groups:yours'),
236
-		'href' => "groups/member/$user->username",
237
-	]);
238
-
239
-	$invitation_count = groups_get_invited_groups($user->guid, false, ['count' => true]);
240
-
241
-	// Invitations
242
-	$text = elgg_echo('groups:invitations');
243
-	$title = $text;
244
-	if ($invitation_count) {
245
-		$title = elgg_echo('groups:invitations:pending', [$invitation_count]);
246
-	}
247
-
248
-	$return[] = \ElggMenuItem::factory([
249
-		'name' => 'groups:user:invites',
250
-		'text' => $text,
251
-		'badge' => $invitation_count ? $invitation_count : null,
252
-		'title' => $title,
253
-		'href' => "groups/invitations/$user->username",
254
-	]);
255
-
256
-	return $return;
233
+    $return[] = \ElggMenuItem::factory([
234
+        'name' => 'groups:member',
235
+        'text' => elgg_echo('groups:yours'),
236
+        'href' => "groups/member/$user->username",
237
+    ]);
238
+
239
+    $invitation_count = groups_get_invited_groups($user->guid, false, ['count' => true]);
240
+
241
+    // Invitations
242
+    $text = elgg_echo('groups:invitations');
243
+    $title = $text;
244
+    if ($invitation_count) {
245
+        $title = elgg_echo('groups:invitations:pending', [$invitation_count]);
246
+    }
247
+
248
+    $return[] = \ElggMenuItem::factory([
249
+        'name' => 'groups:user:invites',
250
+        'text' => $text,
251
+        'badge' => $invitation_count ? $invitation_count : null,
252
+        'title' => $title,
253
+        'href' => "groups/invitations/$user->username",
254
+    ]);
255
+
256
+    return $return;
257 257
 }
258 258
 
259 259
 /**
@@ -277,48 +277,48 @@  discard block
 block discarded – undo
277 277
  */
278 278
 function groups_page_handler($page) {
279 279
 
280
-	if (!isset($page[0])) {
281
-		$page[0] = 'all';
282
-	}
283
-
284
-	elgg_push_breadcrumb(elgg_echo('groups'), "groups/all");
285
-
286
-	$vars = [];
287
-	switch ($page[0]) {
288
-		case 'add':
289
-		case 'all':
290
-		case 'owner':
291
-		case 'search':
292
-			echo elgg_view_resource("groups/{$page[0]}");
293
-			break;
294
-		case 'invitations':
295
-		case 'member':
296
-			echo elgg_view_resource("groups/{$page[0]}", [
297
-				'username' => $page[1],
298
-			]);
299
-			break;
300
-		case 'members':
301
-			$vars['sort'] = elgg_extract('2', $page, 'alpha');
302
-			$vars['guid'] = elgg_extract('1', $page);
303
-			if (elgg_view_exists("resources/groups/members/{$vars['sort']}")) {
304
-				echo elgg_view_resource("groups/members/{$vars['sort']}", $vars);
305
-			} else {
306
-				echo elgg_view_resource('groups/members', $vars);
307
-			}
308
-			break;
309
-		case 'profile':
310
-		case 'activity':
311
-		case 'edit':
312
-		case 'invite':
313
-		case 'requests':
314
-			echo elgg_view_resource("groups/{$page[0]}", [
315
-				'guid' => $page[1],
316
-			]);
317
-			break;
318
-		default:
319
-			return false;
320
-	}
321
-	return true;
280
+    if (!isset($page[0])) {
281
+        $page[0] = 'all';
282
+    }
283
+
284
+    elgg_push_breadcrumb(elgg_echo('groups'), "groups/all");
285
+
286
+    $vars = [];
287
+    switch ($page[0]) {
288
+        case 'add':
289
+        case 'all':
290
+        case 'owner':
291
+        case 'search':
292
+            echo elgg_view_resource("groups/{$page[0]}");
293
+            break;
294
+        case 'invitations':
295
+        case 'member':
296
+            echo elgg_view_resource("groups/{$page[0]}", [
297
+                'username' => $page[1],
298
+            ]);
299
+            break;
300
+        case 'members':
301
+            $vars['sort'] = elgg_extract('2', $page, 'alpha');
302
+            $vars['guid'] = elgg_extract('1', $page);
303
+            if (elgg_view_exists("resources/groups/members/{$vars['sort']}")) {
304
+                echo elgg_view_resource("groups/members/{$vars['sort']}", $vars);
305
+            } else {
306
+                echo elgg_view_resource('groups/members', $vars);
307
+            }
308
+            break;
309
+        case 'profile':
310
+        case 'activity':
311
+        case 'edit':
312
+        case 'invite':
313
+        case 'requests':
314
+            echo elgg_view_resource("groups/{$page[0]}", [
315
+                'guid' => $page[1],
316
+            ]);
317
+            break;
318
+        default:
319
+            return false;
320
+    }
321
+    return true;
322 322
 }
323 323
 
324 324
 /**
@@ -331,148 +331,148 @@  discard block
 block discarded – undo
331 331
  * @return string
332 332
  */
333 333
 function groups_set_url($hook, $type, $url, $params) {
334
-	$entity = $params['entity'];
335
-	$title = elgg_get_friendly_title($entity->name);
336
-	return "groups/profile/{$entity->guid}/$title";
334
+    $entity = $params['entity'];
335
+    $title = elgg_get_friendly_title($entity->name);
336
+    return "groups/profile/{$entity->guid}/$title";
337 337
 }
338 338
 
339 339
 /**
340 340
  * Add owner block link
341 341
  */
342 342
 function groups_activity_owner_block_menu($hook, $type, $return, $params) {
343
-	if (elgg_instanceof($params['entity'], 'group')) {
344
-		if ($params['entity']->activity_enable != "no") {
345
-			$url = "groups/activity/{$params['entity']->guid}";
346
-			$item = new ElggMenuItem('activity', elgg_echo('groups:activity'), $url);
347
-			$return[] = $item;
348
-		}
349
-	}
350
-
351
-	return $return;
343
+    if (elgg_instanceof($params['entity'], 'group')) {
344
+        if ($params['entity']->activity_enable != "no") {
345
+            $url = "groups/activity/{$params['entity']->guid}";
346
+            $item = new ElggMenuItem('activity', elgg_echo('groups:activity'), $url);
347
+            $return[] = $item;
348
+        }
349
+    }
350
+
351
+    return $return;
352 352
 }
353 353
 
354 354
 /**
355 355
  * Add links/info to entity menu particular to group entities
356 356
  */
357 357
 function groups_entity_menu_setup($hook, $type, $return, $params) {
358
-	if (elgg_in_context('widgets')) {
359
-		return $return;
360
-	}
361
-
362
-	/* @var ElggGroup $entity */
363
-	$entity = $params['entity'];
364
-	$handler = elgg_extract('handler', $params, false);
365
-	if ($handler != 'groups') {
366
-		return $return;
367
-	}
368
-
369
-	/* @var ElggMenuItem $item */
370
-	foreach ($return as $index => $item) {
371
-		if (in_array($item->getName(), ['likes', 'unlike', 'edit', 'delete'])) {
372
-			unset($return[$index]);
373
-		}
374
-	}
375
-
376
-	// membership type
377
-	if ($entity->isPublicMembership()) {
378
-		$mem = elgg_echo("groups:open");
379
-	} else {
380
-		$mem = elgg_echo("groups:closed");
381
-	}
382
-
383
-	$options = [
384
-		'name' => 'membership',
385
-		'text' => $mem,
386
-		'href' => false,
387
-		'priority' => 100,
388
-	];
389
-	$return[] = ElggMenuItem::factory($options);
390
-
391
-	// number of members
392
-	$num_members = $entity->getMembers(['count' => true]);
393
-	$members_string = elgg_echo('groups:member');
394
-	$options = [
395
-		'name' => 'members',
396
-		'text' => $num_members . ' ' . $members_string,
397
-		'href' => false,
398
-		'priority' => 200,
399
-	];
400
-	$return[] = ElggMenuItem::factory($options);
401
-
402
-	// feature link
403
-	if (elgg_is_admin_logged_in()) {
404
-		$isFeatured = $entity->featured_group == "yes";
405
-
406
-		$return[] = ElggMenuItem::factory([
407
-			'name' => 'feature',
408
-			'text' => elgg_echo("groups:makefeatured"),
409
-			'href' => elgg_add_action_tokens_to_url("action/groups/featured?group_guid={$entity->guid}&action_type=feature"),
410
-			'priority' => 300,
411
-			'item_class' => $isFeatured ? 'hidden' : '',
412
-			'deps' => 'groups/navigation',
413
-		]);
414
-
415
-		$return[] = ElggMenuItem::factory([
416
-			'name' => 'unfeature',
417
-			'text' => elgg_echo("groups:makeunfeatured"),
418
-			'href' => elgg_add_action_tokens_to_url("action/groups/featured?group_guid={$entity->guid}&action_type=unfeature"),
419
-			'priority' => 300,
420
-			'item_class' => $isFeatured ? '' : 'hidden',
421
-			'deps' => 'groups/navigation',
422
-		]);
423
-	}
424
-
425
-	return $return;
358
+    if (elgg_in_context('widgets')) {
359
+        return $return;
360
+    }
361
+
362
+    /* @var ElggGroup $entity */
363
+    $entity = $params['entity'];
364
+    $handler = elgg_extract('handler', $params, false);
365
+    if ($handler != 'groups') {
366
+        return $return;
367
+    }
368
+
369
+    /* @var ElggMenuItem $item */
370
+    foreach ($return as $index => $item) {
371
+        if (in_array($item->getName(), ['likes', 'unlike', 'edit', 'delete'])) {
372
+            unset($return[$index]);
373
+        }
374
+    }
375
+
376
+    // membership type
377
+    if ($entity->isPublicMembership()) {
378
+        $mem = elgg_echo("groups:open");
379
+    } else {
380
+        $mem = elgg_echo("groups:closed");
381
+    }
382
+
383
+    $options = [
384
+        'name' => 'membership',
385
+        'text' => $mem,
386
+        'href' => false,
387
+        'priority' => 100,
388
+    ];
389
+    $return[] = ElggMenuItem::factory($options);
390
+
391
+    // number of members
392
+    $num_members = $entity->getMembers(['count' => true]);
393
+    $members_string = elgg_echo('groups:member');
394
+    $options = [
395
+        'name' => 'members',
396
+        'text' => $num_members . ' ' . $members_string,
397
+        'href' => false,
398
+        'priority' => 200,
399
+    ];
400
+    $return[] = ElggMenuItem::factory($options);
401
+
402
+    // feature link
403
+    if (elgg_is_admin_logged_in()) {
404
+        $isFeatured = $entity->featured_group == "yes";
405
+
406
+        $return[] = ElggMenuItem::factory([
407
+            'name' => 'feature',
408
+            'text' => elgg_echo("groups:makefeatured"),
409
+            'href' => elgg_add_action_tokens_to_url("action/groups/featured?group_guid={$entity->guid}&action_type=feature"),
410
+            'priority' => 300,
411
+            'item_class' => $isFeatured ? 'hidden' : '',
412
+            'deps' => 'groups/navigation',
413
+        ]);
414
+
415
+        $return[] = ElggMenuItem::factory([
416
+            'name' => 'unfeature',
417
+            'text' => elgg_echo("groups:makeunfeatured"),
418
+            'href' => elgg_add_action_tokens_to_url("action/groups/featured?group_guid={$entity->guid}&action_type=unfeature"),
419
+            'priority' => 300,
420
+            'item_class' => $isFeatured ? '' : 'hidden',
421
+            'deps' => 'groups/navigation',
422
+        ]);
423
+    }
424
+
425
+    return $return;
426 426
 }
427 427
 
428 428
 /**
429 429
  * Add a remove user link to user hover menu when the page owner is a group
430 430
  */
431 431
 function groups_user_entity_menu_setup($hook, $type, $return, $params) {
432
-	if (elgg_is_logged_in()) {
433
-		$group = elgg_get_page_owner_entity();
434
-
435
-		// Check for valid group
436
-		if (!elgg_instanceof($group, 'group')) {
437
-			return $return;
438
-		}
439
-
440
-		$entity = $params['entity'];
441
-
442
-		// Make sure we have a user and that user is a member of the group
443
-		if (!elgg_instanceof($entity, 'user') || !$group->isMember($entity)) {
444
-			return $return;
445
-		}
446
-
447
-		// Add remove link if we can edit the group, and if we're not trying to remove the group owner
448
-		if ($group->canEdit() && $group->getOwnerGUID() != $entity->guid) {
449
-			$return[] = ElggMenuItem::factory([
450
-				'name' => 'removeuser',
451
-				'href' => "action/groups/remove?user_guid={$entity->guid}&group_guid={$group->guid}",
452
-				'text' => elgg_echo('groups:removeuser'),
453
-				'confirm' => true,
454
-				'priority' => 999,
455
-			]);
456
-		}
457
-	}
458
-
459
-	return $return;
432
+    if (elgg_is_logged_in()) {
433
+        $group = elgg_get_page_owner_entity();
434
+
435
+        // Check for valid group
436
+        if (!elgg_instanceof($group, 'group')) {
437
+            return $return;
438
+        }
439
+
440
+        $entity = $params['entity'];
441
+
442
+        // Make sure we have a user and that user is a member of the group
443
+        if (!elgg_instanceof($entity, 'user') || !$group->isMember($entity)) {
444
+            return $return;
445
+        }
446
+
447
+        // Add remove link if we can edit the group, and if we're not trying to remove the group owner
448
+        if ($group->canEdit() && $group->getOwnerGUID() != $entity->guid) {
449
+            $return[] = ElggMenuItem::factory([
450
+                'name' => 'removeuser',
451
+                'href' => "action/groups/remove?user_guid={$entity->guid}&group_guid={$group->guid}",
452
+                'text' => elgg_echo('groups:removeuser'),
453
+                'confirm' => true,
454
+                'priority' => 999,
455
+            ]);
456
+        }
457
+    }
458
+
459
+    return $return;
460 460
 }
461 461
 
462 462
 /**
463 463
  * Groups created so create an access list for it
464 464
  */
465 465
 function groups_create_event_listener($event, $object_type, $object) {
466
-	$ac_name = elgg_echo('groups:group') . ": " . $object->name;
467
-	$ac_id = create_access_collection($ac_name, $object->guid);
468
-	if ($ac_id) {
469
-		$object->group_acl = $ac_id;
470
-	} else {
471
-		// delete group if access creation fails
472
-		return false;
473
-	}
474
-
475
-	return true;
466
+    $ac_name = elgg_echo('groups:group') . ": " . $object->name;
467
+    $ac_id = create_access_collection($ac_name, $object->guid);
468
+    if ($ac_id) {
469
+        $object->group_acl = $ac_id;
470
+    } else {
471
+        // delete group if access creation fails
472
+        return false;
473
+    }
474
+
475
+    return true;
476 476
 }
477 477
 
478 478
 /**
@@ -493,38 +493,38 @@  discard block
 block discarded – undo
493 493
  */
494 494
 function groups_update_event_listener($event, $type, $group) {
495 495
 
496
-	/* @var $group \ElggGroup */
497
-
498
-	$original_attributes = $group->getOriginalAttributes();
499
-
500
-	if (!empty($original_attributes['owner_guid'])) {
501
-		$previous_owner_guid = $original_attributes['owner_guid'];
502
-
503
-		// Update owned metadata
504
-		$metadata = elgg_get_metadata([
505
-			'guid' => $group->guid,
506
-			'metadata_owner_guids' => $previous_owner_guid,
507
-			'limit' => 0,
508
-		]);
509
-
510
-		if ($metadata) {
511
-			foreach ($metadata as $md) {
512
-				$md->owner_guid = $group->owner_guid;
513
-				$md->save();
514
-			}
515
-		}
516
-	}
517
-
518
-	if (!empty($original_attributes['name'])) {
519
-		// update access collection name if group name changes
520
-		$group_name = html_entity_decode($group->name, ENT_QUOTES, 'UTF-8');
521
-		$ac_name = elgg_echo('groups:group') . ": " . $group_name;
522
-		$acl = get_access_collection($group->group_acl);
523
-		if ($acl) {
524
-			$acl->name = $ac_name;
525
-			$acl->save();
526
-		}
527
-	}
496
+    /* @var $group \ElggGroup */
497
+
498
+    $original_attributes = $group->getOriginalAttributes();
499
+
500
+    if (!empty($original_attributes['owner_guid'])) {
501
+        $previous_owner_guid = $original_attributes['owner_guid'];
502
+
503
+        // Update owned metadata
504
+        $metadata = elgg_get_metadata([
505
+            'guid' => $group->guid,
506
+            'metadata_owner_guids' => $previous_owner_guid,
507
+            'limit' => 0,
508
+        ]);
509
+
510
+        if ($metadata) {
511
+            foreach ($metadata as $md) {
512
+                $md->owner_guid = $group->owner_guid;
513
+                $md->save();
514
+            }
515
+        }
516
+    }
517
+
518
+    if (!empty($original_attributes['name'])) {
519
+        // update access collection name if group name changes
520
+        $group_name = html_entity_decode($group->name, ENT_QUOTES, 'UTF-8');
521
+        $ac_name = elgg_echo('groups:group') . ": " . $group_name;
522
+        $acl = get_access_collection($group->group_acl);
523
+        if ($acl) {
524
+            $acl->name = $ac_name;
525
+            $acl->save();
526
+        }
527
+    }
528 528
 }
529 529
 
530 530
 /**
@@ -537,48 +537,48 @@  discard block
 block discarded – undo
537 537
  */
538 538
 function groups_write_acl_plugin_hook(\Elgg\Hook $hook) {
539 539
 
540
-	$user_guid = $hook->getParam('user_id');
541
-	$user = get_user($user_guid);
542
-	if (!$user) {
543
-		return;
544
-	}
545
-
546
-	$page_owner = elgg_get_page_owner_entity();
547
-	if (!$page_owner instanceof ElggGroup) {
548
-		return;
549
-	}
550
-
551
-	if (!$page_owner->canWriteToContainer($user_guid)) {
552
-		return;
553
-	}
554
-
555
-	$allowed_access = [
556
-		ACCESS_PRIVATE,
557
-		$page_owner->group_acl,
558
-	];
559
-
560
-	if ($page_owner->getContentAccessMode() !== ElggGroup::CONTENT_ACCESS_MODE_MEMBERS_ONLY) {
561
-		$allowed_access[] = ACCESS_LOGGED_IN;
562
-		if (!elgg_get_config('walled_garden')) {
563
-			$allowed_access[] = ACCESS_PUBLIC;
564
-		}
565
-	}
566
-
567
-	$write_acls = $hook->getValue();
568
-
569
-	// add write access to the group
570
-	$collection = get_access_collection($page_owner->group_acl);
571
-	if ($collection) {
572
-		$write_acls[$page_owner->group_acl] = $collection->getDisplayName();
573
-	}
574
-
575
-	foreach (array_keys($write_acls) as $access_id) {
576
-		if (!in_array($access_id, $allowed_access)) {
577
-			unset($write_acls[$access_id]);
578
-		}
579
-	}
580
-
581
-	return $write_acls;
540
+    $user_guid = $hook->getParam('user_id');
541
+    $user = get_user($user_guid);
542
+    if (!$user) {
543
+        return;
544
+    }
545
+
546
+    $page_owner = elgg_get_page_owner_entity();
547
+    if (!$page_owner instanceof ElggGroup) {
548
+        return;
549
+    }
550
+
551
+    if (!$page_owner->canWriteToContainer($user_guid)) {
552
+        return;
553
+    }
554
+
555
+    $allowed_access = [
556
+        ACCESS_PRIVATE,
557
+        $page_owner->group_acl,
558
+    ];
559
+
560
+    if ($page_owner->getContentAccessMode() !== ElggGroup::CONTENT_ACCESS_MODE_MEMBERS_ONLY) {
561
+        $allowed_access[] = ACCESS_LOGGED_IN;
562
+        if (!elgg_get_config('walled_garden')) {
563
+            $allowed_access[] = ACCESS_PUBLIC;
564
+        }
565
+    }
566
+
567
+    $write_acls = $hook->getValue();
568
+
569
+    // add write access to the group
570
+    $collection = get_access_collection($page_owner->group_acl);
571
+    if ($collection) {
572
+        $write_acls[$page_owner->group_acl] = $collection->getDisplayName();
573
+    }
574
+
575
+    foreach (array_keys($write_acls) as $access_id) {
576
+        if (!in_array($access_id, $allowed_access)) {
577
+            unset($write_acls[$access_id]);
578
+        }
579
+    }
580
+
581
+    return $write_acls;
582 582
 }
583 583
 
584 584
 /**
@@ -591,25 +591,25 @@  discard block
 block discarded – undo
591 591
  */
592 592
 function groups_set_access_collection_name(\Elgg\Hook $hook) {
593 593
 
594
-	$access_collection = $hook->getParam('access_collection');
595
-	if (!$access_collection instanceof ElggAccessCollection) {
596
-		return;
597
-	}
594
+    $access_collection = $hook->getParam('access_collection');
595
+    if (!$access_collection instanceof ElggAccessCollection) {
596
+        return;
597
+    }
598 598
 
599
-	$owner = $access_collection->getOwnerEntity();
600
-	if (!$owner instanceof ElggGroup) {
601
-		return;
602
-	}
599
+    $owner = $access_collection->getOwnerEntity();
600
+    if (!$owner instanceof ElggGroup) {
601
+        return;
602
+    }
603 603
 	
604
-	$page_owner = elgg_get_page_owner_entity();
604
+    $page_owner = elgg_get_page_owner_entity();
605 605
 
606
-	if ($page_owner->guid == $owner->guid) {
607
-		return elgg_echo('groups:acl:in_context');
608
-	}
606
+    if ($page_owner->guid == $owner->guid) {
607
+        return elgg_echo('groups:acl:in_context');
608
+    }
609 609
 
610
-	if ($owner->canWriteToContainer()) {
611
-		return elgg_echo('groups:acl', [$owner->getDisplayName()]);
612
-	}
610
+    if ($owner->canWriteToContainer()) {
611
+        return elgg_echo('groups:acl', [$owner->getDisplayName()]);
612
+    }
613 613
 }
614 614
 
615 615
 /**
@@ -618,24 +618,24 @@  discard block
 block discarded – undo
618 618
  */
619 619
 function groups_user_join_event_listener($event, $object_type, $object) {
620 620
 
621
-	$group = $object['group'];
622
-	$user = $object['user'];
623
-	$acl = $group->group_acl;
621
+    $group = $object['group'];
622
+    $user = $object['user'];
623
+    $acl = $group->group_acl;
624 624
 
625
-	add_user_to_access_collection($user->guid, $acl);
625
+    add_user_to_access_collection($user->guid, $acl);
626 626
 
627
-	return true;
627
+    return true;
628 628
 }
629 629
 
630 630
 /**
631 631
  * Make sure users are added to the access collection
632 632
  */
633 633
 function groups_access_collection_override($hook, $entity_type, $returnvalue, $params) {
634
-	if (isset($params['collection'])) {
635
-		if (elgg_instanceof(get_entity($params['collection']->owner_guid), 'group')) {
636
-			return true;
637
-		}
638
-	}
634
+    if (isset($params['collection'])) {
635
+        if (elgg_instanceof(get_entity($params['collection']->owner_guid), 'group')) {
636
+            return true;
637
+        }
638
+    }
639 639
 }
640 640
 
641 641
 /**
@@ -644,13 +644,13 @@  discard block
 block discarded – undo
644 644
  */
645 645
 function groups_user_leave_event_listener($event, $object_type, $object) {
646 646
 
647
-	$group = $object['group'];
648
-	$user = $object['user'];
649
-	$acl = $group->group_acl;
647
+    $group = $object['group'];
648
+    $user = $object['user'];
649
+    $acl = $group->group_acl;
650 650
 
651
-	remove_user_from_access_collection($user->guid, $acl);
651
+    remove_user_from_access_collection($user->guid, $acl);
652 652
 
653
-	return true;
653
+    return true;
654 654
 }
655 655
 
656 656
 /**
@@ -664,15 +664,15 @@  discard block
 block discarded – undo
664 664
  * @return int
665 665
  */
666 666
 function groups_access_default_override($hook, $type, $access) {
667
-	$page_owner = elgg_get_page_owner_entity();
667
+    $page_owner = elgg_get_page_owner_entity();
668 668
 
669
-	if ($page_owner instanceof ElggGroup) {
670
-		if ($page_owner->getContentAccessMode() == ElggGroup::CONTENT_ACCESS_MODE_MEMBERS_ONLY) {
671
-			$access = $page_owner->group_acl;
672
-		}
673
-	}
669
+    if ($page_owner instanceof ElggGroup) {
670
+        if ($page_owner->getContentAccessMode() == ElggGroup::CONTENT_ACCESS_MODE_MEMBERS_ONLY) {
671
+            $access = $page_owner->group_acl;
672
+        }
673
+    }
674 674
 
675
-	return $access;
675
+    return $access;
676 676
 }
677 677
 
678 678
 /**
@@ -687,30 +687,30 @@  discard block
 block discarded – undo
687 687
  */
688 688
 function groups_get_invited_groups($user_guid, $return_guids = false, $options = []) {
689 689
 
690
-	$ia = elgg_set_ignore_access(true);
690
+    $ia = elgg_set_ignore_access(true);
691 691
 
692
-	$defaults = [
693
-		'relationship' => 'invited',
694
-		'relationship_guid' => (int) $user_guid,
695
-		'inverse_relationship' => true,
696
-		'limit' => 0,
697
-	];
692
+    $defaults = [
693
+        'relationship' => 'invited',
694
+        'relationship_guid' => (int) $user_guid,
695
+        'inverse_relationship' => true,
696
+        'limit' => 0,
697
+    ];
698 698
 
699
-	$options = array_merge($defaults, $options);
700
-	$groups = elgg_get_entities_from_relationship($options);
699
+    $options = array_merge($defaults, $options);
700
+    $groups = elgg_get_entities_from_relationship($options);
701 701
 
702
-	elgg_set_ignore_access($ia);
702
+    elgg_set_ignore_access($ia);
703 703
 
704
-	if ($return_guids) {
705
-		$guids = [];
706
-		foreach ($groups as $group) {
707
-			$guids[] = $group->getGUID();
708
-		}
704
+    if ($return_guids) {
705
+        $guids = [];
706
+        foreach ($groups as $group) {
707
+            $guids[] = $group->getGUID();
708
+        }
709 709
 
710
-		return $guids;
711
-	}
710
+        return $guids;
711
+    }
712 712
 
713
-	return $groups;
713
+    return $groups;
714 714
 }
715 715
 
716 716
 /**
@@ -722,30 +722,30 @@  discard block
 block discarded – undo
722 722
  */
723 723
 function groups_join_group($group, $user) {
724 724
 
725
-	// access ignore so user can be added to access collection of invisible group
726
-	$ia = elgg_set_ignore_access(true);
727
-	$result = $group->join($user);
728
-	elgg_set_ignore_access($ia);
725
+    // access ignore so user can be added to access collection of invisible group
726
+    $ia = elgg_set_ignore_access(true);
727
+    $result = $group->join($user);
728
+    elgg_set_ignore_access($ia);
729 729
 
730
-	if ($result) {
731
-		// flush user's access info so the collection is added
732
-		get_access_list($user->guid, 0, true);
730
+    if ($result) {
731
+        // flush user's access info so the collection is added
732
+        get_access_list($user->guid, 0, true);
733 733
 
734
-		// Remove any invite or join request flags
735
-		remove_entity_relationship($group->guid, 'invited', $user->guid);
736
-		remove_entity_relationship($user->guid, 'membership_request', $group->guid);
734
+        // Remove any invite or join request flags
735
+        remove_entity_relationship($group->guid, 'invited', $user->guid);
736
+        remove_entity_relationship($user->guid, 'membership_request', $group->guid);
737 737
 
738
-		elgg_create_river_item([
739
-			'view' => 'river/relationship/member/create',
740
-			'action_type' => 'join',
741
-			'subject_guid' => $user->guid,
742
-			'object_guid' => $group->guid,
743
-		]);
738
+        elgg_create_river_item([
739
+            'view' => 'river/relationship/member/create',
740
+            'action_type' => 'join',
741
+            'subject_guid' => $user->guid,
742
+            'object_guid' => $group->guid,
743
+        ]);
744 744
 
745
-		return true;
746
-	}
745
+        return true;
746
+    }
747 747
 
748
-	return false;
748
+    return false;
749 749
 }
750 750
 
751 751
 /**
@@ -757,55 +757,55 @@  discard block
 block discarded – undo
757 757
  */
758 758
 function group_access_options($group) {
759 759
 
760
-	$access_array = [
761
-		ACCESS_PRIVATE => elgg_echo('PRIVATE'),
762
-		ACCESS_LOGGED_IN => elgg_echo('LOGGED_IN'),
763
-	];
760
+    $access_array = [
761
+        ACCESS_PRIVATE => elgg_echo('PRIVATE'),
762
+        ACCESS_LOGGED_IN => elgg_echo('LOGGED_IN'),
763
+    ];
764 764
 
765
-	if (!elgg_get_config('walled_garden')) {
766
-		$access_array[ACCESS_PUBLIC] = elgg_echo('PUBLIC');
767
-	}
765
+    if (!elgg_get_config('walled_garden')) {
766
+        $access_array[ACCESS_PUBLIC] = elgg_echo('PUBLIC');
767
+    }
768 768
 
769
-	$collection = get_access_collection($group->group_acl);
770
-	if ($collection) {
771
-		$access_array[$collection->id] = $collection->getDisplayName();
772
-	}
769
+    $collection = get_access_collection($group->group_acl);
770
+    if ($collection) {
771
+        $access_array[$collection->id] = $collection->getDisplayName();
772
+    }
773 773
 	
774
-	return $access_array;
774
+    return $access_array;
775 775
 }
776 776
 
777 777
 function activity_profile_menu($hook, $entity_type, $return_value, $params) {
778 778
 
779
-	if (!$params['owner'] instanceof ElggGroup
780
-			|| elgg_get_plugin_setting('allow_activity', 'groups') === 'no') {
781
-		return;
782
-	}
779
+    if (!$params['owner'] instanceof ElggGroup
780
+            || elgg_get_plugin_setting('allow_activity', 'groups') === 'no') {
781
+        return;
782
+    }
783 783
 
784
-	$return_value[] = [
785
-		'text' => elgg_echo('groups:activity'),
786
-		'href' => "groups/activity/{$params['owner']->guid}"
787
-	];
788
-	return $return_value;
784
+    $return_value[] = [
785
+        'text' => elgg_echo('groups:activity'),
786
+        'href' => "groups/activity/{$params['owner']->guid}"
787
+    ];
788
+    return $return_value;
789 789
 }
790 790
 
791 791
 /**
792 792
  * Parse ECML on group profiles
793 793
  */
794 794
 function groupprofile_ecml_views_hook($hook, $entity_type, $return_value, $params) {
795
-	$return_value['groups/groupprofile'] = elgg_echo('groups:ecml:groupprofile');
795
+    $return_value['groups/groupprofile'] = elgg_echo('groups:ecml:groupprofile');
796 796
 
797
-	return $return_value;
797
+    return $return_value;
798 798
 }
799 799
 
800 800
 /**
801 801
  * Process upgrades for the groups plugin
802 802
  */
803 803
 function groups_run_upgrades() {
804
-	$path = __DIR__ . '/upgrades/';
805
-	$files = elgg_get_upgrade_files($path);
806
-	foreach ($files as $file) {
807
-		include "$path{$file}";
808
-	}
804
+    $path = __DIR__ . '/upgrades/';
805
+    $files = elgg_get_upgrade_files($path);
806
+    foreach ($files as $file) {
807
+        include "$path{$file}";
808
+    }
809 809
 }
810 810
 
811 811
 /**
@@ -814,8 +814,8 @@  discard block
 block discarded – undo
814 814
  * @return array
815 815
  */
816 816
 function groups_test($hook, $type, $value, $params) {
817
-	$value[] = elgg_get_plugins_path() . 'groups/tests/write_access.php';
818
-	return $value;
817
+    $value[] = elgg_get_plugins_path() . 'groups/tests/write_access.php';
818
+    return $value;
819 819
 }
820 820
 
821 821
 /**
@@ -829,46 +829,46 @@  discard block
 block discarded – undo
829 829
  */
830 830
 function groups_invitationrequest_menu_setup($hook, $type, $menu, $params) {
831 831
 
832
-	$group = elgg_extract('entity', $params);
833
-	$user = elgg_extract('user', $params);
834
-
835
-	if (!$group instanceof \ElggGroup) {
836
-		return $menu;
837
-	}
838
-
839
-	if (!$user instanceof \ElggUser || !$user->canEdit()) {
840
-		return $menu;
841
-	}
842
-
843
-	$accept_url = elgg_http_add_url_query_elements('action/groups/join', [
844
-		'user_guid' => $user->guid,
845
-		'group_guid' => $group->guid,
846
-	]);
847
-
848
-	$menu[] = \ElggMenuItem::factory([
849
-		'name' => 'accept',
850
-		'href' => $accept_url,
851
-		'is_action' => true,
852
-		'text' => elgg_echo('accept'),
853
-		'link_class' => 'elgg-button elgg-button-submit',
854
-		'is_trusted' => true,
855
-	]);
856
-
857
-	$delete_url = elgg_http_add_url_query_elements('action/groups/killinvitation', [
858
-		'user_guid' => $user->guid,
859
-		'group_guid' => $group->guid,
860
-	]);
861
-
862
-	$menu[] = \ElggMenuItem::factory([
863
-		'name' => 'delete',
864
-		'href' => $delete_url,
865
-		'is_action' => true,
866
-		'confirm' => elgg_echo('groups:invite:remove:check'),
867
-		'text' => elgg_echo('delete'),
868
-		'link_class' => 'elgg-button elgg-button-delete mlm',
869
-	]);
870
-
871
-	return $menu;
832
+    $group = elgg_extract('entity', $params);
833
+    $user = elgg_extract('user', $params);
834
+
835
+    if (!$group instanceof \ElggGroup) {
836
+        return $menu;
837
+    }
838
+
839
+    if (!$user instanceof \ElggUser || !$user->canEdit()) {
840
+        return $menu;
841
+    }
842
+
843
+    $accept_url = elgg_http_add_url_query_elements('action/groups/join', [
844
+        'user_guid' => $user->guid,
845
+        'group_guid' => $group->guid,
846
+    ]);
847
+
848
+    $menu[] = \ElggMenuItem::factory([
849
+        'name' => 'accept',
850
+        'href' => $accept_url,
851
+        'is_action' => true,
852
+        'text' => elgg_echo('accept'),
853
+        'link_class' => 'elgg-button elgg-button-submit',
854
+        'is_trusted' => true,
855
+    ]);
856
+
857
+    $delete_url = elgg_http_add_url_query_elements('action/groups/killinvitation', [
858
+        'user_guid' => $user->guid,
859
+        'group_guid' => $group->guid,
860
+    ]);
861
+
862
+    $menu[] = \ElggMenuItem::factory([
863
+        'name' => 'delete',
864
+        'href' => $delete_url,
865
+        'is_action' => true,
866
+        'confirm' => elgg_echo('groups:invite:remove:check'),
867
+        'text' => elgg_echo('delete'),
868
+        'link_class' => 'elgg-button elgg-button-delete mlm',
869
+    ]);
870
+
871
+    return $menu;
872 872
 }
873 873
 
874 874
 /**
@@ -883,26 +883,26 @@  discard block
 block discarded – undo
883 883
  */
884 884
 function groups_members_menu_setup($hook, $type, $menu, $params) {
885 885
 
886
-	$entity = elgg_extract('entity', $params);
887
-	if (empty($entity) || !($entity instanceof ElggGroup)) {
888
-		return;
889
-	}
890
-
891
-	$menu[] = ElggMenuItem::factory([
892
-		'name' => 'alpha',
893
-		'text' => elgg_echo('sort:alpha'),
894
-		'href' => "groups/members/{$entity->getGUID()}",
895
-		'priority' => 100
896
-	]);
897
-
898
-	$menu[] = ElggMenuItem::factory([
899
-		'name' => 'newest',
900
-		'text' => elgg_echo('sort:newest'),
901
-		'href' => "groups/members/{$entity->getGUID()}/newest",
902
-		'priority' => 200
903
-	]);
904
-
905
-	return $menu;
886
+    $entity = elgg_extract('entity', $params);
887
+    if (empty($entity) || !($entity instanceof ElggGroup)) {
888
+        return;
889
+    }
890
+
891
+    $menu[] = ElggMenuItem::factory([
892
+        'name' => 'alpha',
893
+        'text' => elgg_echo('sort:alpha'),
894
+        'href' => "groups/members/{$entity->getGUID()}",
895
+        'priority' => 100
896
+    ]);
897
+
898
+    $menu[] = ElggMenuItem::factory([
899
+        'name' => 'newest',
900
+        'text' => elgg_echo('sort:newest'),
901
+        'href' => "groups/members/{$entity->getGUID()}/newest",
902
+        'priority' => 200
903
+    ]);
904
+
905
+    return $menu;
906 906
 }
907 907
 
908 908
 /**
@@ -916,48 +916,48 @@  discard block
 block discarded – undo
916 916
  */
917 917
 function groups_prepare_profile_buttons($hook, $type, $items, $params) {
918 918
 
919
-	$group = elgg_extract('entity', $params);
920
-	if (!$group instanceof ElggGroup) {
921
-		return;
922
-	}
923
-
924
-	$actions = [];
925
-
926
-	if ($group->canEdit()) {
927
-		// group owners can edit the group and invite new members
928
-		$actions['groups:edit'] = "groups/edit/{$group->guid}";
929
-		$actions['groups:invite'] = "groups/invite/{$group->guid}";
930
-	}
931
-
932
-	$user = elgg_get_logged_in_user_entity();
933
-	if ($user && $group->isMember($user)) {
934
-		if ($group->owner_guid != $user->guid) {
935
-			// a member can leave a group if he/she doesn't own it
936
-			$actions['groups:leave'] = "action/groups/leave?group_guid={$group->guid}";
937
-		}
938
-	} else if ($user) {
939
-		$url = "action/groups/join?group_guid={$group->guid}";
940
-		if ($group->isPublicMembership() || $group->canEdit()) {
941
-			// admins can always join
942
-			// non-admins can join if membership is public
943
-			$actions['groups:join'] = $url;
944
-		} else {
945
-			// request membership
946
-			$actions['groups:joinrequest'] = $url;
947
-		}
948
-	}
949
-
950
-	foreach ($actions as $action => $url) {
951
-		$items[] = ElggMenuItem::factory([
952
-			'name' => $action,
953
-			'href' => elgg_normalize_url($url),
954
-			'text' => elgg_echo($action),
955
-			'is_action' => 0 === strpos($url, 'action'),
956
-			'link_class' => 'elgg-button elgg-button-action',
957
-		]);
958
-	}
959
-
960
-	return $items;
919
+    $group = elgg_extract('entity', $params);
920
+    if (!$group instanceof ElggGroup) {
921
+        return;
922
+    }
923
+
924
+    $actions = [];
925
+
926
+    if ($group->canEdit()) {
927
+        // group owners can edit the group and invite new members
928
+        $actions['groups:edit'] = "groups/edit/{$group->guid}";
929
+        $actions['groups:invite'] = "groups/invite/{$group->guid}";
930
+    }
931
+
932
+    $user = elgg_get_logged_in_user_entity();
933
+    if ($user && $group->isMember($user)) {
934
+        if ($group->owner_guid != $user->guid) {
935
+            // a member can leave a group if he/she doesn't own it
936
+            $actions['groups:leave'] = "action/groups/leave?group_guid={$group->guid}";
937
+        }
938
+    } else if ($user) {
939
+        $url = "action/groups/join?group_guid={$group->guid}";
940
+        if ($group->isPublicMembership() || $group->canEdit()) {
941
+            // admins can always join
942
+            // non-admins can join if membership is public
943
+            $actions['groups:join'] = $url;
944
+        } else {
945
+            // request membership
946
+            $actions['groups:joinrequest'] = $url;
947
+        }
948
+    }
949
+
950
+    foreach ($actions as $action => $url) {
951
+        $items[] = ElggMenuItem::factory([
952
+            'name' => $action,
953
+            'href' => elgg_normalize_url($url),
954
+            'text' => elgg_echo($action),
955
+            'is_action' => 0 === strpos($url, 'action'),
956
+            'link_class' => 'elgg-button elgg-button-action',
957
+        ]);
958
+    }
959
+
960
+    return $items;
961 961
 }
962 962
 
963 963
 /**
@@ -973,54 +973,54 @@  discard block
 block discarded – undo
973 973
  */
974 974
 function groups_default_page_owner_handler($hook, $type, $return, $params) {
975 975
 
976
-	if ($return) {
977
-		return;
978
-	}
979
-
980
-	$segments = _elgg_services()->request->getUrlSegments();
981
-	$identifier = array_shift($segments);
982
-
983
-	if ($identifier !== 'groups') {
984
-		return;
985
-	}
986
-
987
-	$page = array_shift($segments);
988
-
989
-	switch ($page) {
990
-		case 'add' :
991
-			$guid = array_shift($segments);
992
-			if (!$guid) {
993
-				$guid = elgg_get_logged_in_user_guid();
994
-			}
995
-			return $guid;
996
-
997
-		case 'edit':
998
-		case 'profile' :
999
-		case 'activity' :
1000
-		case 'invite' :
1001
-		case 'requests' :
1002
-		case 'members' :
1003
-		case 'profile' :
1004
-			$guid = array_shift($segments);
1005
-			if (!$guid) {
1006
-				return;
1007
-			}
1008
-			return $guid;
1009
-
1010
-		case 'member' :
1011
-		case 'owner' :
1012
-		case 'invitations':
1013
-			$username = array_shift($segments);
1014
-			if ($username) {
1015
-				$user = get_user_by_username($username);
1016
-			} else {
1017
-				$user = elgg_get_logged_in_user_entity();
1018
-			}
1019
-			if (!$user) {
1020
-				return;
1021
-			}
1022
-			return $user->guid;
1023
-	}
976
+    if ($return) {
977
+        return;
978
+    }
979
+
980
+    $segments = _elgg_services()->request->getUrlSegments();
981
+    $identifier = array_shift($segments);
982
+
983
+    if ($identifier !== 'groups') {
984
+        return;
985
+    }
986
+
987
+    $page = array_shift($segments);
988
+
989
+    switch ($page) {
990
+        case 'add' :
991
+            $guid = array_shift($segments);
992
+            if (!$guid) {
993
+                $guid = elgg_get_logged_in_user_guid();
994
+            }
995
+            return $guid;
996
+
997
+        case 'edit':
998
+        case 'profile' :
999
+        case 'activity' :
1000
+        case 'invite' :
1001
+        case 'requests' :
1002
+        case 'members' :
1003
+        case 'profile' :
1004
+            $guid = array_shift($segments);
1005
+            if (!$guid) {
1006
+                return;
1007
+            }
1008
+            return $guid;
1009
+
1010
+        case 'member' :
1011
+        case 'owner' :
1012
+        case 'invitations':
1013
+            $username = array_shift($segments);
1014
+            if ($username) {
1015
+                $user = get_user_by_username($username);
1016
+            } else {
1017
+                $user = elgg_get_logged_in_user_entity();
1018
+            }
1019
+            if (!$user) {
1020
+                return;
1021
+            }
1022
+            return $user->guid;
1023
+    }
1024 1024
 }
1025 1025
 
1026 1026
 /**
@@ -1034,41 +1034,41 @@  discard block
 block discarded – undo
1034 1034
  */
1035 1035
 function groups_setup_filter_tabs($hook, $type, $return, $params) {
1036 1036
 
1037
-	$filter_value = elgg_extract('filter_value', $params);
1038
-
1039
-	$return[] = ElggMenuItem::factory([
1040
-		'name' => 'newest',
1041
-		'text' => elgg_echo('sort:newest'),
1042
-		'href' => 'groups/all?filter=newest',
1043
-		'priority' => 200,
1044
-		'selected' => $filter_value == 'newest',
1045
-	]);
1046
-
1047
-	$return[] = ElggMenuItem::factory([
1048
-		'name' => 'alpha',
1049
-		'text' => elgg_echo('sort:alpha'),
1050
-		'href' => 'groups/all?filter=alpha',
1051
-		'priority' => 250,
1052
-		'selected' => $filter_value == 'alpha',
1053
-	]);
1054
-
1055
-	$return[] = ElggMenuItem::factory([
1056
-		'name' => 'popular',
1057
-		'text' => elgg_echo('sort:popular'),
1058
-		'href' => 'groups/all?filter=popular',
1059
-		'priority' => 300,
1060
-		'selected' => $filter_value == 'popular',
1061
-	]);
1062
-
1063
-	$return[] = ElggMenuItem::factory([
1064
-		'name' => 'featured',
1065
-		'text' => elgg_echo('groups:featured'),
1066
-		'href' => 'groups/all?filter=featured',
1067
-		'priority' => 400,
1068
-		'selected' => $filter_value == 'featured',
1069
-	]);
1037
+    $filter_value = elgg_extract('filter_value', $params);
1038
+
1039
+    $return[] = ElggMenuItem::factory([
1040
+        'name' => 'newest',
1041
+        'text' => elgg_echo('sort:newest'),
1042
+        'href' => 'groups/all?filter=newest',
1043
+        'priority' => 200,
1044
+        'selected' => $filter_value == 'newest',
1045
+    ]);
1046
+
1047
+    $return[] = ElggMenuItem::factory([
1048
+        'name' => 'alpha',
1049
+        'text' => elgg_echo('sort:alpha'),
1050
+        'href' => 'groups/all?filter=alpha',
1051
+        'priority' => 250,
1052
+        'selected' => $filter_value == 'alpha',
1053
+    ]);
1054
+
1055
+    $return[] = ElggMenuItem::factory([
1056
+        'name' => 'popular',
1057
+        'text' => elgg_echo('sort:popular'),
1058
+        'href' => 'groups/all?filter=popular',
1059
+        'priority' => 300,
1060
+        'selected' => $filter_value == 'popular',
1061
+    ]);
1062
+
1063
+    $return[] = ElggMenuItem::factory([
1064
+        'name' => 'featured',
1065
+        'text' => elgg_echo('groups:featured'),
1066
+        'href' => 'groups/all?filter=featured',
1067
+        'priority' => 400,
1068
+        'selected' => $filter_value == 'featured',
1069
+    ]);
1070 1070
 	
1071
-	return $return;
1071
+    return $return;
1072 1072
 }
1073 1073
 
1074 1074
 /**
@@ -1081,8 +1081,8 @@  discard block
 block discarded – undo
1081 1081
  */
1082 1082
 function groups_set_icon_sizes(\Elgg\Hook $hook) {
1083 1083
 
1084
-	$sizes = $hook->getValue();
1085
-	$sizes['original'] = [];
1084
+    $sizes = $hook->getValue();
1085
+    $sizes['original'] = [];
1086 1086
 
1087
-	return $sizes;
1087
+    return $sizes;
1088 1088
 }
Please login to merge, or discard this patch.
mod/groups/languages/en.php 1 patch
Indentation   +187 added lines, -187 removed lines patch added patch discarded remove patch
@@ -1,166 +1,166 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 return [
3 3
 
4
-	/**
5
-	 * Menu items and titles
6
-	 */
7
-	'groups' => "Groups",
8
-	'groups:owned' => "Groups I own",
9
-	'groups:owned:user' => 'Groups %s owns',
10
-	'groups:yours' => "My groups",
11
-	'groups:user' => "%s's groups",
12
-	'groups:all' => "All groups",
13
-	'groups:add' => "Create a new group",
14
-	'groups:edit' => "Edit group",
15
-	'groups:delete' => 'Delete group',
16
-	'groups:membershiprequests' => 'Manage join requests',
17
-	'groups:membershiprequests:pending' => 'Manage join requests (%s)',
18
-	'groups:invitations' => 'Group invitations',
19
-	'groups:invitations:pending' => 'Group invitations (%s)',
20
-
21
-	'groups:icon' => 'Group icon (leave blank to leave unchanged)',
22
-	'groups:name' => 'Group name',
23
-	'groups:username' => 'Group short name (displayed in URLs, alphanumeric characters only)',
24
-	'groups:description' => 'Description',
25
-	'groups:briefdescription' => 'Brief description',
26
-	'groups:interests' => 'Tags',
27
-	'groups:website' => 'Website',
28
-	'groups:members' => 'Group members',
29
-	'groups:my_status' => 'My status',
30
-	'groups:my_status:group_owner' => 'You own this group',
31
-	'groups:my_status:group_member' => 'You are in this group',
32
-	'groups:subscribed' => 'Group notifications are on',
33
-	'groups:unsubscribed' => 'Group notifications are off',
34
-
35
-	'groups:members:title' => 'Members of %s',
36
-	'groups:members:more' => "View all members",
37
-	'groups:membership' => "Group membership permissions",
38
-	'groups:content_access_mode' => "Accessibility of group content",
39
-	'groups:content_access_mode:warning' => "Warning: Changing this setting won't change the access permission of existing group content.",
40
-	'groups:content_access_mode:unrestricted' => "Unrestricted - Access depends on content-level settings",
41
-	'groups:content_access_mode:membersonly' => "Members Only - Non-members can never access group content",
42
-	'groups:access' => "Access permissions",
43
-	'groups:owner' => "Owner",
44
-	'groups:owner:warning' => "Warning: if you change this value, you will no longer be the owner of this group.",
45
-	'groups:widget:num_display' => 'Number of groups to display',
46
-	'groups:widget:membership' => 'Group membership',
47
-	'groups:widgets:description' => 'Display the groups you are a member of on your profile',
48
-
49
-	'groups:widget:group_activity:title' => 'Group activity',
50
-	'groups:widget:group_activity:description' => 'View the activity in one of your groups',
51
-	'groups:widget:group_activity:edit:select' => 'Select a group',
52
-	'groups:widget:group_activity:content:noactivity' => 'There is no activity in this group',
53
-	'groups:widget:group_activity:content:noselect' => 'Edit this widget to select a group',
54
-
55
-	'groups:noaccess' => 'No access to group',
56
-	'groups:ingroup' => 'in the group',
57
-	'groups:cantcreate' => 'You can not create a group. Only admins can.',
58
-	'groups:cantedit' => 'You can not edit this group',
59
-	'groups:saved' => 'Group saved',
60
-	'groups:save_error' => 'Group could not be saved',
61
-	'groups:featured' => 'Featured groups',
62
-	'groups:makeunfeatured' => 'Unfeature',
63
-	'groups:makefeatured' => 'Make featured',
64
-	'groups:featuredon' => '%s is now a featured group.',
65
-	'groups:unfeatured' => '%s has been removed from the featured groups.',
66
-	'groups:featured_error' => 'Invalid group.',
67
-	'groups:nofeatured' => 'No featured groups',
68
-	'groups:joinrequest' => 'Request membership',
69
-	'groups:join' => 'Join group',
70
-	'groups:leave' => 'Leave group',
71
-	'groups:invite' => 'Invite friends',
72
-	'groups:invite:title' => 'Invite friends to this group',
73
-	'groups:inviteto' => "Invite friends to '%s'",
74
-	'groups:nofriends' => "You have no friends left who have not been invited to this group.",
75
-	'groups:nofriendsatall' => 'You have no friends to invite!',
76
-	'groups:viagroups' => "via groups",
77
-	'groups:group' => "Group",
78
-	'groups:search:tags' => "tag",
79
-	'groups:search:title' => "Search for groups tagged with '%s'",
80
-	'groups:search:none' => "No matching groups were found",
81
-	'groups:search_in_group' => "Search in this group",
82
-	'groups:acl' => "Group: %s",
83
-	'groups:acl:in_context' => 'Group members',
84
-
85
-	'groups:activity' => "Group activity",
86
-	'groups:enableactivity' => 'Enable group activity',
87
-	'groups:activity:none' => "There is no group activity yet",
88
-
89
-	'groups:notfound' => "Group not found",
90
-	'groups:notfound:details' => "The requested group either does not exist or you do not have access to it",
91
-
92
-	'groups:requests:none' => 'There are no current membership requests.',
93
-
94
-	'groups:invitations:none' => 'There are no current invitations.',
95
-
96
-	'groups:count' => "groups created",
97
-	'groups:open' => "open group",
98
-	'groups:closed' => "closed group",
99
-	'groups:member' => "members",
100
-	'groups:searchtag' => "Search for groups by tag",
101
-
102
-	'groups:more' => 'More groups',
103
-	'groups:none' => 'No groups',
104
-
105
-	/**
106
-	 * Access
107
-	 */
108
-	'groups:access:private' => 'Closed - Users must be invited',
109
-	'groups:access:public' => 'Open - Any user may join',
110
-	'groups:access:group' => 'Group members only',
111
-	'groups:closedgroup' => "This group's membership is closed.",
112
-	'groups:closedgroup:request' => 'To ask to be added, click the "Request membership" menu link.',
113
-	'groups:closedgroup:membersonly' => "This group's membership is closed and its content is accessible only by members.",
114
-	'groups:opengroup:membersonly' => "This group's content is accessible only by members.",
115
-	'groups:opengroup:membersonly:join' => 'To be a member, click the "Join group" menu link.',
116
-	'groups:visibility' => 'Who can see this group?',
117
-
118
-	/**
119
-	 * Group tools
120
-	 */
121
-	'groups:lastupdated' => 'Last updated %s by %s',
122
-	'groups:lastcomment' => 'Last comment %s by %s',
123
-
124
-	'admin:groups' => 'Groups',
125
-
126
-	'groups:privategroup' => 'This group is closed. Requesting membership.',
127
-	'groups:notitle' => 'Groups must have a title',
128
-	'groups:cantjoin' => 'Can not join group',
129
-	'groups:cantleave' => 'Could not leave group',
130
-	'groups:removeuser' => 'Remove from group',
131
-	'groups:cantremove' => 'Cannot remove user from group',
132
-	'groups:removed' => 'Successfully removed %s from group',
133
-	'groups:addedtogroup' => 'Successfully added the user to the group',
134
-	'groups:joinrequestnotmade' => 'Could not request to join group',
135
-	'groups:joinrequestmade' => 'Requested to join group',
136
-	'groups:joinrequest:exists' => 'You already requested membership for this group',
137
-	'groups:joined' => 'Successfully joined group!',
138
-	'groups:left' => 'Successfully left group',
139
-	'groups:notowner' => 'Sorry, you are not the owner of this group.',
140
-	'groups:notmember' => 'Sorry, you are not a member of this group.',
141
-	'groups:alreadymember' => 'You are already a member of this group!',
142
-	'groups:userinvited' => 'User has been invited.',
143
-	'groups:usernotinvited' => 'User could not be invited.',
144
-	'groups:useralreadyinvited' => 'User has already been invited',
145
-	'groups:invite:subject' => "%s you have been invited to join %s!",
146
-	'groups:started' => "Started by %s",
147
-	'groups:joinrequest:remove:check' => 'Are you sure you want to remove this join request?',
148
-	'groups:invite:remove:check' => 'Are you sure you want to remove this invitation?',
149
-	'groups:invite:body' => "Hi %s,
4
+    /**
5
+     * Menu items and titles
6
+     */
7
+    'groups' => "Groups",
8
+    'groups:owned' => "Groups I own",
9
+    'groups:owned:user' => 'Groups %s owns',
10
+    'groups:yours' => "My groups",
11
+    'groups:user' => "%s's groups",
12
+    'groups:all' => "All groups",
13
+    'groups:add' => "Create a new group",
14
+    'groups:edit' => "Edit group",
15
+    'groups:delete' => 'Delete group',
16
+    'groups:membershiprequests' => 'Manage join requests',
17
+    'groups:membershiprequests:pending' => 'Manage join requests (%s)',
18
+    'groups:invitations' => 'Group invitations',
19
+    'groups:invitations:pending' => 'Group invitations (%s)',
20
+
21
+    'groups:icon' => 'Group icon (leave blank to leave unchanged)',
22
+    'groups:name' => 'Group name',
23
+    'groups:username' => 'Group short name (displayed in URLs, alphanumeric characters only)',
24
+    'groups:description' => 'Description',
25
+    'groups:briefdescription' => 'Brief description',
26
+    'groups:interests' => 'Tags',
27
+    'groups:website' => 'Website',
28
+    'groups:members' => 'Group members',
29
+    'groups:my_status' => 'My status',
30
+    'groups:my_status:group_owner' => 'You own this group',
31
+    'groups:my_status:group_member' => 'You are in this group',
32
+    'groups:subscribed' => 'Group notifications are on',
33
+    'groups:unsubscribed' => 'Group notifications are off',
34
+
35
+    'groups:members:title' => 'Members of %s',
36
+    'groups:members:more' => "View all members",
37
+    'groups:membership' => "Group membership permissions",
38
+    'groups:content_access_mode' => "Accessibility of group content",
39
+    'groups:content_access_mode:warning' => "Warning: Changing this setting won't change the access permission of existing group content.",
40
+    'groups:content_access_mode:unrestricted' => "Unrestricted - Access depends on content-level settings",
41
+    'groups:content_access_mode:membersonly' => "Members Only - Non-members can never access group content",
42
+    'groups:access' => "Access permissions",
43
+    'groups:owner' => "Owner",
44
+    'groups:owner:warning' => "Warning: if you change this value, you will no longer be the owner of this group.",
45
+    'groups:widget:num_display' => 'Number of groups to display',
46
+    'groups:widget:membership' => 'Group membership',
47
+    'groups:widgets:description' => 'Display the groups you are a member of on your profile',
48
+
49
+    'groups:widget:group_activity:title' => 'Group activity',
50
+    'groups:widget:group_activity:description' => 'View the activity in one of your groups',
51
+    'groups:widget:group_activity:edit:select' => 'Select a group',
52
+    'groups:widget:group_activity:content:noactivity' => 'There is no activity in this group',
53
+    'groups:widget:group_activity:content:noselect' => 'Edit this widget to select a group',
54
+
55
+    'groups:noaccess' => 'No access to group',
56
+    'groups:ingroup' => 'in the group',
57
+    'groups:cantcreate' => 'You can not create a group. Only admins can.',
58
+    'groups:cantedit' => 'You can not edit this group',
59
+    'groups:saved' => 'Group saved',
60
+    'groups:save_error' => 'Group could not be saved',
61
+    'groups:featured' => 'Featured groups',
62
+    'groups:makeunfeatured' => 'Unfeature',
63
+    'groups:makefeatured' => 'Make featured',
64
+    'groups:featuredon' => '%s is now a featured group.',
65
+    'groups:unfeatured' => '%s has been removed from the featured groups.',
66
+    'groups:featured_error' => 'Invalid group.',
67
+    'groups:nofeatured' => 'No featured groups',
68
+    'groups:joinrequest' => 'Request membership',
69
+    'groups:join' => 'Join group',
70
+    'groups:leave' => 'Leave group',
71
+    'groups:invite' => 'Invite friends',
72
+    'groups:invite:title' => 'Invite friends to this group',
73
+    'groups:inviteto' => "Invite friends to '%s'",
74
+    'groups:nofriends' => "You have no friends left who have not been invited to this group.",
75
+    'groups:nofriendsatall' => 'You have no friends to invite!',
76
+    'groups:viagroups' => "via groups",
77
+    'groups:group' => "Group",
78
+    'groups:search:tags' => "tag",
79
+    'groups:search:title' => "Search for groups tagged with '%s'",
80
+    'groups:search:none' => "No matching groups were found",
81
+    'groups:search_in_group' => "Search in this group",
82
+    'groups:acl' => "Group: %s",
83
+    'groups:acl:in_context' => 'Group members',
84
+
85
+    'groups:activity' => "Group activity",
86
+    'groups:enableactivity' => 'Enable group activity',
87
+    'groups:activity:none' => "There is no group activity yet",
88
+
89
+    'groups:notfound' => "Group not found",
90
+    'groups:notfound:details' => "The requested group either does not exist or you do not have access to it",
91
+
92
+    'groups:requests:none' => 'There are no current membership requests.',
93
+
94
+    'groups:invitations:none' => 'There are no current invitations.',
95
+
96
+    'groups:count' => "groups created",
97
+    'groups:open' => "open group",
98
+    'groups:closed' => "closed group",
99
+    'groups:member' => "members",
100
+    'groups:searchtag' => "Search for groups by tag",
101
+
102
+    'groups:more' => 'More groups',
103
+    'groups:none' => 'No groups',
104
+
105
+    /**
106
+     * Access
107
+     */
108
+    'groups:access:private' => 'Closed - Users must be invited',
109
+    'groups:access:public' => 'Open - Any user may join',
110
+    'groups:access:group' => 'Group members only',
111
+    'groups:closedgroup' => "This group's membership is closed.",
112
+    'groups:closedgroup:request' => 'To ask to be added, click the "Request membership" menu link.',
113
+    'groups:closedgroup:membersonly' => "This group's membership is closed and its content is accessible only by members.",
114
+    'groups:opengroup:membersonly' => "This group's content is accessible only by members.",
115
+    'groups:opengroup:membersonly:join' => 'To be a member, click the "Join group" menu link.',
116
+    'groups:visibility' => 'Who can see this group?',
117
+
118
+    /**
119
+     * Group tools
120
+     */
121
+    'groups:lastupdated' => 'Last updated %s by %s',
122
+    'groups:lastcomment' => 'Last comment %s by %s',
123
+
124
+    'admin:groups' => 'Groups',
125
+
126
+    'groups:privategroup' => 'This group is closed. Requesting membership.',
127
+    'groups:notitle' => 'Groups must have a title',
128
+    'groups:cantjoin' => 'Can not join group',
129
+    'groups:cantleave' => 'Could not leave group',
130
+    'groups:removeuser' => 'Remove from group',
131
+    'groups:cantremove' => 'Cannot remove user from group',
132
+    'groups:removed' => 'Successfully removed %s from group',
133
+    'groups:addedtogroup' => 'Successfully added the user to the group',
134
+    'groups:joinrequestnotmade' => 'Could not request to join group',
135
+    'groups:joinrequestmade' => 'Requested to join group',
136
+    'groups:joinrequest:exists' => 'You already requested membership for this group',
137
+    'groups:joined' => 'Successfully joined group!',
138
+    'groups:left' => 'Successfully left group',
139
+    'groups:notowner' => 'Sorry, you are not the owner of this group.',
140
+    'groups:notmember' => 'Sorry, you are not a member of this group.',
141
+    'groups:alreadymember' => 'You are already a member of this group!',
142
+    'groups:userinvited' => 'User has been invited.',
143
+    'groups:usernotinvited' => 'User could not be invited.',
144
+    'groups:useralreadyinvited' => 'User has already been invited',
145
+    'groups:invite:subject' => "%s you have been invited to join %s!",
146
+    'groups:started' => "Started by %s",
147
+    'groups:joinrequest:remove:check' => 'Are you sure you want to remove this join request?',
148
+    'groups:invite:remove:check' => 'Are you sure you want to remove this invitation?',
149
+    'groups:invite:body' => "Hi %s,
150 150
 
151 151
 %s invited you to join the '%s' group. Click below to view your invitations:
152 152
 
153 153
 %s",
154 154
 
155
-	'groups:welcome:subject' => "Welcome to the %s group!",
156
-	'groups:welcome:body' => "Hi %s!
155
+    'groups:welcome:subject' => "Welcome to the %s group!",
156
+    'groups:welcome:body' => "Hi %s!
157 157
 
158 158
 You are now a member of the '%s' group! Click below to begin posting!
159 159
 
160 160
 %s",
161 161
 
162
-	'groups:request:subject' => "%s has requested to join %s",
163
-	'groups:request:body' => "Hi %s,
162
+    'groups:request:subject' => "%s has requested to join %s",
163
+    'groups:request:body' => "Hi %s,
164 164
 
165 165
 %s has requested to join the '%s' group. Click below to view their profile:
166 166
 
@@ -170,54 +170,54 @@  discard block
 block discarded – undo
170 170
 
171 171
 %s",
172 172
 
173
-	/**
174
-	 * Forum river items
175
-	 */
173
+    /**
174
+     * Forum river items
175
+     */
176 176
 
177
-	'river:create:group:default' => '%s created the group %s',
178
-	'river:join:group:default' => '%s joined the group %s',
177
+    'river:create:group:default' => '%s created the group %s',
178
+    'river:join:group:default' => '%s joined the group %s',
179 179
 
180
-	'groups:nowidgets' => 'No widgets have been defined for this group.',
180
+    'groups:nowidgets' => 'No widgets have been defined for this group.',
181 181
 
182 182
 
183
-	'groups:widgets:members:title' => 'Group members',
184
-	'groups:widgets:members:description' => 'List the members of a group.',
185
-	'groups:widgets:members:label:displaynum' => 'List the members of a group.',
186
-	'groups:widgets:members:label:pleaseedit' => 'Please configure this widget.',
183
+    'groups:widgets:members:title' => 'Group members',
184
+    'groups:widgets:members:description' => 'List the members of a group.',
185
+    'groups:widgets:members:label:displaynum' => 'List the members of a group.',
186
+    'groups:widgets:members:label:pleaseedit' => 'Please configure this widget.',
187 187
 
188
-	'groups:widgets:entities:title' => "Objects in group",
189
-	'groups:widgets:entities:description' => "List the objects saved in this group",
190
-	'groups:widgets:entities:label:displaynum' => 'List the objects of a group.',
191
-	'groups:widgets:entities:label:pleaseedit' => 'Please configure this widget.',
188
+    'groups:widgets:entities:title' => "Objects in group",
189
+    'groups:widgets:entities:description' => "List the objects saved in this group",
190
+    'groups:widgets:entities:label:displaynum' => 'List the objects of a group.',
191
+    'groups:widgets:entities:label:pleaseedit' => 'Please configure this widget.',
192 192
 
193
-	'groups:allowhiddengroups' => 'Allow private (invisible) groups?',
194
-	'groups:whocancreate' => 'Who can create new groups?',
195
-	'groups:allow_activity' => 'Allow activity pages in groups?',
193
+    'groups:allowhiddengroups' => 'Allow private (invisible) groups?',
194
+    'groups:whocancreate' => 'Who can create new groups?',
195
+    'groups:allow_activity' => 'Allow activity pages in groups?',
196 196
 
197
-	/**
198
-	 * Action messages
199
-	 */
200
-	'group:deleted' => 'Group and group contents deleted',
201
-	'group:notdeleted' => 'Group could not be deleted',
197
+    /**
198
+     * Action messages
199
+     */
200
+    'group:deleted' => 'Group and group contents deleted',
201
+    'group:notdeleted' => 'Group could not be deleted',
202 202
 
203
-	'group:notfound' => 'Could not find the group',
204
-	'groups:deletewarning' => "Are you sure you want to delete this group? There is no undo!",
203
+    'group:notfound' => 'Could not find the group',
204
+    'groups:deletewarning' => "Are you sure you want to delete this group? There is no undo!",
205 205
 
206
-	'groups:invitekilled' => 'The invite has been deleted.',
207
-	'groups:joinrequestkilled' => 'The join request has been deleted.',
208
-	'groups:error:addedtogroup' => "Could not add %s to the group",
209
-	'groups:add:alreadymember' => "%s is already a member of this group",
206
+    'groups:invitekilled' => 'The invite has been deleted.',
207
+    'groups:joinrequestkilled' => 'The join request has been deleted.',
208
+    'groups:error:addedtogroup' => "Could not add %s to the group",
209
+    'groups:add:alreadymember' => "%s is already a member of this group",
210 210
 
211
-	/**
212
-	 * ecml
213
-	 */
214
-	'groups:ecml:groupprofile' => 'Group profiles',
211
+    /**
212
+     * ecml
213
+     */
214
+    'groups:ecml:groupprofile' => 'Group profiles',
215 215
 
216
-	/**
217
-	 * Upgrades
218
-	 */
219
-	'groups:upgrade:2016101900:title' => 'Transfer group icons to new location',
220
-	'groups:upgrade:2016101900:description' => '
216
+    /**
217
+     * Upgrades
218
+     */
219
+    'groups:upgrade:2016101900:title' => 'Transfer group icons to new location',
220
+    'groups:upgrade:2016101900:description' => '
221 221
 		New entity icon API stores icons in a predictable location on the filestore
222 222
 		relative to the entity\'s filestore directory. This upgrade aligns
223 223
 		will align group plugin with the requirements of the new API.
Please login to merge, or discard this patch.
engine/classes/Elgg/Database/AccessCollections.php 1 patch
Indentation   +812 added lines, -812 removed lines patch added patch discarded remove patch
@@ -23,159 +23,159 @@  discard block
 block discarded – undo
23 23
  */
24 24
 class AccessCollections {
25 25
 
26
-	/**
27
-	 * @var Conf
28
-	 */
29
-	protected $config;
30
-
31
-	/**
32
-	 * @var Database
33
-	 */
34
-	protected $db;
35
-
36
-	/**
37
-	 * @vars \ElggStateVariableCache
38
-	 */
39
-	protected $access_cache;
40
-
41
-	/**
42
-	 * @var PluginHooksService
43
-	 */
44
-	protected $hooks;
45
-
46
-	/**
47
-	 * @var ElggSession
48
-	 */
49
-	protected $session;
50
-
51
-	/**
52
-	 * @var EntityTable
53
-	 */
54
-	protected $entities;
55
-
56
-	/**
57
-	 * @var Translator
58
-	 */
59
-	protected $translator;
60
-
61
-	/**
62
-	 * @var string
63
-	 */
64
-	protected $table;
65
-
66
-	/**
67
-	 * @var string
68
-	 */
69
-	protected $membership_table;
70
-
71
-	/**
72
-	 * Constructor
73
-	 *
74
-	 * @param Config                  $config     Config
75
-	 * @param Database                $db         Database
76
-	 * @param EntityTable             $entities   Entity table
77
-	 * @param ElggStaticVariableCache $cache      Access cache
78
-	 * @param PluginHooksService      $hooks      Hooks
79
-	 * @param ElggSession             $session    Session
80
-	 * @param Translator              $translator Translator
81
-	 */
82
-	public function __construct(
83
-			Conf $config,
84
-			Database $db,
85
-			EntityTable $entities,
86
-			ElggStaticVariableCache $cache,
87
-			PluginHooksService $hooks,
88
-			ElggSession $session,
89
-			Translator $translator) {
90
-		$this->config = $config;
91
-		$this->db = $db;
92
-		$this->entities = $entities;
93
-		$this->access_cache = $cache;
94
-		$this->hooks = $hooks;
95
-		$this->session = $session;
96
-		$this->translator = $translator;
97
-
98
-		$this->table = "{$this->db->prefix}access_collections";
99
-		$this->membership_table = "{$this->db->prefix}access_collection_membership";
100
-	}
101
-
102
-	/**
103
-	 * Returns a string of access_ids for $user_guid appropriate for inserting into an SQL IN clause.
104
-	 *
105
-	 * @see get_access_array()
106
-	 *
107
-	 * @param int  $user_guid User ID; defaults to currently logged in user
108
-	 * @param bool $flush     If set to true, will refresh the access list from the
109
-	 *                        database rather than using this function's cache.
110
-	 *
111
-	 * @return string A concatenated string of access collections suitable for using in an SQL IN clause
112
-	 * @access private
113
-	 */
114
-	public function getAccessList($user_guid = 0, $flush = false) {
115
-		$access_array = $this->getAccessArray($user_guid, $flush);
116
-		$access_ids = implode(',', $access_array);
117
-		$list = "($access_ids)";
118
-
119
-		// for BC, populate the cache
120
-		$hash = $user_guid . 'get_access_list';
121
-		$this->access_cache->add($hash, $list);
122
-
123
-		return $list;
124
-	}
125
-
126
-	/**
127
-	 * Returns an array of access IDs a user is permitted to see.
128
-	 *
129
-	 * Can be overridden with the 'access:collections:read', 'user' plugin hook.
130
-	 * @warning A callback for that plugin hook needs to either not retrieve data
131
-	 * from the database that would use the access system (triggering the plugin again)
132
-	 * or ignore the second call. Otherwise, an infinite loop will be created.
133
-	 *
134
-	 * This returns a list of all the collection ids a user owns or belongs
135
-	 * to plus public and logged in access levels. If the user is an admin, it includes
136
-	 * the private access level.
137
-	 *
138
-	 * @internal this is only used in core for creating the SQL where clause when
139
-	 * retrieving content from the database. The friends access level is handled by
140
-	 * _elgg_get_access_where_sql().
141
-	 *
142
-	 * @see get_write_access_array() for the access levels that a user can write to.
143
-	 *
144
-	 * @param int  $user_guid User ID; defaults to currently logged in user
145
-	 * @param bool $flush     If set to true, will refresh the access ids from the
146
-	 *                        database rather than using this function's cache.
147
-	 *
148
-	 * @return array An array of access collections ids
149
-	 */
150
-	public function getAccessArray($user_guid = 0, $flush = false) {
151
-		global $init_finished;
152
-
153
-		$cache = $this->access_cache;
154
-
155
-		if ($flush) {
156
-			$cache->clear();
157
-		}
158
-
159
-		if ($user_guid == 0) {
160
-			$user_guid = $this->session->getLoggedInUserGuid();
161
-		}
162
-
163
-		$user_guid = (int) $user_guid;
164
-
165
-		$hash = $user_guid . 'get_access_array';
166
-
167
-		if ($cache[$hash]) {
168
-			$access_array = $cache[$hash];
169
-		} else {
170
-			// Public access is always visible
171
-			$access_array = [ACCESS_PUBLIC];
172
-
173
-			// The following can only return sensible data for a known user.
174
-			if ($user_guid) {
175
-				$access_array[] = ACCESS_LOGGED_IN;
176
-
177
-				// Get ACLs that user owns or is a member of
178
-				$query = "
26
+    /**
27
+     * @var Conf
28
+     */
29
+    protected $config;
30
+
31
+    /**
32
+     * @var Database
33
+     */
34
+    protected $db;
35
+
36
+    /**
37
+     * @vars \ElggStateVariableCache
38
+     */
39
+    protected $access_cache;
40
+
41
+    /**
42
+     * @var PluginHooksService
43
+     */
44
+    protected $hooks;
45
+
46
+    /**
47
+     * @var ElggSession
48
+     */
49
+    protected $session;
50
+
51
+    /**
52
+     * @var EntityTable
53
+     */
54
+    protected $entities;
55
+
56
+    /**
57
+     * @var Translator
58
+     */
59
+    protected $translator;
60
+
61
+    /**
62
+     * @var string
63
+     */
64
+    protected $table;
65
+
66
+    /**
67
+     * @var string
68
+     */
69
+    protected $membership_table;
70
+
71
+    /**
72
+     * Constructor
73
+     *
74
+     * @param Config                  $config     Config
75
+     * @param Database                $db         Database
76
+     * @param EntityTable             $entities   Entity table
77
+     * @param ElggStaticVariableCache $cache      Access cache
78
+     * @param PluginHooksService      $hooks      Hooks
79
+     * @param ElggSession             $session    Session
80
+     * @param Translator              $translator Translator
81
+     */
82
+    public function __construct(
83
+            Conf $config,
84
+            Database $db,
85
+            EntityTable $entities,
86
+            ElggStaticVariableCache $cache,
87
+            PluginHooksService $hooks,
88
+            ElggSession $session,
89
+            Translator $translator) {
90
+        $this->config = $config;
91
+        $this->db = $db;
92
+        $this->entities = $entities;
93
+        $this->access_cache = $cache;
94
+        $this->hooks = $hooks;
95
+        $this->session = $session;
96
+        $this->translator = $translator;
97
+
98
+        $this->table = "{$this->db->prefix}access_collections";
99
+        $this->membership_table = "{$this->db->prefix}access_collection_membership";
100
+    }
101
+
102
+    /**
103
+     * Returns a string of access_ids for $user_guid appropriate for inserting into an SQL IN clause.
104
+     *
105
+     * @see get_access_array()
106
+     *
107
+     * @param int  $user_guid User ID; defaults to currently logged in user
108
+     * @param bool $flush     If set to true, will refresh the access list from the
109
+     *                        database rather than using this function's cache.
110
+     *
111
+     * @return string A concatenated string of access collections suitable for using in an SQL IN clause
112
+     * @access private
113
+     */
114
+    public function getAccessList($user_guid = 0, $flush = false) {
115
+        $access_array = $this->getAccessArray($user_guid, $flush);
116
+        $access_ids = implode(',', $access_array);
117
+        $list = "($access_ids)";
118
+
119
+        // for BC, populate the cache
120
+        $hash = $user_guid . 'get_access_list';
121
+        $this->access_cache->add($hash, $list);
122
+
123
+        return $list;
124
+    }
125
+
126
+    /**
127
+     * Returns an array of access IDs a user is permitted to see.
128
+     *
129
+     * Can be overridden with the 'access:collections:read', 'user' plugin hook.
130
+     * @warning A callback for that plugin hook needs to either not retrieve data
131
+     * from the database that would use the access system (triggering the plugin again)
132
+     * or ignore the second call. Otherwise, an infinite loop will be created.
133
+     *
134
+     * This returns a list of all the collection ids a user owns or belongs
135
+     * to plus public and logged in access levels. If the user is an admin, it includes
136
+     * the private access level.
137
+     *
138
+     * @internal this is only used in core for creating the SQL where clause when
139
+     * retrieving content from the database. The friends access level is handled by
140
+     * _elgg_get_access_where_sql().
141
+     *
142
+     * @see get_write_access_array() for the access levels that a user can write to.
143
+     *
144
+     * @param int  $user_guid User ID; defaults to currently logged in user
145
+     * @param bool $flush     If set to true, will refresh the access ids from the
146
+     *                        database rather than using this function's cache.
147
+     *
148
+     * @return array An array of access collections ids
149
+     */
150
+    public function getAccessArray($user_guid = 0, $flush = false) {
151
+        global $init_finished;
152
+
153
+        $cache = $this->access_cache;
154
+
155
+        if ($flush) {
156
+            $cache->clear();
157
+        }
158
+
159
+        if ($user_guid == 0) {
160
+            $user_guid = $this->session->getLoggedInUserGuid();
161
+        }
162
+
163
+        $user_guid = (int) $user_guid;
164
+
165
+        $hash = $user_guid . 'get_access_array';
166
+
167
+        if ($cache[$hash]) {
168
+            $access_array = $cache[$hash];
169
+        } else {
170
+            // Public access is always visible
171
+            $access_array = [ACCESS_PUBLIC];
172
+
173
+            // The following can only return sensible data for a known user.
174
+            if ($user_guid) {
175
+                $access_array[] = ACCESS_LOGGED_IN;
176
+
177
+                // Get ACLs that user owns or is a member of
178
+                $query = "
179 179
 					SELECT ac.id
180 180
 					FROM {$this->table} ac
181 181
 					WHERE ac.owner_guid = :user_guid
@@ -185,687 +185,687 @@  discard block
 block discarded – undo
185 185
 							   AND user_guid = :user_guid)
186 186
 				";
187 187
 
188
-				$collections = $this->db->getData($query, null, [
189
-					':user_guid' => $user_guid,
190
-				]);
191
-
192
-				if ($collections) {
193
-					foreach ($collections as $collection) {
194
-						$access_array[] = (int) $collection->id;
195
-					}
196
-				}
197
-
198
-				$ignore_access = elgg_check_access_overrides($user_guid);
199
-
200
-				if ($ignore_access == true) {
201
-					$access_array[] = ACCESS_PRIVATE;
202
-				}
203
-			}
204
-
205
-			if ($init_finished) {
206
-				$cache[$hash] = $access_array;
207
-			}
208
-		}
209
-
210
-		$options = [
211
-			'user_id' => $user_guid,
212
-		];
213
-
214
-		// see the warning in the docs for this function about infinite loop potential
215
-		return $this->hooks->trigger('access:collections:read', 'user', $options, $access_array);
216
-	}
217
-
218
-	/**
219
-	 * Returns the SQL where clause for enforcing read access to data.
220
-	 *
221
-	 * Note that if this code is executed in privileged mode it will return (1=1).
222
-	 *
223
-	 * Otherwise it returns a where clause to retrieve the data that a user has
224
-	 * permission to read.
225
-	 *
226
-	 * Plugin authors can hook into the 'get_sql', 'access' plugin hook to modify,
227
-	 * remove, or add to the where clauses. The plugin hook will pass an array with the current
228
-	 * ors and ands to the function in the form:
229
-	 *  array(
230
-	 *      'ors' => array(),
231
-	 *      'ands' => array()
232
-	 *  )
233
-	 *
234
-	 * The results will be combined into an SQL where clause in the form:
235
-	 *  ((or1 OR or2 OR orN) AND (and1 AND and2 AND andN))
236
-	 *
237
-	 * @param array $options Array in format:
238
-	 *
239
-	 * 	table_alias => STR Optional table alias. This is based on the select and join clauses.
240
-	 *                     Default is 'e'.
241
-	 *
242
-	 *  user_guid => INT Optional GUID for the user that we are retrieving data for.
243
-	 *                   Defaults to the logged in user if null.
244
-	 *                   Passing 0 will build a query for a logged out user (even if there is a logged in user)
245
-	 *
246
-	 *  use_enabled_clause => BOOL Optional. Should we append the enabled clause? The default
247
-	 *                             is set by access_show_hidden_entities().
248
-	 *
249
-	 *  access_column => STR Optional access column name. Default is 'access_id'.
250
-	 *
251
-	 *  owner_guid_column => STR Optional owner_guid column. Default is 'owner_guid'.
252
-	 *
253
-	 *  guid_column => STR Optional guid_column. Default is 'guid'.
254
-	 *
255
-	 * @return string
256
-	 * @access private
257
-	 */
258
-	public function getWhereSql(array $options = []) {
259
-
260
-		$defaults = [
261
-			'table_alias' => 'e',
262
-			'user_guid' => $this->session->getLoggedInUserGuid(),
263
-			'use_enabled_clause' => !access_get_show_hidden_status(),
264
-			'access_column' => 'access_id',
265
-			'owner_guid_column' => 'owner_guid',
266
-			'guid_column' => 'guid',
267
-		];
268
-
269
-		foreach ($options as $key => $value) {
270
-			if (is_null($value)) {
271
-				// remove null values so we don't loose defaults in array_merge
272
-				unset($options[$key]);
273
-			}
274
-		}
275
-
276
-		$options = array_merge($defaults, $options);
277
-
278
-		// just in case someone passes a . at the end
279
-		$options['table_alias'] = rtrim($options['table_alias'], '.');
280
-
281
-		foreach (['table_alias', 'access_column', 'owner_guid_column', 'guid_column'] as $key) {
282
-			$options[$key] = sanitize_string($options[$key]);
283
-		}
284
-		$options['user_guid'] = sanitize_int($options['user_guid'], false);
285
-
286
-		// only add dot if we have an alias or table name
287
-		$table_alias = $options['table_alias'] ? $options['table_alias'] . '.' : '';
288
-
289
-		if (!isset($options['ignore_access'])) {
290
-			$options['ignore_access'] = elgg_check_access_overrides($options['user_guid']);
291
-		}
292
-
293
-		$clauses = [
294
-			'ors' => [],
295
-			'ands' => []
296
-		];
297
-
298
-		$prefix = $this->db->prefix;
299
-
300
-		if ($options['ignore_access']) {
301
-			$clauses['ors']['ignore_access'] = '1 = 1';
302
-		} else if ($options['user_guid']) {
303
-			// include content of user's friends
304
-			$clauses['ors']['friends_access'] = "$table_alias{$options['access_column']} = " . ACCESS_FRIENDS . "
188
+                $collections = $this->db->getData($query, null, [
189
+                    ':user_guid' => $user_guid,
190
+                ]);
191
+
192
+                if ($collections) {
193
+                    foreach ($collections as $collection) {
194
+                        $access_array[] = (int) $collection->id;
195
+                    }
196
+                }
197
+
198
+                $ignore_access = elgg_check_access_overrides($user_guid);
199
+
200
+                if ($ignore_access == true) {
201
+                    $access_array[] = ACCESS_PRIVATE;
202
+                }
203
+            }
204
+
205
+            if ($init_finished) {
206
+                $cache[$hash] = $access_array;
207
+            }
208
+        }
209
+
210
+        $options = [
211
+            'user_id' => $user_guid,
212
+        ];
213
+
214
+        // see the warning in the docs for this function about infinite loop potential
215
+        return $this->hooks->trigger('access:collections:read', 'user', $options, $access_array);
216
+    }
217
+
218
+    /**
219
+     * Returns the SQL where clause for enforcing read access to data.
220
+     *
221
+     * Note that if this code is executed in privileged mode it will return (1=1).
222
+     *
223
+     * Otherwise it returns a where clause to retrieve the data that a user has
224
+     * permission to read.
225
+     *
226
+     * Plugin authors can hook into the 'get_sql', 'access' plugin hook to modify,
227
+     * remove, or add to the where clauses. The plugin hook will pass an array with the current
228
+     * ors and ands to the function in the form:
229
+     *  array(
230
+     *      'ors' => array(),
231
+     *      'ands' => array()
232
+     *  )
233
+     *
234
+     * The results will be combined into an SQL where clause in the form:
235
+     *  ((or1 OR or2 OR orN) AND (and1 AND and2 AND andN))
236
+     *
237
+     * @param array $options Array in format:
238
+     *
239
+     * 	table_alias => STR Optional table alias. This is based on the select and join clauses.
240
+     *                     Default is 'e'.
241
+     *
242
+     *  user_guid => INT Optional GUID for the user that we are retrieving data for.
243
+     *                   Defaults to the logged in user if null.
244
+     *                   Passing 0 will build a query for a logged out user (even if there is a logged in user)
245
+     *
246
+     *  use_enabled_clause => BOOL Optional. Should we append the enabled clause? The default
247
+     *                             is set by access_show_hidden_entities().
248
+     *
249
+     *  access_column => STR Optional access column name. Default is 'access_id'.
250
+     *
251
+     *  owner_guid_column => STR Optional owner_guid column. Default is 'owner_guid'.
252
+     *
253
+     *  guid_column => STR Optional guid_column. Default is 'guid'.
254
+     *
255
+     * @return string
256
+     * @access private
257
+     */
258
+    public function getWhereSql(array $options = []) {
259
+
260
+        $defaults = [
261
+            'table_alias' => 'e',
262
+            'user_guid' => $this->session->getLoggedInUserGuid(),
263
+            'use_enabled_clause' => !access_get_show_hidden_status(),
264
+            'access_column' => 'access_id',
265
+            'owner_guid_column' => 'owner_guid',
266
+            'guid_column' => 'guid',
267
+        ];
268
+
269
+        foreach ($options as $key => $value) {
270
+            if (is_null($value)) {
271
+                // remove null values so we don't loose defaults in array_merge
272
+                unset($options[$key]);
273
+            }
274
+        }
275
+
276
+        $options = array_merge($defaults, $options);
277
+
278
+        // just in case someone passes a . at the end
279
+        $options['table_alias'] = rtrim($options['table_alias'], '.');
280
+
281
+        foreach (['table_alias', 'access_column', 'owner_guid_column', 'guid_column'] as $key) {
282
+            $options[$key] = sanitize_string($options[$key]);
283
+        }
284
+        $options['user_guid'] = sanitize_int($options['user_guid'], false);
285
+
286
+        // only add dot if we have an alias or table name
287
+        $table_alias = $options['table_alias'] ? $options['table_alias'] . '.' : '';
288
+
289
+        if (!isset($options['ignore_access'])) {
290
+            $options['ignore_access'] = elgg_check_access_overrides($options['user_guid']);
291
+        }
292
+
293
+        $clauses = [
294
+            'ors' => [],
295
+            'ands' => []
296
+        ];
297
+
298
+        $prefix = $this->db->prefix;
299
+
300
+        if ($options['ignore_access']) {
301
+            $clauses['ors']['ignore_access'] = '1 = 1';
302
+        } else if ($options['user_guid']) {
303
+            // include content of user's friends
304
+            $clauses['ors']['friends_access'] = "$table_alias{$options['access_column']} = " . ACCESS_FRIENDS . "
305 305
 				AND $table_alias{$options['owner_guid_column']} IN (
306 306
 					SELECT guid_one FROM {$prefix}entity_relationships
307 307
 					WHERE relationship = 'friend' AND guid_two = {$options['user_guid']}
308 308
 				)";
309 309
 
310
-			// include user's content
311
-			$clauses['ors']['owner_access'] = "$table_alias{$options['owner_guid_column']} = {$options['user_guid']}";
312
-		}
313
-
314
-		// include standard accesses (public, logged in, access collections)
315
-		if (!$options['ignore_access']) {
316
-			$access_list = $this->getAccessList($options['user_guid']);
317
-			$clauses['ors']['acl_access'] = "$table_alias{$options['access_column']} IN {$access_list}";
318
-		}
319
-
320
-		if ($options['use_enabled_clause']) {
321
-			$clauses['ands']['use_enabled'] = "{$table_alias}enabled = 'yes'";
322
-		}
323
-
324
-		$clauses = $this->hooks->trigger('get_sql', 'access', $options, $clauses);
325
-
326
-		$clauses_str = '';
327
-		if (is_array($clauses['ors']) && $clauses['ors']) {
328
-			$clauses_str = '(' . implode(' OR ', $clauses['ors']) . ')';
329
-		}
330
-
331
-		if (is_array($clauses['ands']) && $clauses['ands']) {
332
-			if ($clauses_str) {
333
-				$clauses_str .= ' AND ';
334
-			}
335
-			$clauses_str .= '(' . implode(' AND ', $clauses['ands']) . ')';
336
-		}
337
-
338
-		return "($clauses_str)";
339
-	}
340
-
341
-	/**
342
-	 * Can a user access an entity.
343
-	 *
344
-	 * @warning If a logged in user doesn't have access to an entity, the
345
-	 * core engine will not load that entity.
346
-	 *
347
-	 * @tip This is mostly useful for checking if a user other than the logged in
348
-	 * user has access to an entity that is currently loaded.
349
-	 *
350
-	 * @todo This function would be much more useful if we could pass the guid of the
351
-	 * entity to test access for. We need to be able to tell whether the entity exists
352
-	 * and whether the user has access to the entity.
353
-	 *
354
-	 * @param ElggEntity $entity The entity to check access for.
355
-	 * @param ElggUser   $user   Optionally user to check access for. Defaults to
356
-	 *                           logged in user (which is a useless default).
357
-	 *
358
-	 * @return bool
359
-	 */
360
-	public function hasAccessToEntity($entity, $user = null) {
361
-		if (!$entity instanceof \ElggEntity) {
362
-			return false;
363
-		}
364
-
365
-		if ($entity->access_id == ACCESS_PUBLIC) {
366
-			// Public entities are always accessible
367
-			return true;
368
-		}
369
-
370
-		$user_guid = isset($user) ? (int) $user->guid : elgg_get_logged_in_user_guid();
371
-
372
-		if ($user_guid && $user_guid == $entity->owner_guid) {
373
-			// Owners have access to their own content
374
-			return true;
375
-		}
376
-
377
-		if ($user_guid && $entity->access_id == ACCESS_LOGGED_IN) {
378
-			// Existing users have access to entities with logged in access
379
-			return true;
380
-		}
381
-
382
-		// See #7159. Must not allow ignore access to affect query
383
-		$ia = elgg_set_ignore_access(false);
310
+            // include user's content
311
+            $clauses['ors']['owner_access'] = "$table_alias{$options['owner_guid_column']} = {$options['user_guid']}";
312
+        }
313
+
314
+        // include standard accesses (public, logged in, access collections)
315
+        if (!$options['ignore_access']) {
316
+            $access_list = $this->getAccessList($options['user_guid']);
317
+            $clauses['ors']['acl_access'] = "$table_alias{$options['access_column']} IN {$access_list}";
318
+        }
319
+
320
+        if ($options['use_enabled_clause']) {
321
+            $clauses['ands']['use_enabled'] = "{$table_alias}enabled = 'yes'";
322
+        }
323
+
324
+        $clauses = $this->hooks->trigger('get_sql', 'access', $options, $clauses);
325
+
326
+        $clauses_str = '';
327
+        if (is_array($clauses['ors']) && $clauses['ors']) {
328
+            $clauses_str = '(' . implode(' OR ', $clauses['ors']) . ')';
329
+        }
330
+
331
+        if (is_array($clauses['ands']) && $clauses['ands']) {
332
+            if ($clauses_str) {
333
+                $clauses_str .= ' AND ';
334
+            }
335
+            $clauses_str .= '(' . implode(' AND ', $clauses['ands']) . ')';
336
+        }
337
+
338
+        return "($clauses_str)";
339
+    }
340
+
341
+    /**
342
+     * Can a user access an entity.
343
+     *
344
+     * @warning If a logged in user doesn't have access to an entity, the
345
+     * core engine will not load that entity.
346
+     *
347
+     * @tip This is mostly useful for checking if a user other than the logged in
348
+     * user has access to an entity that is currently loaded.
349
+     *
350
+     * @todo This function would be much more useful if we could pass the guid of the
351
+     * entity to test access for. We need to be able to tell whether the entity exists
352
+     * and whether the user has access to the entity.
353
+     *
354
+     * @param ElggEntity $entity The entity to check access for.
355
+     * @param ElggUser   $user   Optionally user to check access for. Defaults to
356
+     *                           logged in user (which is a useless default).
357
+     *
358
+     * @return bool
359
+     */
360
+    public function hasAccessToEntity($entity, $user = null) {
361
+        if (!$entity instanceof \ElggEntity) {
362
+            return false;
363
+        }
364
+
365
+        if ($entity->access_id == ACCESS_PUBLIC) {
366
+            // Public entities are always accessible
367
+            return true;
368
+        }
369
+
370
+        $user_guid = isset($user) ? (int) $user->guid : elgg_get_logged_in_user_guid();
371
+
372
+        if ($user_guid && $user_guid == $entity->owner_guid) {
373
+            // Owners have access to their own content
374
+            return true;
375
+        }
376
+
377
+        if ($user_guid && $entity->access_id == ACCESS_LOGGED_IN) {
378
+            // Existing users have access to entities with logged in access
379
+            return true;
380
+        }
381
+
382
+        // See #7159. Must not allow ignore access to affect query
383
+        $ia = elgg_set_ignore_access(false);
384 384
 		
385
-		$row = $this->entities->getRow($entity->guid, $user_guid);
386
-
387
-		elgg_set_ignore_access($ia);
388
-
389
-		return !empty($row);
390
-	}
391
-
392
-	/**
393
-	 * Returns an array of access permissions that the user is allowed to save content with.
394
-	 * Permissions returned are of the form (id => 'name').
395
-	 *
396
-	 * Example return value in English:
397
-	 * array(
398
-	 *     0 => 'Private',
399
-	 *    -2 => 'Friends',
400
-	 *     1 => 'Logged in users',
401
-	 *     2 => 'Public',
402
-	 *    34 => 'My favorite friends',
403
-	 * );
404
-	 *
405
-	 * Plugin hook of 'access:collections:write', 'user'
406
-	 *
407
-	 * @warning this only returns access collections that the user owns plus the
408
-	 * standard access levels. It does not return access collections that the user
409
-	 * belongs to such as the access collection for a group.
410
-	 *
411
-	 * @param int   $user_guid    The user's GUID.
412
-	 * @param bool  $flush        If this is set to true, this will ignore a cached access array
413
-	 * @param array $input_params Some parameters passed into an input/access view
414
-	 *
415
-	 * @return array List of access permissions
416
-	 */
417
-	public function getWriteAccessArray($user_guid = 0, $flush = false, array $input_params = []) {
418
-		global $init_finished;
419
-		$cache = $this->access_cache;
420
-
421
-		if ($flush) {
422
-			$cache->clear();
423
-		}
424
-
425
-		if ($user_guid == 0) {
426
-			$user_guid = $this->session->getLoggedInUserGuid();
427
-		}
428
-
429
-		$user_guid = (int) $user_guid;
430
-
431
-		$hash = $user_guid . 'get_write_access_array';
432
-
433
-		if ($cache[$hash]) {
434
-			$access_array = $cache[$hash];
435
-		} else {
436
-			// @todo is there such a thing as public write access?
437
-			$access_array = [
438
-				ACCESS_PRIVATE => $this->getReadableAccessLevel(ACCESS_PRIVATE),
439
-				ACCESS_LOGGED_IN => $this->getReadableAccessLevel(ACCESS_LOGGED_IN),
440
-				ACCESS_PUBLIC => $this->getReadableAccessLevel(ACCESS_PUBLIC)
441
-			];
442
-
443
-			$collections = $this->getEntityCollections($user_guid);
444
-			if ($collections) {
445
-				foreach ($collections as $collection) {
446
-					$access_array[$collection->id] = $collection->name;
447
-				}
448
-			}
449
-
450
-			if ($init_finished) {
451
-				$cache[$hash] = $access_array;
452
-			}
453
-		}
454
-
455
-		$options = [
456
-			'user_id' => $user_guid,
457
-			'input_params' => $input_params,
458
-		];
459
-		return $this->hooks->trigger('access:collections:write', 'user', $options, $access_array);
460
-	}
461
-
462
-	/**
463
-	 * Can the user change this access collection?
464
-	 *
465
-	 * Use the plugin hook of 'access:collections:write', 'user' to change this.
466
-	 * @see get_write_access_array() for details on the hook.
467
-	 *
468
-	 * Respects access control disabling for admin users and {@link elgg_set_ignore_access()}
469
-	 *
470
-	 * @see get_write_access_array()
471
-	 *
472
-	 * @param int   $collection_id The collection id
473
-	 * @param mixed $user_guid     The user GUID to check for. Defaults to logged in user.
474
-	 * @return bool
475
-	 */
476
-	public function canEdit($collection_id, $user_guid = null) {
477
-		try {
478
-			$user = $this->entities->getUserForPermissionsCheck($user_guid);
479
-		} catch (UserFetchFailureException $e) {
480
-			return false;
481
-		}
482
-
483
-		$collection = $this->get($collection_id);
484
-
485
-		if (!$user || !$collection) {
486
-			return false;
487
-		}
488
-
489
-		if (elgg_check_access_overrides($user->guid)) {
490
-			return true;
491
-		}
492
-
493
-		$write_access = $this->getWriteAccessArray($user->guid, true);
494
-		return array_key_exists($collection_id, $write_access);
495
-	}
496
-
497
-	/**
498
-	 * Creates a new access collection.
499
-	 *
500
-	 * Access colletions allow plugins and users to create granular access
501
-	 * for entities.
502
-	 *
503
-	 * Triggers plugin hook 'access:collections:addcollection', 'collection'
504
-	 *
505
-	 * @internal Access collections are stored in the access_collections table.
506
-	 * Memberships to collections are in access_collections_membership.
507
-	 *
508
-	 * @param string $name       The name of the collection.
509
-	 * @param int    $owner_guid The GUID of the owner (default: currently logged in user).
510
-	 *
511
-	 * @return int|false The collection ID if successful and false on failure.
512
-	 */
513
-	public function create($name, $owner_guid = 0) {
514
-		$name = trim($name);
515
-		if (empty($name)) {
516
-			return false;
517
-		}
518
-
519
-		if ($owner_guid == 0) {
520
-			$owner_guid = $this->session->getLoggedInUserGuid();
521
-		}
522
-
523
-		$query = "
385
+        $row = $this->entities->getRow($entity->guid, $user_guid);
386
+
387
+        elgg_set_ignore_access($ia);
388
+
389
+        return !empty($row);
390
+    }
391
+
392
+    /**
393
+     * Returns an array of access permissions that the user is allowed to save content with.
394
+     * Permissions returned are of the form (id => 'name').
395
+     *
396
+     * Example return value in English:
397
+     * array(
398
+     *     0 => 'Private',
399
+     *    -2 => 'Friends',
400
+     *     1 => 'Logged in users',
401
+     *     2 => 'Public',
402
+     *    34 => 'My favorite friends',
403
+     * );
404
+     *
405
+     * Plugin hook of 'access:collections:write', 'user'
406
+     *
407
+     * @warning this only returns access collections that the user owns plus the
408
+     * standard access levels. It does not return access collections that the user
409
+     * belongs to such as the access collection for a group.
410
+     *
411
+     * @param int   $user_guid    The user's GUID.
412
+     * @param bool  $flush        If this is set to true, this will ignore a cached access array
413
+     * @param array $input_params Some parameters passed into an input/access view
414
+     *
415
+     * @return array List of access permissions
416
+     */
417
+    public function getWriteAccessArray($user_guid = 0, $flush = false, array $input_params = []) {
418
+        global $init_finished;
419
+        $cache = $this->access_cache;
420
+
421
+        if ($flush) {
422
+            $cache->clear();
423
+        }
424
+
425
+        if ($user_guid == 0) {
426
+            $user_guid = $this->session->getLoggedInUserGuid();
427
+        }
428
+
429
+        $user_guid = (int) $user_guid;
430
+
431
+        $hash = $user_guid . 'get_write_access_array';
432
+
433
+        if ($cache[$hash]) {
434
+            $access_array = $cache[$hash];
435
+        } else {
436
+            // @todo is there such a thing as public write access?
437
+            $access_array = [
438
+                ACCESS_PRIVATE => $this->getReadableAccessLevel(ACCESS_PRIVATE),
439
+                ACCESS_LOGGED_IN => $this->getReadableAccessLevel(ACCESS_LOGGED_IN),
440
+                ACCESS_PUBLIC => $this->getReadableAccessLevel(ACCESS_PUBLIC)
441
+            ];
442
+
443
+            $collections = $this->getEntityCollections($user_guid);
444
+            if ($collections) {
445
+                foreach ($collections as $collection) {
446
+                    $access_array[$collection->id] = $collection->name;
447
+                }
448
+            }
449
+
450
+            if ($init_finished) {
451
+                $cache[$hash] = $access_array;
452
+            }
453
+        }
454
+
455
+        $options = [
456
+            'user_id' => $user_guid,
457
+            'input_params' => $input_params,
458
+        ];
459
+        return $this->hooks->trigger('access:collections:write', 'user', $options, $access_array);
460
+    }
461
+
462
+    /**
463
+     * Can the user change this access collection?
464
+     *
465
+     * Use the plugin hook of 'access:collections:write', 'user' to change this.
466
+     * @see get_write_access_array() for details on the hook.
467
+     *
468
+     * Respects access control disabling for admin users and {@link elgg_set_ignore_access()}
469
+     *
470
+     * @see get_write_access_array()
471
+     *
472
+     * @param int   $collection_id The collection id
473
+     * @param mixed $user_guid     The user GUID to check for. Defaults to logged in user.
474
+     * @return bool
475
+     */
476
+    public function canEdit($collection_id, $user_guid = null) {
477
+        try {
478
+            $user = $this->entities->getUserForPermissionsCheck($user_guid);
479
+        } catch (UserFetchFailureException $e) {
480
+            return false;
481
+        }
482
+
483
+        $collection = $this->get($collection_id);
484
+
485
+        if (!$user || !$collection) {
486
+            return false;
487
+        }
488
+
489
+        if (elgg_check_access_overrides($user->guid)) {
490
+            return true;
491
+        }
492
+
493
+        $write_access = $this->getWriteAccessArray($user->guid, true);
494
+        return array_key_exists($collection_id, $write_access);
495
+    }
496
+
497
+    /**
498
+     * Creates a new access collection.
499
+     *
500
+     * Access colletions allow plugins and users to create granular access
501
+     * for entities.
502
+     *
503
+     * Triggers plugin hook 'access:collections:addcollection', 'collection'
504
+     *
505
+     * @internal Access collections are stored in the access_collections table.
506
+     * Memberships to collections are in access_collections_membership.
507
+     *
508
+     * @param string $name       The name of the collection.
509
+     * @param int    $owner_guid The GUID of the owner (default: currently logged in user).
510
+     *
511
+     * @return int|false The collection ID if successful and false on failure.
512
+     */
513
+    public function create($name, $owner_guid = 0) {
514
+        $name = trim($name);
515
+        if (empty($name)) {
516
+            return false;
517
+        }
518
+
519
+        if ($owner_guid == 0) {
520
+            $owner_guid = $this->session->getLoggedInUserGuid();
521
+        }
522
+
523
+        $query = "
524 524
 			INSERT INTO {$this->table}
525 525
 			SET name = :name,
526 526
 				owner_guid = :owner_guid
527 527
 		";
528 528
 
529
-		$params = [
530
-			':name' => $name,
531
-			':owner_guid' => (int) $owner_guid,
532
-		];
533
-
534
-		$id = $this->db->insertData($query, $params);
535
-		if (!$id) {
536
-			return false;
537
-		}
538
-
539
-		$this->access_cache->clear();
540
-
541
-		$hook_params = [
542
-			'collection_id' => $id,
543
-			'name' => $name,
544
-			'owner_guid' => $owner_guid,
545
-		];
546
-
547
-		if (!$this->hooks->trigger('access:collections:addcollection', 'collection', $hook_params, true)) {
548
-			$this->delete($id);
549
-			return false;
550
-		}
551
-
552
-		return $id;
553
-	}
554
-
555
-	/**
556
-	 * Renames an access collection
557
-	 *
558
-	 * @param int    $collection_id ID of the collection
559
-	 * @param string $name          The name of the collection
560
-	 * @return bool
561
-	 */
562
-	public function rename($collection_id, $name) {
563
-
564
-		$query = "
529
+        $params = [
530
+            ':name' => $name,
531
+            ':owner_guid' => (int) $owner_guid,
532
+        ];
533
+
534
+        $id = $this->db->insertData($query, $params);
535
+        if (!$id) {
536
+            return false;
537
+        }
538
+
539
+        $this->access_cache->clear();
540
+
541
+        $hook_params = [
542
+            'collection_id' => $id,
543
+            'name' => $name,
544
+            'owner_guid' => $owner_guid,
545
+        ];
546
+
547
+        if (!$this->hooks->trigger('access:collections:addcollection', 'collection', $hook_params, true)) {
548
+            $this->delete($id);
549
+            return false;
550
+        }
551
+
552
+        return $id;
553
+    }
554
+
555
+    /**
556
+     * Renames an access collection
557
+     *
558
+     * @param int    $collection_id ID of the collection
559
+     * @param string $name          The name of the collection
560
+     * @return bool
561
+     */
562
+    public function rename($collection_id, $name) {
563
+
564
+        $query = "
565 565
 			UPDATE {$this->table}
566 566
 			SET name = :name
567 567
 			WHERE id = :id
568 568
 		";
569 569
 
570
-		$params = [
571
-			':name' => $name,
572
-			':id' => (int) $collection_id,
573
-		];
574
-
575
-		if ($this->db->insertData($query, $params)) {
576
-			$this->access_cache->clear();
577
-			return (int) $collection_id;
578
-		}
579
-
580
-		return false;
581
-	}
582
-
583
-
584
-	/**
585
-	 * Updates the membership in an access collection.
586
-	 *
587
-	 * @warning Expects a full list of all members that should
588
-	 * be part of the access collection
589
-	 *
590
-	 * @note This will run all hooks associated with adding or removing
591
-	 * members to access collections.
592
-	 *
593
-	 * @param int   $collection_id ID of the collection.
594
-	 * @param array $new_members   Array of member entities or GUIDs
595
-	 * @return bool
596
-	 */
597
-	public function update($collection_id, array $new_members = []) {
598
-		$acl = $this->get($collection_id);
599
-
600
-		if (!$acl) {
601
-			return false;
602
-		}
570
+        $params = [
571
+            ':name' => $name,
572
+            ':id' => (int) $collection_id,
573
+        ];
574
+
575
+        if ($this->db->insertData($query, $params)) {
576
+            $this->access_cache->clear();
577
+            return (int) $collection_id;
578
+        }
579
+
580
+        return false;
581
+    }
582
+
583
+
584
+    /**
585
+     * Updates the membership in an access collection.
586
+     *
587
+     * @warning Expects a full list of all members that should
588
+     * be part of the access collection
589
+     *
590
+     * @note This will run all hooks associated with adding or removing
591
+     * members to access collections.
592
+     *
593
+     * @param int   $collection_id ID of the collection.
594
+     * @param array $new_members   Array of member entities or GUIDs
595
+     * @return bool
596
+     */
597
+    public function update($collection_id, array $new_members = []) {
598
+        $acl = $this->get($collection_id);
599
+
600
+        if (!$acl) {
601
+            return false;
602
+        }
603 603
 		
604
-		$to_guid = function($elem) {
605
-			if (empty($elem)) {
606
-				return 0;
607
-			}
608
-			if (is_object($elem)) {
609
-				return (int) $elem->guid;
610
-			}
611
-			return (int) $elem;
612
-		};
604
+        $to_guid = function($elem) {
605
+            if (empty($elem)) {
606
+                return 0;
607
+            }
608
+            if (is_object($elem)) {
609
+                return (int) $elem->guid;
610
+            }
611
+            return (int) $elem;
612
+        };
613 613
 		
614
-		$current_members = [];
615
-		$new_members = array_map($to_guid, $new_members);
614
+        $current_members = [];
615
+        $new_members = array_map($to_guid, $new_members);
616 616
 
617
-		$current_members_batch = $this->getMembers($collection_id, [
618
-			'batch' => true,
619
-			'limit' => 0,
620
-			'callback' => false,
621
-		]);
617
+        $current_members_batch = $this->getMembers($collection_id, [
618
+            'batch' => true,
619
+            'limit' => 0,
620
+            'callback' => false,
621
+        ]);
622 622
 
623
-		foreach ($current_members_batch as $row) {
624
-			$current_members[] = $to_guid($row);
625
-		}
623
+        foreach ($current_members_batch as $row) {
624
+            $current_members[] = $to_guid($row);
625
+        }
626 626
 
627
-		$remove_members = array_diff($current_members, $new_members);
628
-		$add_members = array_diff($new_members, $current_members);
627
+        $remove_members = array_diff($current_members, $new_members);
628
+        $add_members = array_diff($new_members, $current_members);
629 629
 
630
-		$result = true;
630
+        $result = true;
631 631
 
632
-		foreach ($add_members as $guid) {
633
-			$result = $result && $this->addUser($guid, $collection_id);
634
-		}
632
+        foreach ($add_members as $guid) {
633
+            $result = $result && $this->addUser($guid, $collection_id);
634
+        }
635 635
 
636
-		foreach ($remove_members as $guid) {
637
-			$result = $result && $this->removeUser($guid, $collection_id);
638
-		}
636
+        foreach ($remove_members as $guid) {
637
+            $result = $result && $this->removeUser($guid, $collection_id);
638
+        }
639 639
 
640
-		$this->access_cache->clear();
640
+        $this->access_cache->clear();
641 641
 
642
-		return $result;
643
-	}
642
+        return $result;
643
+    }
644 644
 
645
-	/**
646
-	 * Deletes a collection and its membership information
647
-	 *
648
-	 * @param int $collection_id ID of the collection
649
-	 * @return bool
650
-	 */
651
-	public function delete($collection_id) {
652
-		$collection_id = (int) $collection_id;
645
+    /**
646
+     * Deletes a collection and its membership information
647
+     *
648
+     * @param int $collection_id ID of the collection
649
+     * @return bool
650
+     */
651
+    public function delete($collection_id) {
652
+        $collection_id = (int) $collection_id;
653 653
 
654
-		$params = [
655
-			'collection_id' => $collection_id,
656
-		];
654
+        $params = [
655
+            'collection_id' => $collection_id,
656
+        ];
657 657
 
658
-		if (!$this->hooks->trigger('access:collections:deletecollection', 'collection', $params, true)) {
659
-			return false;
660
-		}
658
+        if (!$this->hooks->trigger('access:collections:deletecollection', 'collection', $params, true)) {
659
+            return false;
660
+        }
661 661
 
662
-		// Deleting membership doesn't affect result of deleting ACL.
663
-		$query = "
662
+        // Deleting membership doesn't affect result of deleting ACL.
663
+        $query = "
664 664
 			DELETE FROM {$this->membership_table}
665 665
 			WHERE access_collection_id = :access_collection_id
666 666
 		";
667
-		$this->db->deleteData($query, [
668
-			':access_collection_id' => $collection_id,
669
-		]);
667
+        $this->db->deleteData($query, [
668
+            ':access_collection_id' => $collection_id,
669
+        ]);
670 670
 
671
-		$query = "
671
+        $query = "
672 672
 			DELETE FROM {$this->table}
673 673
 			WHERE id = :id
674 674
 		";
675
-		$result = $this->db->deleteData($query, [
676
-			':id' => $collection_id,
677
-		]);
675
+        $result = $this->db->deleteData($query, [
676
+            ':id' => $collection_id,
677
+        ]);
678 678
 
679
-		$this->access_cache->clear();
679
+        $this->access_cache->clear();
680 680
 		
681
-		return (bool) $result;
682
-	}
683
-
684
-	/**
685
-	 * Transforms a database row to an instance of ElggAccessCollection
686
-	 *
687
-	 * @param \stdClass $row Database row
688
-	 * @return \ElggAccessCollection
689
-	 */
690
-	public function rowToElggAccessCollection(\stdClass $row) {
691
-		return new \ElggAccessCollection($row);
692
-	}
693
-
694
-	/**
695
-	 * Get a specified access collection
696
-	 *
697
-	 * @note This doesn't return the members of an access collection,
698
-	 * just the database row of the actual collection.
699
-	 *
700
-	 * @see get_members_of_access_collection()
701
-	 *
702
-	 * @param int $collection_id The collection ID
703
-	 * @return \ElggAccessCollection|false
704
-	 */
705
-	public function get($collection_id) {
706
-
707
-		$callback = [$this, 'rowToElggAccessCollection'];
708
-
709
-		$query = "
681
+        return (bool) $result;
682
+    }
683
+
684
+    /**
685
+     * Transforms a database row to an instance of ElggAccessCollection
686
+     *
687
+     * @param \stdClass $row Database row
688
+     * @return \ElggAccessCollection
689
+     */
690
+    public function rowToElggAccessCollection(\stdClass $row) {
691
+        return new \ElggAccessCollection($row);
692
+    }
693
+
694
+    /**
695
+     * Get a specified access collection
696
+     *
697
+     * @note This doesn't return the members of an access collection,
698
+     * just the database row of the actual collection.
699
+     *
700
+     * @see get_members_of_access_collection()
701
+     *
702
+     * @param int $collection_id The collection ID
703
+     * @return \ElggAccessCollection|false
704
+     */
705
+    public function get($collection_id) {
706
+
707
+        $callback = [$this, 'rowToElggAccessCollection'];
708
+
709
+        $query = "
710 710
 			SELECT * FROM {$this->table}
711 711
 			WHERE id = :id
712 712
 		";
713 713
 
714
-		return $this->db->getDataRow($query, $callback, [
715
-			':id' => (int) $collection_id,
716
-		]);
717
-	}
718
-
719
-	/**
720
-	 * Check if user is already in the collection
721
-	 *
722
-	 * @param int $user_guid     GUID of the user
723
-	 * @param int $collection_id ID of the collection
724
-	 * @return bool
725
-	 */
726
-	public function hasUser($user_guid, $collection_id) {
727
-		$options = [
728
-			'guids' => (int) $user_guid,
729
-			'count' => true,
730
-		];
731
-		return (bool) $this->getMembers($collection_id, $options);
732
-	}
733
-
734
-	/**
735
-	 * Adds a user to an access collection.
736
-	 *
737
-	 * Triggers the 'access:collections:add_user', 'collection' plugin hook.
738
-	 *
739
-	 * @param int $user_guid     GUID of the user to add
740
-	 * @param int $collection_id ID of the collection to add them to
741
-	 * @return bool
742
-	 */
743
-	public function addUser($user_guid, $collection_id) {
744
-
745
-		$collection = $this->get($collection_id);
746
-
747
-		if (!$collection) {
748
-			return false;
749
-		}
750
-
751
-		if (!$this->entities->exists($user_guid)) {
752
-			return false;
753
-		}
754
-
755
-		$hook_params = [
756
-			'collection_id' => $collection->id,
757
-			'user_guid' => (int) $user_guid
758
-		];
759
-
760
-		$result = $this->hooks->trigger('access:collections:add_user', 'collection', $hook_params, true);
761
-		if ($result == false) {
762
-			return false;
763
-		}
764
-
765
-		// if someone tries to insert the same data twice, we do a no-op on duplicate key
766
-		$query = "
714
+        return $this->db->getDataRow($query, $callback, [
715
+            ':id' => (int) $collection_id,
716
+        ]);
717
+    }
718
+
719
+    /**
720
+     * Check if user is already in the collection
721
+     *
722
+     * @param int $user_guid     GUID of the user
723
+     * @param int $collection_id ID of the collection
724
+     * @return bool
725
+     */
726
+    public function hasUser($user_guid, $collection_id) {
727
+        $options = [
728
+            'guids' => (int) $user_guid,
729
+            'count' => true,
730
+        ];
731
+        return (bool) $this->getMembers($collection_id, $options);
732
+    }
733
+
734
+    /**
735
+     * Adds a user to an access collection.
736
+     *
737
+     * Triggers the 'access:collections:add_user', 'collection' plugin hook.
738
+     *
739
+     * @param int $user_guid     GUID of the user to add
740
+     * @param int $collection_id ID of the collection to add them to
741
+     * @return bool
742
+     */
743
+    public function addUser($user_guid, $collection_id) {
744
+
745
+        $collection = $this->get($collection_id);
746
+
747
+        if (!$collection) {
748
+            return false;
749
+        }
750
+
751
+        if (!$this->entities->exists($user_guid)) {
752
+            return false;
753
+        }
754
+
755
+        $hook_params = [
756
+            'collection_id' => $collection->id,
757
+            'user_guid' => (int) $user_guid
758
+        ];
759
+
760
+        $result = $this->hooks->trigger('access:collections:add_user', 'collection', $hook_params, true);
761
+        if ($result == false) {
762
+            return false;
763
+        }
764
+
765
+        // if someone tries to insert the same data twice, we do a no-op on duplicate key
766
+        $query = "
767 767
 			INSERT INTO {$this->membership_table}
768 768
 				SET access_collection_id = :access_collection_id,
769 769
 				    user_guid = :user_guid
770 770
 				ON DUPLICATE KEY UPDATE user_guid = user_guid
771 771
 		";
772 772
 
773
-		$result = $this->db->insertData($query, [
774
-			':access_collection_id' => (int) $collection->id,
775
-			':user_guid' => (int) $user_guid,
776
-		]);
773
+        $result = $this->db->insertData($query, [
774
+            ':access_collection_id' => (int) $collection->id,
775
+            ':user_guid' => (int) $user_guid,
776
+        ]);
777 777
 
778
-		$this->access_cache->clear();
778
+        $this->access_cache->clear();
779 779
 		
780
-		return $result !== false;
781
-	}
782
-
783
-	/**
784
-	 * Removes a user from an access collection.
785
-	 *
786
-	 * Triggers the 'access:collections:remove_user', 'collection' plugin hook.
787
-	 *
788
-	 * @param int $user_guid     GUID of the user
789
-	 * @param int $collection_id ID of the collection
790
-	 * @return bool
791
-	 */
792
-	public function removeUser($user_guid, $collection_id) {
793
-
794
-		$params = [
795
-			'collection_id' => (int) $collection_id,
796
-			'user_guid' => (int) $user_guid,
797
-		];
798
-
799
-		if (!$this->hooks->trigger('access:collections:remove_user', 'collection', $params, true)) {
800
-			return false;
801
-		}
802
-
803
-		$query = "
780
+        return $result !== false;
781
+    }
782
+
783
+    /**
784
+     * Removes a user from an access collection.
785
+     *
786
+     * Triggers the 'access:collections:remove_user', 'collection' plugin hook.
787
+     *
788
+     * @param int $user_guid     GUID of the user
789
+     * @param int $collection_id ID of the collection
790
+     * @return bool
791
+     */
792
+    public function removeUser($user_guid, $collection_id) {
793
+
794
+        $params = [
795
+            'collection_id' => (int) $collection_id,
796
+            'user_guid' => (int) $user_guid,
797
+        ];
798
+
799
+        if (!$this->hooks->trigger('access:collections:remove_user', 'collection', $params, true)) {
800
+            return false;
801
+        }
802
+
803
+        $query = "
804 804
 			DELETE FROM {$this->membership_table}
805 805
 			WHERE access_collection_id = :access_collection_id
806 806
 				AND user_guid = :user_guid
807 807
 		";
808 808
 
809
-		$this->access_cache->clear();
809
+        $this->access_cache->clear();
810 810
 
811
-		return (bool) $this->db->deleteData($query, [
812
-			':access_collection_id' => (int) $collection_id,
813
-			':user_guid' => (int) $user_guid,
814
-		]);
815
-	}
811
+        return (bool) $this->db->deleteData($query, [
812
+            ':access_collection_id' => (int) $collection_id,
813
+            ':user_guid' => (int) $user_guid,
814
+        ]);
815
+    }
816 816
 
817
-	/**
818
-	 * Returns access collections owned by the user
819
-	 *
820
-	 * @param int $owner_guid GUID of the owner
821
-	 * @return ElggAccessCollection[]|false
822
-	 */
823
-	public function getEntityCollections($owner_guid) {
817
+    /**
818
+     * Returns access collections owned by the user
819
+     *
820
+     * @param int $owner_guid GUID of the owner
821
+     * @return ElggAccessCollection[]|false
822
+     */
823
+    public function getEntityCollections($owner_guid) {
824 824
 
825
-		$callback = [$this, 'rowToElggAccessCollection'];
825
+        $callback = [$this, 'rowToElggAccessCollection'];
826 826
 
827
-		$query = "
827
+        $query = "
828 828
 			SELECT * FROM {$this->table}
829 829
 				WHERE owner_guid = :owner_guid
830 830
 				ORDER BY name ASC
831 831
 		";
832 832
 
833
-		$params = [
834
-			':owner_guid' => (int) $owner_guid,
835
-		];
833
+        $params = [
834
+            ':owner_guid' => (int) $owner_guid,
835
+        ];
836 836
 
837
-		return $this->db->getData($query, $callback, $params);
838
-	}
837
+        return $this->db->getData($query, $callback, $params);
838
+    }
839 839
 
840
-	/**
841
-	 * Get members of an access collection
842
-	 *
843
-	 * @param int   $collection_id The collection's ID
844
-	 * @param array $options       Ege* options
845
-	 * @return ElggEntity[]|false
846
-	 */
847
-	public function getMembers($collection_id, array $options = []) {
840
+    /**
841
+     * Get members of an access collection
842
+     *
843
+     * @param int   $collection_id The collection's ID
844
+     * @param array $options       Ege* options
845
+     * @return ElggEntity[]|false
846
+     */
847
+    public function getMembers($collection_id, array $options = []) {
848 848
 
849
-		$options['joins'][] = "JOIN {$this->membership_table} acm";
849
+        $options['joins'][] = "JOIN {$this->membership_table} acm";
850 850
 
851
-		$collection_id = (int) $collection_id;
852
-		$options['wheres'][] = "e.guid = acm.user_guid AND acm.access_collection_id = {$collection_id}";
851
+        $collection_id = (int) $collection_id;
852
+        $options['wheres'][] = "e.guid = acm.user_guid AND acm.access_collection_id = {$collection_id}";
853 853
 
854
-		return $this->entities->getEntities($options);
855
-	}
854
+        return $this->entities->getEntities($options);
855
+    }
856 856
 
857
-	/**
858
-	 * Return an array of collections that the entity is member of
859
-	 *
860
-	 * @param int $member_guid GUID of th member
861
-	 *
862
-	 * @return ElggAccessCollection[]|false
863
-	 */
864
-	public function getCollectionsByMember($member_guid) {
857
+    /**
858
+     * Return an array of collections that the entity is member of
859
+     *
860
+     * @param int $member_guid GUID of th member
861
+     *
862
+     * @return ElggAccessCollection[]|false
863
+     */
864
+    public function getCollectionsByMember($member_guid) {
865 865
 
866
-		$callback = [$this, 'rowToElggAccessCollection'];
866
+        $callback = [$this, 'rowToElggAccessCollection'];
867 867
 
868
-		$query = "
868
+        $query = "
869 869
 			SELECT ac.* FROM {$this->table} ac
870 870
 				JOIN {$this->membership_table} acm
871 871
 					ON ac.id = acm.access_collection_id
@@ -873,58 +873,58 @@  discard block
 block discarded – undo
873 873
 				ORDER BY name ASC
874 874
 		";
875 875
 
876
-		return $this->db->getData($query, $callback, [
877
-			':member_guid' => (int) $member_guid,
878
-		]);
879
-	}
880
-
881
-	/**
882
-	 * Return the name of an ACCESS_* constant or an access collection,
883
-	 * but only if the logged in user owns the access collection or is an admin.
884
-	 * Ownership requirement prevents us from exposing names of access collections
885
-	 * that current user has been added to by other members and may contain
886
-	 * sensitive classification of the current user (e.g. close friends vs acquaintances).
887
-	 *
888
-	 * Returns a string in the language of the user for global access levels, e.g.'Public, 'Friends', 'Logged in', 'Private';
889
-	 * or a name of the owned access collection, e.g. 'My work colleagues';
890
-	 * or a name of the group or other access collection, e.g. 'Group: Elgg technical support';
891
-	 * or 'Limited' if the user access is restricted to read-only, e.g. a friends collection the user was added to
892
-	 *
893
-	 * @param int $entity_access_id The entity's access id
894
-	 *
895
-	 * @return string
896
-	 * @since 1.11
897
-	 */
898
-	public function getReadableAccessLevel($entity_access_id) {
899
-		$access = (int) $entity_access_id;
900
-
901
-		$translator = $this->translator;
902
-
903
-		// Check if entity access id is a defined global constant
904
-		$access_array = [
905
-			ACCESS_PRIVATE => $translator->translate("PRIVATE"),
906
-			ACCESS_FRIENDS => $translator->translate("access:friends:label"),
907
-			ACCESS_LOGGED_IN => $translator->translate("LOGGED_IN"),
908
-			ACCESS_PUBLIC => $translator->translate("PUBLIC"),
909
-		];
910
-
911
-		if (array_key_exists($access, $access_array)) {
912
-			return $access_array[$access];
913
-		}
914
-
915
-		// Entity access id is probably a custom access collection
916
-		// Check if the user has write access to it and can see it's label
917
-		// Admins should always be able to see the readable version
918
-		$collection = $this->get($access);
919
-
920
-		$user_guid = $this->session->getLoggedInUserGuid();
876
+        return $this->db->getData($query, $callback, [
877
+            ':member_guid' => (int) $member_guid,
878
+        ]);
879
+    }
880
+
881
+    /**
882
+     * Return the name of an ACCESS_* constant or an access collection,
883
+     * but only if the logged in user owns the access collection or is an admin.
884
+     * Ownership requirement prevents us from exposing names of access collections
885
+     * that current user has been added to by other members and may contain
886
+     * sensitive classification of the current user (e.g. close friends vs acquaintances).
887
+     *
888
+     * Returns a string in the language of the user for global access levels, e.g.'Public, 'Friends', 'Logged in', 'Private';
889
+     * or a name of the owned access collection, e.g. 'My work colleagues';
890
+     * or a name of the group or other access collection, e.g. 'Group: Elgg technical support';
891
+     * or 'Limited' if the user access is restricted to read-only, e.g. a friends collection the user was added to
892
+     *
893
+     * @param int $entity_access_id The entity's access id
894
+     *
895
+     * @return string
896
+     * @since 1.11
897
+     */
898
+    public function getReadableAccessLevel($entity_access_id) {
899
+        $access = (int) $entity_access_id;
900
+
901
+        $translator = $this->translator;
902
+
903
+        // Check if entity access id is a defined global constant
904
+        $access_array = [
905
+            ACCESS_PRIVATE => $translator->translate("PRIVATE"),
906
+            ACCESS_FRIENDS => $translator->translate("access:friends:label"),
907
+            ACCESS_LOGGED_IN => $translator->translate("LOGGED_IN"),
908
+            ACCESS_PUBLIC => $translator->translate("PUBLIC"),
909
+        ];
910
+
911
+        if (array_key_exists($access, $access_array)) {
912
+            return $access_array[$access];
913
+        }
914
+
915
+        // Entity access id is probably a custom access collection
916
+        // Check if the user has write access to it and can see it's label
917
+        // Admins should always be able to see the readable version
918
+        $collection = $this->get($access);
919
+
920
+        $user_guid = $this->session->getLoggedInUserGuid();
921 921
 		
922
-		if (!$collection || !$user_guid) {
923
-			// return 'Limited' if there is no logged in user or collection can not be loaded
924
-			return $translator->translate('access:limited:label');
925
-		}
922
+        if (!$collection || !$user_guid) {
923
+            // return 'Limited' if there is no logged in user or collection can not be loaded
924
+            return $translator->translate('access:limited:label');
925
+        }
926 926
 
927
-		return $collection->getDisplayName();
928
-	}
927
+        return $collection->getDisplayName();
928
+    }
929 929
 
930 930
 }
Please login to merge, or discard this patch.
engine/classes/ElggAccessCollection.php 1 patch
Indentation   +219 added lines, -219 removed lines patch added patch discarded remove patch
@@ -12,225 +12,225 @@
 block discarded – undo
12 12
  */
13 13
 class ElggAccessCollection extends ElggData {
14 14
 
15
-	/**
16
-	 * Create an access collection object
17
-	 *
18
-	 * @param stdClass $row Database row
19
-	 * @throws InvalidArgumentException
20
-	 */
21
-	public function __construct(stdClass $row = null) {
22
-		$this->initializeAttributes();
23
-
24
-		foreach ((array) $row as $key => $value) {
25
-			$this->attributes[$key] = $value;
26
-		}
27
-	}
28
-
29
-	/**
30
-	 * Initialize the attributes array
31
-	 *
32
-	 * @see ElggData::initializeAttributes()
33
-	 * @return void
34
-	 */
35
-	protected function initializeAttributes() {
36
-		parent::initializeAttributes();
37
-
38
-		$this->attributes['id'] = null;
39
-		$this->attributes['owner_guid'] = null;
40
-		$this->attributes['name'] = null;
41
-	}
42
-
43
-	/**
44
-	 * Set an attribute
45
-	 *
46
-	 * @param string $name  Name
47
-	 * @param mixed  $value Value
48
-	 * @return void
49
-	 * @throws RuntimeException
50
-	 */
51
-	public function __set($name, $value) {
52
-		if (in_array($name, ['id', 'owner_guid'])) {
53
-			throw new RuntimeException("$name can not be set at runtime");
54
-		}
55
-		$this->attributes[$name] = $value;
56
-	}
57
-
58
-	/**
59
-	 * Get an attribute
60
-	 *
61
-	 * @param string $name Name
62
-	 * @return mixed
63
-	 */
64
-	public function __get($name) {
65
-		if (array_key_exists($name, $this->attributes)) {
66
-			return $this->attributes[$name];
67
-		}
68
-
69
-		return null;
70
-	}
71
-
72
-	/**
73
-	 * Returns owner entity of the collection
74
-	 * @return \ElggEntity|false
75
-	 */
76
-	public function getOwnerEntity() {
77
-		return _elgg_services()->entityTable->get($this->owner_guid);
78
-	}
79
-
80
-	/**
81
-	 * Get readable access level name for this collection
82
-	 * @return string
83
-	 */
84
-	public function getDisplayName() {
85
-
86
-		$filter = function($name = null) {
87
-			if (!isset($name)) {
88
-				$name = _elgg_services()->translator->translate('access:limited:label');
89
-			}
90
-			$params = [
91
-				'access_collection' => $this,
92
-			];
93
-			return _elgg_services()->hooks->trigger('access_collection:name', $this->getType(), $params, $name);
94
-		};
95
-
96
-		$user = _elgg_services()->session->getLoggedInUser();
97
-		$owner = $this->getOwnerEntity();
98
-		if (!$user || !$owner) {
99
-			// User is not logged in or does not access to the owner entity:
100
-			// return default 'Limited' label
101
-			return $filter();
102
-		}
15
+    /**
16
+     * Create an access collection object
17
+     *
18
+     * @param stdClass $row Database row
19
+     * @throws InvalidArgumentException
20
+     */
21
+    public function __construct(stdClass $row = null) {
22
+        $this->initializeAttributes();
23
+
24
+        foreach ((array) $row as $key => $value) {
25
+            $this->attributes[$key] = $value;
26
+        }
27
+    }
28
+
29
+    /**
30
+     * Initialize the attributes array
31
+     *
32
+     * @see ElggData::initializeAttributes()
33
+     * @return void
34
+     */
35
+    protected function initializeAttributes() {
36
+        parent::initializeAttributes();
37
+
38
+        $this->attributes['id'] = null;
39
+        $this->attributes['owner_guid'] = null;
40
+        $this->attributes['name'] = null;
41
+    }
42
+
43
+    /**
44
+     * Set an attribute
45
+     *
46
+     * @param string $name  Name
47
+     * @param mixed  $value Value
48
+     * @return void
49
+     * @throws RuntimeException
50
+     */
51
+    public function __set($name, $value) {
52
+        if (in_array($name, ['id', 'owner_guid'])) {
53
+            throw new RuntimeException("$name can not be set at runtime");
54
+        }
55
+        $this->attributes[$name] = $value;
56
+    }
57
+
58
+    /**
59
+     * Get an attribute
60
+     *
61
+     * @param string $name Name
62
+     * @return mixed
63
+     */
64
+    public function __get($name) {
65
+        if (array_key_exists($name, $this->attributes)) {
66
+            return $this->attributes[$name];
67
+        }
68
+
69
+        return null;
70
+    }
71
+
72
+    /**
73
+     * Returns owner entity of the collection
74
+     * @return \ElggEntity|false
75
+     */
76
+    public function getOwnerEntity() {
77
+        return _elgg_services()->entityTable->get($this->owner_guid);
78
+    }
79
+
80
+    /**
81
+     * Get readable access level name for this collection
82
+     * @return string
83
+     */
84
+    public function getDisplayName() {
85
+
86
+        $filter = function($name = null) {
87
+            if (!isset($name)) {
88
+                $name = _elgg_services()->translator->translate('access:limited:label');
89
+            }
90
+            $params = [
91
+                'access_collection' => $this,
92
+            ];
93
+            return _elgg_services()->hooks->trigger('access_collection:name', $this->getType(), $params, $name);
94
+        };
95
+
96
+        $user = _elgg_services()->session->getLoggedInUser();
97
+        $owner = $this->getOwnerEntity();
98
+        if (!$user || !$owner) {
99
+            // User is not logged in or does not access to the owner entity:
100
+            // return default 'Limited' label
101
+            return $filter();
102
+        }
103 103
 		
104
-		if ($user->isAdmin() || $owner->guid == $user->guid) {
105
-			return $filter($this->name);
106
-		}
107
-
108
-		return $filter();
109
-	}
110
-
111
-	/**
112
-	 * {@inheritdoc}
113
-	 */
114
-	public function save() {
115
-		if ($this->id > 0) {
116
-			return _elgg_services()->accessCollections->rename($this->id, $this->name);
117
-		} else {
118
-			return _elgg_services()->accessCollections->create($this->name, $this->owner_guid);
119
-		}
120
-	}
121
-
122
-	/**
123
-	 * {@inheritdoc}
124
-	 */
125
-	public function delete() {
126
-		return _elgg_services()->accessCollections->delete($this->id);
127
-	}
128
-
129
-	/**
130
-	 * Check if user can this collection
131
-	 *
132
-	 * @param int $user_guid GUID of the user
133
-	 * @return bool
134
-	 */
135
-	public function canEdit($user_guid = null) {
136
-		return _elgg_services()->accessCollections->canEdit($this->id, $user_guid);
137
-	}
138
-
139
-	/**
140
-	 * Returns members of the access collection
141
-	 *
142
-	 * @param array $options ege options
143
-	 * @return ElggEntity|int|false
144
-	 */
145
-	public function getMembers(array $options = []) {
146
-		return _elgg_services()->accessCollections->getMembers($this->id, $options);
147
-	}
148
-
149
-	/**
150
-	 * Checks if user is already in access collection
151
-	 *
152
-	 * @param int $member_guid GUID of the user
153
-	 * @return bool
154
-	 */
155
-	public function hasMember($member_guid = 0) {
156
-		return _elgg_services()->accessCollections->hasUser($member_guid, $this->id);
157
-	}
158
-
159
-	/**
160
-	 * Adds a new member to access collection
161
-	 *
162
-	 * @param int $member_guid GUID of the user
163
-	 * @return bool
164
-	 */
165
-	public function addMember($member_guid = 0) {
166
-		return _elgg_services()->accessCollections->addUser($member_guid, $this->id);
167
-	}
168
-
169
-	/**
170
-	 * Removes a user from access collection
171
-	 *
172
-	 * @param int $member_guid GUID of the user
173
-	 * @return bool
174
-	 */
175
-	public function removeMember($member_guid = 0) {
176
-		return _elgg_services()->accessCollections->removeUser($member_guid, $this->id);
177
-	}
178
-
179
-	/**
180
-	 * {@inheritdoc}
181
-	 */
182
-	public function getURL() {
183
-		$type = $this->getType();
184
-		$params = [
185
-			'access_collection' => $this,
186
-		];
187
-		$url = _elgg_services()->hooks->trigger('access_collection:url', $type, $params, $url);
188
-		return elgg_normalize_url($url);
189
-	}
190
-
191
-	/**
192
-	 * {@inheritdoc}
193
-	 */
194
-	public function toObject() {
195
-		$object = new stdClass();
196
-		$object->type = $this->getType();
197
-		$object->subtype = $this->getSubtype();
198
-		$object->id = $this->id;
199
-		$object->owner_guid = $this->owner_guid;
200
-		$object->name = $this->name;
201
-
202
-		$params = [
203
-			'access_collection' => $this,
204
-		];
205
-		return _elgg_services()->hooks->trigger('to:object', 'access_collection', $params, $object);
206
-	}
207
-
208
-	/**
209
-	 * {@inheritdoc}
210
-	 */
211
-	public function getSystemLogID() {
212
-		return $this->id;
213
-	}
214
-
215
-	/**
216
-	 * {@inheritdoc}
217
-	 */
218
-	public function getObjectFromID($id) {
219
-		return _elgg_services()->accessCollections->get($id);
220
-	}
221
-
222
-	/**
223
-	 * {@inheritdoc}
224
-	 */
225
-	public function getType() {
226
-		return 'access_collection';
227
-	}
228
-
229
-	/**
230
-	 * {@inheritdoc}
231
-	 */
232
-	public function getSubtype() {
233
-		return $this->name;
234
-	}
104
+        if ($user->isAdmin() || $owner->guid == $user->guid) {
105
+            return $filter($this->name);
106
+        }
107
+
108
+        return $filter();
109
+    }
110
+
111
+    /**
112
+     * {@inheritdoc}
113
+     */
114
+    public function save() {
115
+        if ($this->id > 0) {
116
+            return _elgg_services()->accessCollections->rename($this->id, $this->name);
117
+        } else {
118
+            return _elgg_services()->accessCollections->create($this->name, $this->owner_guid);
119
+        }
120
+    }
121
+
122
+    /**
123
+     * {@inheritdoc}
124
+     */
125
+    public function delete() {
126
+        return _elgg_services()->accessCollections->delete($this->id);
127
+    }
128
+
129
+    /**
130
+     * Check if user can this collection
131
+     *
132
+     * @param int $user_guid GUID of the user
133
+     * @return bool
134
+     */
135
+    public function canEdit($user_guid = null) {
136
+        return _elgg_services()->accessCollections->canEdit($this->id, $user_guid);
137
+    }
138
+
139
+    /**
140
+     * Returns members of the access collection
141
+     *
142
+     * @param array $options ege options
143
+     * @return ElggEntity|int|false
144
+     */
145
+    public function getMembers(array $options = []) {
146
+        return _elgg_services()->accessCollections->getMembers($this->id, $options);
147
+    }
148
+
149
+    /**
150
+     * Checks if user is already in access collection
151
+     *
152
+     * @param int $member_guid GUID of the user
153
+     * @return bool
154
+     */
155
+    public function hasMember($member_guid = 0) {
156
+        return _elgg_services()->accessCollections->hasUser($member_guid, $this->id);
157
+    }
158
+
159
+    /**
160
+     * Adds a new member to access collection
161
+     *
162
+     * @param int $member_guid GUID of the user
163
+     * @return bool
164
+     */
165
+    public function addMember($member_guid = 0) {
166
+        return _elgg_services()->accessCollections->addUser($member_guid, $this->id);
167
+    }
168
+
169
+    /**
170
+     * Removes a user from access collection
171
+     *
172
+     * @param int $member_guid GUID of the user
173
+     * @return bool
174
+     */
175
+    public function removeMember($member_guid = 0) {
176
+        return _elgg_services()->accessCollections->removeUser($member_guid, $this->id);
177
+    }
178
+
179
+    /**
180
+     * {@inheritdoc}
181
+     */
182
+    public function getURL() {
183
+        $type = $this->getType();
184
+        $params = [
185
+            'access_collection' => $this,
186
+        ];
187
+        $url = _elgg_services()->hooks->trigger('access_collection:url', $type, $params, $url);
188
+        return elgg_normalize_url($url);
189
+    }
190
+
191
+    /**
192
+     * {@inheritdoc}
193
+     */
194
+    public function toObject() {
195
+        $object = new stdClass();
196
+        $object->type = $this->getType();
197
+        $object->subtype = $this->getSubtype();
198
+        $object->id = $this->id;
199
+        $object->owner_guid = $this->owner_guid;
200
+        $object->name = $this->name;
201
+
202
+        $params = [
203
+            'access_collection' => $this,
204
+        ];
205
+        return _elgg_services()->hooks->trigger('to:object', 'access_collection', $params, $object);
206
+    }
207
+
208
+    /**
209
+     * {@inheritdoc}
210
+     */
211
+    public function getSystemLogID() {
212
+        return $this->id;
213
+    }
214
+
215
+    /**
216
+     * {@inheritdoc}
217
+     */
218
+    public function getObjectFromID($id) {
219
+        return _elgg_services()->accessCollections->get($id);
220
+    }
221
+
222
+    /**
223
+     * {@inheritdoc}
224
+     */
225
+    public function getType() {
226
+        return 'access_collection';
227
+    }
228
+
229
+    /**
230
+     * {@inheritdoc}
231
+     */
232
+    public function getSubtype() {
233
+        return $this->name;
234
+    }
235 235
 
236 236
 }
Please login to merge, or discard this patch.