Elgg  Version master
CreateContentEventHandler.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg\Notifications;
4 
12 
20  public function __invoke(\Elgg\Event $event): void {
21  $entity = $event->getObject();
22  if (!$entity instanceof \ElggObject && !$entity instanceof \ElggGroup) {
23  return;
24  }
25 
26  $owner = $entity->getOwnerEntity();
27  if (!$owner instanceof \ElggUser) {
28  return;
29  }
30 
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  }
40 
41  $content_preferences = $owner->getNotificationSettings('content_create');
42  $enabled_methods = array_keys(array_filter($content_preferences));
43 
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  }
51 
52  $entity->addSubscription($owner->guid, $method);
53  }
54  }
55 }
$owner
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
$entity
Definition: reset.php:8
foreach($entity->getSubscriptions($user->guid) as $subscription) $notification_events
Definition: details.php:44
_elgg_services()
Get the global service provider.
Definition: elgglib.php:351
elgg_get_notification_methods()
Returns registered delivery methods for notifications [ &#39;email&#39; => &#39;email&#39;, &#39;sms&#39; => &#39;sms&#39;...
$methods
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.