Elgg  Version 6.2
AutoSubscribeHandler.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg\Comments;
4 
13 
21  public function __invoke(\Elgg\Event $event): void {
22  $object = $event->getObject();
23  if (!$object instanceof \ElggComment) {
24  return;
25  }
26 
27  $owner = $object->getOwnerEntity();
28  $container = $object->getContainerEntity();
29  if (!$owner instanceof \ElggUser || !$container instanceof \ElggEntity) {
30  return;
31  }
32 
33  if ($container->hasMutedNotifications($owner->guid)) {
34  // user already said to not receive notifications, so don't force it
35  return;
36  }
37 
38  $comment_preferences = $owner->getNotificationSettings('create_comment');
39  $enabled_methods = array_keys(array_filter($comment_preferences));
40  if (empty($enabled_methods)) {
41  return;
42  }
43 
44  $container->addSubscription($owner->guid, $enabled_methods);
45  }
46 }
$owner
Definition: upload.php:7
$container
Definition: delete.php:23
When a comment is created subscribe the owner to the container (original content) of the comment if t...
__invoke(\Elgg\Event $event)
Subscribe the user to the comment container.
Models an event passed to event handlers.
Definition: Event.php:11
if($email instanceof \Elgg\Email) $object
Definition: body.php:24