Elgg  Version master
Go to the documentation of this file.
1 <?php
3 namespace Elgg\Notifications;
20  public function __invoke(\Elgg\Event $event): void {
21  $entity = $event->getObject();
22  if (!$entity instanceof \ElggObject && !$entity instanceof \ElggGroup) {
23  return;
24  }
26  $owner = $entity->getOwnerEntity();
27  if (!$owner instanceof \ElggUser) {
28  return;
29  }
31  if ($entity instanceof \ElggObject) {
32  $notification_events = _elgg_services()->notifications->getEvents();
33  if (!isset($notification_events[$entity->getType()]) || !isset($notification_events[$entity->getType()][$entity->getSubtype()])) {
34  // no notification events registered for this entity type/subtype
35  // so there is no need to subscribe
36  // this also prevents the database from flooding with relationships that are never used (e.g. subscriptions to site notifications)
37  return;
38  }
39  }
41  $content_preferences = $owner->getNotificationSettings('content_create');
42  $enabled_methods = array_keys(array_filter($content_preferences));
44  // loop through all notification types
46  foreach ($enabled_methods as $method) {
47  // only enable supported methods
48  if (!in_array($method, $methods)) {
49  continue;
50  }
52  $entity->addSubscription($owner->guid, $method);
53  }
54  }
55 }
Definition: upload.php:7
c Accompany it with the information you received as to the offer to distribute corresponding source complete source code means all the source code for all modules it plus any associated interface definition plus the scripts used to control compilation and installation of the executable as a special the source code distributed need not include anything that is normally and so on of the operating system on which the executable unless that component itself accompanies the executable If distribution of executable or object code is made by offering access to copy from a designated then offering equivalent access to copy the source code from the same place counts as distribution of the source even though third parties are not compelled to copy the source along with the object code You may not or distribute the Program except as expressly provided under this License Any attempt otherwise to sublicense or distribute the Program is void
Definition: LICENSE.txt:215
Definition: reset.php:8
foreach($entity->getSubscriptions($user->guid) as $subscription) $notification_events
Definition: details.php:44
Get the global service provider.
Definition: elgglib.php:351
Returns registered delivery methods for notifications [ &#39;email&#39; => &#39;email&#39;, &#39;sms&#39; => &#39;sms&#39;...
Definition: subscribe.php:8
Models an event passed to event handlers.
Definition: Event.php:11
__invoke(\Elgg\Event $event)
Subscribe to content you just created in order to receive notifications.
Apply subscriptions based on preferences.