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  /* @var $handler \Elgg\Notifications\NotificationEventHandler */
49  foreach ($actions as $action => $handler) {
50  // can users configure this handler
51  if (!$handler::isConfigurableByUser()) {
52  continue;
53  }
54 
55  // can this handler be configured for the current container
56  if (!$handler::isConfigurableForEntity($entity)) {
57  continue;
58  }
59 
60  $label = elgg_echo("notification:{$type}:{$subtype}:{$action}");
62  '#type' => 'checkboxes',
63  '#label' => $label,
64  '#class' => 'elgg-subscription-details',
65  'name' => "subscriptions[{$entity->guid}][notify:{$type}:{$subtype}:{$action}]",
66  'options' => $method_options,
67  'value' => $detailed_subscriptions[$type][$subtype][$action] ?? [],
68  'align' => 'horizontal',
69  ]);
70  }
71  }
72 }
73 
74 if (empty($details)) {
75  echo elgg_view('page/components/no_results', [
76  'no_results' => elgg_echo('notifications:subscriptions:details:no_results'),
77  ]);
78  return;
79 }
80 
81 ksort($details, SORT_NATURAL | SORT_FLAG_CASE);
82 echo implode('', $details);
83 
84 echo elgg_view_field([
85  '#type' => 'fieldset',
86  '#class' => 'mtm',
87  'align' => 'horizontal',
88  'justify' => 'right',
89  'fields' => [
90  [
91  '#type' => 'button',
92  'text' => elgg_echo('notifications:subscriptions:details:reset'),
93  'class' => ['elgg-button-delete', 'elgg-subscriptions-details-reset'],
94  ],
95  ],
96 ]);
if($view &&elgg_view_exists($view)) $label
Definition: field.php:26
elgg_view_field(array $params=[])
Renders a form field, usually with a wrapper element, a label, help text, etc.
Definition: views.php:1112
elgg_echo(string $message_key, array $args=[], string $language= '')
Elgg language module Functions to manage language and translations.
Definition: languages.php:17
$type
Definition: delete.php:21
$user
Definition: details.php:13
if(empty($methods)) $method_options
Definition: details.php:29
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
elgg_view(string $view, array $vars=[], string $viewtype= '')
Return a parsed view.
Definition: views.php:156
Thrown when page is not accessible.
get_entity(int $guid)
Loads and returns an entity object from a guid.
Definition: entities.php:70
Thrown when entity can not be edited or container permissions do not allow it to be written...
if(!$menu instanceof\Elgg\Menu\PreparedMenu) $actions
Definition: user_hover.php:16
foreach($entity->getSubscriptions($user->guid) as $subscription) $notification_events
Definition: details.php:44
$action
Definition: subscribe.php:11
$vars
Definition: theme.php:5
Thrown when request is malformatted.
$details
Definition: details.php:45
$subtype
Definition: delete.php:22
$subtypes
if(!$user instanceof\ElggUser||!$entity instanceof\ElggEntity) if(!$user->canEdit()) $methods
Definition: details.php:24
elgg_get_notification_methods()
Returns registered delivery methods for notifications [ &#39;email&#39; => &#39;email&#39;, &#39;sms&#39; => &#39;sms&#39;...
$handler
Definition: add.php:7
$entity
Ajax view to list user details on admin listings.
Definition: details.php:9
elgg_get_notification_events()
Get the registered notification events in the format.
foreach($methods as $method) $detailed_subscriptions
Definition: details.php:35