Elgg  Version 4.3
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\Hook $hook) {
23  if (!elgg_is_admin_logged_in()) {
24  return;
25  }
26 
27  /* @var $return MenuItems */
28  $return = $hook->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\Hook $hook) {
63  if (!$page_owner instanceof \ElggUser || !$page_owner->canEdit()) {
64  return;
65  }
66 
67  /* @var $result MenuItems */
68  $result = $hook->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\Hook $hook): MenuItems {
97  /* @var $result MenuItems */
98  $result = $hook->getValue();
99 
100  $entity_type = $hook->getParam('entity_type', '');
101  $entity_subtype = $hook->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 = $hook->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 = $hook->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\Hook $hook): MenuItems {
168  /* @var $result MenuItems */
169  $result = $hook->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 }
static registerFilterTabs(\Elgg\Hook $hook)
Register the default All and Mine filter menu items.
Definition: Filter.php:96
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
elgg_echo($message_key, array $args=[], $language="")
Elgg language module Functions to manage language and translations.
Definition: languages.php:18
static factory($options)
Create an ElggMenuItem from an associative array.
Models an event passed to hook handlers.
Definition: Hook.php:11
elgg_generate_url($name, array $parameters=[])
Generate a URL for named route.
$user
Definition: ban.php:7
static registerAdminUsers(\Elgg\Hook $hook)
Register the default All and Mine filter menu items.
Definition: Filter.php:167
static registerAdminUpgrades(\Elgg\Hook $hook)
Add menu items to the filter menu on the admin upgrades page.
Definition: Filter.php:22
elgg_get_page_owner_entity()
Gets the owner entity for the current page.
Definition: pageowner.php:23
$page_owner
Definition: add.php:15
elgg_extract($key, $array, $default=null, $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
Definition: elgglib.php:547
Register menu items to the filter menu.
Definition: Filter.php:13
if($item instanceof\ElggEntity) elseif($item instanceof\ElggRiverItem) elseif($item instanceof ElggRelationship) elseif(is_callable([$item, 'getType']))
Definition: item.php:48
static registerNotificationSettings(\Elgg\Hook $hook)
Register the settings tab to the notification settings pages.
Definition: Filter.php:61
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