Elgg  Version master
details.php
Go to the documentation of this file.
1 <?php
12 
13 $user = get_entity((int) elgg_extract('user_guid', $vars));
14 $entity = get_entity((int) elgg_extract('entity_guid', $vars));
15 
16 if (!$user instanceof \ElggUser || !$entity instanceof \ElggEntity) {
17  throw new BadRequestException();
18 }
19 
20 if (!$user->canEdit()) {
21  throw new EntityPermissionsException();
22 }
23 
25 if (empty($methods)) {
26  throw new PageNotFoundException();
27 }
28 
30 foreach ($methods as $method) {
31  $label = elgg_echo("notification:method:{$method}");
32  $method_options[$label] = $method;
33 }
34 
36 foreach ($entity->getSubscriptions($user->guid) as $subscription) {
37  $parts = explode(':', $subscription->relationship);
38  if (count($parts) > 2) {
39  list(, $type, $subtype, $action, $method) = $parts;
40  $detailed_subscriptions[$type][$subtype][$action][$method] = $method;
41  }
42 }
43 
45 $details = [];
46 foreach ($notification_events as $type => $subtypes) {
47  foreach ($subtypes as $subtype => $actions) {
48  foreach ($actions as $action => $handlers) {
50  foreach ($handlers as $handler) {
51  // can users configure this handler
52  if (!$handler::isConfigurableByUser()) {
53  continue;
54  }
55 
56  // can this handler be configured for the current container
57  if (!$handler::isConfigurableForEntity($entity)) {
58  continue;
59  }
60 
61  $label = elgg_echo("notification:{$type}:{$subtype}:{$action}");
63  '#type' => 'checkboxes',
64  '#label' => $label,
65  '#class' => 'elgg-subscription-details',
66  'name' => "subscriptions[{$entity->guid}][notify:{$type}:{$subtype}:{$action}]",
67  'options' => $method_options,
68  'value' => $detailed_subscriptions[$type][$subtype][$action] ?? [],
69  'align' => 'horizontal',
70  ]);
71 
72  // only show one checkbox per action
73  break;
74  }
75  }
76  }
77 }
78 
79 if (empty($details)) {
80  echo elgg_view_no_results(elgg_echo('notifications:subscriptions:details:no_results'));
81  return;
82 }
83 
84 ksort($details, SORT_NATURAL | SORT_FLAG_CASE);
85 echo implode('', $details);
86 
87 echo elgg_view_field([
88  '#type' => 'fieldset',
89  'align' => 'horizontal',
90  'justify' => 'right',
91  'fields' => [
92  [
93  '#type' => 'button',
94  'text' => elgg_echo('notifications:subscriptions:details:reset'),
95  'class' => ['elgg-button-delete', 'elgg-subscriptions-details-reset'],
96  ],
97  ],
98 ]);
$vars
Definition: theme.php:3
$subtype
Definition: delete.php:22
$type
Definition: delete.php:21
$handler
Definition: add.php:7
$entity
Ajax view to list user details on admin listings.
Definition: details.php:9
Thrown when request is malformatted.
Thrown when entity can not be edited or container permissions do not allow it to be written.
Thrown when page is not accessible.
$subtypes
if($view &&elgg_view_exists($view)) $label
Definition: field.php:26
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:246
elgg_echo(string $message_key, array $args=[], string $language='')
Elgg language module Functions to manage language and translations.
Definition: languages.php:17
get_entity(int $guid)
Loads and returns an entity object from a guid.
Definition: entities.php:68
elgg_view_no_results(string $text='')
Helper function to display a no results view.
Definition: views.php:1474
elgg_view_field(array $params=[])
Renders a form field, usually with a wrapper element, a label, help text, etc.
Definition: views.php:1116
elgg_get_notification_events()
Get the registered notification events in the format.
elgg_get_notification_methods()
Returns registered delivery methods for notifications [ 'email' => 'email', 'sms' => 'sms',...
if(empty($methods)) $method_options
Definition: details.php:29
foreach($methods as $method) $detailed_subscriptions
Definition: details.php:35
if(! $user instanceof \ElggUser||! $entity instanceof \ElggEntity) if(! $user->canEdit()) $methods
Definition: details.php:24
$user
Definition: details.php:13
foreach($entity->getSubscriptions($user->guid) as $subscription) $notification_events
Definition: details.php:44
$details
Definition: details.php:45
$action
Definition: subscribe.php:11
if(! $menu instanceof \Elgg\Menu\PreparedMenu) $actions
Definition: user_hover.php:21