Elgg  Version master
Filter.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg\Menus;
4 
6 
13 class Filter {
14 
22  public static function registerAdminUpgrades(\Elgg\Event $event) {
23  if (!elgg_is_admin_logged_in()) {
24  return;
25  }
26 
27  /* @var $return MenuItems */
28  $return = $event->getValue();
29 
30  $return[] = \ElggMenuItem::factory([
31  'name' => 'pending',
32  'text' => elgg_echo('admin:upgrades:menu:pending'),
33  'href' => 'admin/upgrades',
34  'priority' => 100,
35  ]);
36 
37  $return[] = \ElggMenuItem::factory([
38  'name' => 'completed',
39  'text' => elgg_echo('admin:upgrades:menu:completed'),
40  'href' => 'admin/upgrades/finished',
41  'priority' => 200,
42  ]);
43 
44  $return[] = \ElggMenuItem::factory([
45  'name' => 'db',
46  'text' => elgg_echo('admin:upgrades:menu:db'),
47  'href' => 'admin/upgrades/db',
48  'priority' => 300,
49  ]);
50 
51  return $return;
52  }
53 
61  public static function registerNotificationSettings(\Elgg\Event $event) {
63  if (!$page_owner instanceof \ElggUser || !$page_owner->canEdit()) {
64  return;
65  }
66 
67  /* @var $result MenuItems */
68  $result = $event->getValue();
69 
71  'name' => 'settings',
72  'text' => elgg_echo('usersettings:notifications:menu:filter:settings'),
73  'href' => elgg_generate_url('settings:notifications', [
74  'username' => $page_owner->username,
75  ]),
76  'priority' => 100,
77  ]);
78 
80  'name' => 'users',
81  'text' => elgg_echo('collection:user:user'),
82  'href' => elgg_generate_url('settings:notifications:users', [
83  'username' => $page_owner->username,
84  ]),
85  'priority' => 200,
86  ]);
87  }
88 
96  public static function registerFilterTabs(\Elgg\Event $event): MenuItems {
97  /* @var $result MenuItems */
98  $result = $event->getValue();
99 
100  $entity_type = $event->getParam('entity_type', '');
101  $entity_subtype = $event->getParam('entity_subtype', '');
102  if (empty($entity_type) || empty($entity_subtype)) {
103  $route_name = elgg_get_current_route_name();
104  if (!empty($route_name)) {
105  // assume route name as '<purpose>:<entity type>:<entity subtype>:<sub>'
106  // eg collection:object:blog:owner or view:group:group
107  // @see http://learn.elgg.org/en/stable/guides/routing.html#routes-names
108  $route_parts = explode(':', $route_name);
109  $entity_type = elgg_extract(1, $route_parts, '');
110  $entity_subtype = elgg_extract(2, $route_parts, '');
111  }
112  }
113 
114  $all_link = $event->getParam('all_link');
115  if (empty($all_link)) {
116  if (elgg_route_exists("collection:{$entity_type}:{$entity_subtype}:all")) {
117  $all_link = elgg_generate_url("collection:{$entity_type}:{$entity_subtype}:all");
118  } elseif (elgg_route_exists("collection:{$entity_type}:all")) {
119  $all_link = elgg_generate_url("collection:{$entity_type}:all");
120  }
121  }
122 
123  if (!empty($all_link)) {
125  'name' => 'all',
126  'text' => elgg_echo('all'),
127  'href' => $all_link,
128  'priority' => 200,
129  ]);
130  }
131 
133  if ($user instanceof \ElggUser) {
134  $mine_link = $event->getParam('mine_link');
135  if (empty($mine_link)) {
136  if (elgg_route_exists("collection:{$entity_type}:{$entity_subtype}:owner")) {
137  $mine_link = elgg_generate_url("collection:{$entity_type}:{$entity_subtype}:owner", [
138  'username' => $user->username,
139  ]);
140  } elseif (elgg_route_exists("collection:{$entity_type}:owner")) {
141  $mine_link = elgg_generate_url("collection:{$entity_type}:owner", [
142  'username' => $user->username,
143  ]);
144  }
145  }
146 
147  if (!empty($mine_link)) {
149  'name' => 'mine',
150  'text' => elgg_echo('mine'),
151  'href' => $mine_link,
152  'priority' => 300,
153  ]);
154  }
155  }
156 
157  return $result;
158  }
159 
167  public static function registerAdminUsers(\Elgg\Event $event): MenuItems {
168  /* @var $result MenuItems */
169  $result = $event->getValue();
170 
172  'name' => 'all',
173  'text' => elgg_echo('all'),
174  'href' => 'admin/users',
175  'priority' => 100,
176  ]);
178  'name' => 'online',
179  'text' => elgg_echo('admin:users:online'),
180  'href' => 'admin/users/online',
181  'priority' => 200,
182  ]);
184  'name' => 'admins',
185  'text' => elgg_echo('admin:users:admins'),
186  'href' => 'admin/users/admins',
187  'priority' => 300,
188  ]);
190  'name' => 'banned',
191  'text' => elgg_echo('admin:users:banned'),
192  'href' => 'admin/users/banned',
193  'priority' => 400,
194  ]);
196  'name' => 'unvalidated',
197  'text' => elgg_echo('admin:users:unvalidated'),
198  'href' => 'admin/users/unvalidated',
199  'priority' => 500,
200  ]);
202  'name' => 'inactive',
203  'text' => elgg_echo('admin:users:inactive'),
204  'href' => 'admin/users/inactive',
205  'priority' => 600,
206  ]);
207 
209  'name' => 'search',
210  'icon' => 'search',
211  'text' => elgg_echo('search'),
212  'href' => false,
213  'class' => 'elgg-toggle',
214  'data-toggle-selector' => '.elgg-form-admin-users-search',
215  'priority' => 9999,
216  ]);
217 
218  return $result;
219  }
220 
228  public static function registerAvatarEdit(\Elgg\Event $event) {
229  $user = $event->getParam('entity', elgg_get_page_owner_entity());
230  if (!$user instanceof \ElggUser) {
231  return;
232  }
233 
234  /* @var $return MenuItems */
235  $return = $event->getValue();
236 
237  $return[] = \ElggMenuItem::factory([
238  'name' => 'edit_avatar',
239  'text' => elgg_echo('avatar:edit'),
240  'href' => elgg_generate_entity_url($user, 'edit', 'avatar'),
241  ]);
242 
243  return $return;
244  }
245 }
elgg_route_exists(string $name)
Check if a route is registered.
elgg_is_admin_logged_in()
Returns whether or not the viewer is currently logged in and an admin user.
Definition: sessions.php:52
elgg_get_current_route_name()
Get the route name for the current request.
Definition: pagehandler.php:98
static registerAvatarEdit(\Elgg\Event $event)
Add a link to the profile/edit filter menu.
Definition: Filter.php:228
static registerAdminUpgrades(\Elgg\Event $event)
Add menu items to the filter menu on the admin upgrades page.
Definition: Filter.php:22
elgg_echo(string $message_key, array $args=[], string $language= '')
Elgg language module Functions to manage language and translations.
Definition: languages.php:17
static factory(array $options)
Create an ElggMenuItem from an associative array.
if($item instanceof\ElggEntity) elseif($item instanceof\ElggRiverItem) elseif($item instanceof\ElggRelationship) elseif(is_callable([$item, 'getType']))
Definition: item.php:48
elgg_extract($key, $array, $default=null, bool $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
Definition: elgglib.php:254
static registerFilterTabs(\Elgg\Event $event)
Register the default All and Mine filter menu items.
Definition: Filter.php:96
elgg_generate_entity_url(ElggEntity $entity, string $resource= 'view', string $subresource=null, array $parameters=[])
Generate entity URL from a named route.
$user
Definition: ban.php:7
elgg_get_page_owner_entity()
Gets the owner entity for the current page.
Definition: pageowner.php:23
$page_owner
Definition: add.php:16
static registerAdminUsers(\Elgg\Event $event)
Register the default All and Mine filter menu items.
Definition: Filter.php:167
static registerNotificationSettings(\Elgg\Event $event)
Register the settings tab to the notification settings pages.
Definition: Filter.php:61
Register menu items to the filter menu.
Definition: Filter.php:13
elgg_generate_url(string $name, array $parameters=[])
Generate a URL for named route.
elgg_get_logged_in_user_entity()
Return the current logged in user, or null if no user is logged in.
Definition: sessions.php:24
A collection of menu items.
Definition: MenuItems.php:10
Models an event passed to event handlers.
Definition: Event.php:11