Elgg  Version master
plaintext.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 $output = 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  $output .= elgg_echo($category, [], (string) $recipient->language) . PHP_EOL;
85 
86  /* @var $notification Notification */
87  foreach ($sorted_notifications as $notification) {
88  /* @var $event \Elgg\Notifications\NotificationEvent */
89  $event = elgg_extract('event', $notification->params);
90 
91  $output .= ' - ';
92  $output .= $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  $output .= ' ' . $object->getURL();
104  }
105 
106  $output .= PHP_EOL;
107  }
108 
109  $output .= PHP_EOL . PHP_EOL;
110 }
111 
112 if (empty($output)) {
113  return;
114 }
115 
116 // add salutation and sign-off
117 echo elgg_view('notifications/body', [
118  'body' => $output,
119  'recipient' => $recipient,
120 ]);
$recipient
Definition: plaintext.php:13
$notifications
Definition: plaintext.php:12
if(!empty($unknowns)) $output
Definition: plaintext.php:79
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($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
$vars['class']
Elgg long text input (plaintext) Displays a long text input field that should not be overridden by wy...
Definition: plaintext.php:11
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
foreach($notifications as $index=> $notification) if(empty($sorted)) $unknowns
Definition: plaintext.php:66
if($email instanceof\Elgg\Email) $object
Definition: body.php:24
$index
Definition: gallery.php:40
if(empty($notifications)||!$recipient instanceof\ElggEntity) $sorted
Definition: plaintext.php:20