Elgg  Version 6.1
html.php
Go to the documentation of this file.
1 <?php
11 
12 $notifications = (array) elgg_extract('notifications', $vars);
13 $recipient = elgg_extract('recipient', $vars);
14 if (empty($notifications) || !$recipient instanceof \ElggEntity) {
15  return;
16 }
17 
18 // notification listing
19 // sort by content type
20 $sorted = [];
21 
22 /* @var $notification Notification */
23 foreach ($notifications as $index => $notification) {
24  /* @var $event \Elgg\Notifications\NotificationEvent */
25  $event = elgg_extract('event', $notification->params);
26 
27  $category = 'other';
28 
29  $object = $event->getObject();
30  if (empty($object)) {
31  continue;
32  }
33 
34  $entity = false;
35  if ($object instanceof \ElggEntity) {
36  $entity = $object;
37  } elseif ($object instanceof \ElggAnnotation) {
38  $entity = $object->getEntity();
39  }
40 
41  if ($entity instanceof \ElggEntity && $recipient instanceof \ElggUser && !$entity->hasAccess($recipient->guid)) {
42  // user no longer has access to entity
43  continue;
44  }
45 
46  if ($entity instanceof \ElggEntity) {
47  if (elgg_language_key_exists("collection:{$entity->type}:{$entity->subtype}")) {
48  $category = "collection:{$entity->type}:{$entity->subtype}";
49  } elseif (elgg_language_key_exists("item:{$entity->type}:{$entity->subtype}")) {
50  $category = "item:{$entity->type}:{$entity->subtype}";
51  }
52  }
53 
54  if (!array_key_exists($category, $sorted)) {
55  $sorted[$category] = [];
56  }
57 
58  $sorted[$category][$object->getTimeCreated() . '_' . $index] = $notification;
59 }
60 
61 if (empty($sorted)) {
62  // can happen if all notification objects have been removed
63  return;
64 }
65 
66 $unknowns = elgg_extract('other', $sorted, []);
67 unset($sorted['other']);
68 
69 // sort based on the actual elgg_echo of the category not the language key
70 uksort($sorted, function($a, $b) {
71  return strnatcasecmp(elgg_echo($a), elgg_echo($b));
72 });
73 
74 if (!empty($unknowns)) {
75  // add the rest to the end of the list
76  $sorted['other'] = $unknowns;
77 }
78 
79 $body = elgg_echo('notifications:delayed_email:body:intro') . PHP_EOL . PHP_EOL;
80 
81 foreach ($sorted as $category => $sorted_notifications) {
82  uksort($sorted_notifications, 'strnatcasecmp');
83 
84  $body .= elgg_format_element('strong', [], elgg_echo($category, [], (string) $recipient->language)) . PHP_EOL;
85 
86  $lis = [];
87  /* @var $notification Notification */
88  foreach ($sorted_notifications as $notification) {
89  /* @var $event \Elgg\Notifications\NotificationEvent */
90  $event = elgg_extract('event', $notification->params);
91 
92  $text = $notification->summary ?: $notification->subject;
93 
94  $object = $event->getObject();
95  $entity = false;
96  if ($object instanceof \ElggEntity) {
97  $entity = $object;
98  } elseif ($object instanceof \ElggAnnotation) {
99  $entity = $object->getEntity();
100  }
101 
102  if ($entity instanceof \ElggEntity) {
103  $text = elgg_view('output/url', [
104  'text' => $text,
105  'href' => $entity->getURL(),
106  'is_trusted' => true,
107  ]);
108  }
109 
110  $lis[] = elgg_format_element('li', [], $text);
111  }
112 
113  $body .= elgg_format_element('ul', [], implode(PHP_EOL, $lis));
114  $body .= PHP_EOL . PHP_EOL;
115 }
116 
117 if (empty($body)) {
118  return;
119 }
120 
121 // add salutation and sign-off
122 echo elgg_view('notifications/body', [
123  'body' => $body,
124  'recipient' => $recipient,
125 ]);
$notifications
Definition: html.php:12
foreach($notifications as $index=> $notification) if(empty($sorted)) $unknowns
Definition: html.php:66
elgg_echo(string $message_key, array $args=[], string $language= '')
Elgg language module Functions to manage language and translations.
Definition: languages.php:17
Entity Annotation.
if(!empty($unknowns)) $body
Definition: html.php:79
$recipient
Definition: html.php:13
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:256
elgg_view(string $view, array $vars=[], string $viewtype= '')
Return a parsed view.
Definition: views.php:156
elgg_language_key_exists(string $key, string $language= 'en')
Check if a given language key exists.
Definition: languages.php:44
$entity
Definition: reset.php:8
$notification
Definition: body.php:13
if(empty($notifications)||!$recipient instanceof\ElggEntity) $sorted
Definition: html.php:20
if($email instanceof\Elgg\Email) $object
Definition: body.php:24
$vars['head']
Definition: html.php:24
elgg_format_element(string $tag_name, array $attributes=[], string $text= '', array $options=[])
Format an HTML element.
Definition: output.php:145
$index
Definition: gallery.php:40
$text
Definition: button.php:33