Elgg  Version 6.3
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 an object is subscribable we should subscribe the owner
32  if ($entity instanceof \ElggObject && !$entity->hasCapability('subscribable')) {
33  // not subscribable, so check if there are notification events for this object
34  $notification_events = _elgg_services()->notifications->getEvents();
35  if (!isset($notification_events[$entity->getType()]) || !isset($notification_events[$entity->getType()][$entity->getSubtype()])) {
36  // no notification events registered for this entity type/subtype
37  // so there is no need to subscribe
38  // this also prevents the database from flooding with relationships that are never used (e.g. subscriptions to site notifications)
39  return;
40  }
41  }
42 
43  $enabled_methods = $owner->getNotificationSettings('content_create', true);
44  if (empty($enabled_methods)) {
45  return;
46  }
47 
48  $entity->addSubscription($owner->guid, $enabled_methods);
49  }
50 }
$entity
Definition: reset.php:8
$owner
Definition: upload.php:7
Models an event passed to event handlers.
Definition: Event.php:11
Apply subscriptions based on preferences.
__invoke(\Elgg\Event $event)
Subscribe to content you just created in order to receive notifications.
_elgg_services()
Get the global service provider.
Definition: elgglib.php:337
foreach($entity->getSubscriptions($user->guid) as $subscription) $notification_events
Definition: details.php:44