49 final public function send(): array {
62 $params[
'deliveries'] = $deliveries;
79 'methods_override' => (array)
elgg_extract(
'methods_override', $this->params, []),
93 return (
bool)
elgg_extract(
'apply_muting', $this->params,
true);
111 $object = $this->
event->getObject();
118 $exclude[] =
$object->owner_guid;
122 $exclude[] =
$object->container_guid;
168 return $this->service->getMethods();
196 $current_language = $translator->getCurrentLanguage();
202 $translator->setCurrentLanguage(
$recipient->getLanguage());
209 if ($this->service->isRegisteredMethod($method)) {
213 }
catch (\Throwable $t) {
214 $translator->setCurrentLanguage($current_language);
218 $translator->setCurrentLanguage($current_language);
221 $this->
getLogger()->info(
"Results for the notification event {$this->event->getDescription()}: " . print_r(
$result,
true));
235 if (!
_elgg_services()->events->hasHandler(
'send',
"notification:{$method}")) {
240 $actor = $this->
event->getActor();
241 $object = $this->
event->getObject();
284 $params[
'action'] = $this->
event->getAction();
309 if ($this->
getLogger()->isLoggable(LogLevel::INFO)) {
310 $logger_data = print_r((array) $notification->
toObject(),
true);
312 $this->
getLogger()->info(
'Notification sent: ' . $logger_data);
314 $this->
getLogger()->info(
'Notification was not sent: ' . $logger_data);
330 $notification =
new Notification($params[
'sender'], $params[
'recipient'], $params[
'language'], $params[
'subject'], $params[
'body'], $params[
'summary'], $params);
334 throw new RuntimeException(
"'prepare','notification' event must return an instance of " . Notification::class);
337 $type =
'notification:' . $this->
event->getDescription();
340 throw new RuntimeException(
"'prepare','{$type}' event must return an instance of " . Notification::class);
350 throw new RuntimeException(
"'format','notification:{$params['method']}' event must return an instance of " . Notification::class);
368 $actor = $this->
event->getActor() ?: null;
369 $object = $this->
event->getObject();
372 $subject_key =
"notification:{$this->event->getDescription()}:subject";
373 if (
_elgg_services()->translator->languageKeyExists($subject_key)) {
375 $actor?->getDisplayName(),
381 return _elgg_services()->translator->translate(
'notification:subject', [
$actor?->getDisplayName()]);
407 $actor = $this->
event->getActor() ?: null;
408 $object = $this->
event->getObject() ?: null;
411 $body_key =
"notification:{$this->event->getDescription()}:body";
415 $container_name =
'';
418 $container_name =
$container->getDisplayName();
422 $container_name =
'';
426 $actor?->getDisplayName(),
459 $object = $this->
event->getObject() ?: null;
461 return (
string)
$object?->getURL();
471 $actor = $this->
event->getActor();
483 $object = $this->
event->getObject();
509 return static::isConfigurableForUser($entity);
511 return static::isConfigurableForGroup($entity);
static isConfigurableByUser()
Is this event configurable by the user on the notification settings page.
static isConfigurableForEntity(\ElggEntity $entity)
Can this event be configured for a specific entity.
if(!elgg_get_config('trash_enabled')) $group
toObject()
Export notification.
prepareSubscriptions()
Returns subscriptions.
Exception thrown if an error which can only be found on runtime occurs.
static isConfigurableForUser(\ElggUser $user)
Can this event be configured for a specific user.
prepareNotification(array $params)
Prepares a notification for delivery.
excludeOwnerSubscribers()
Exclude the NotificationEvent object owner_guid when fetching the subscription records for this notif...
getMethods()
Returns methods to be used for this notification.
getNotificationURL(\ElggUser $recipient, string $method)
Returns the url related to this notification.
getNotificationSubject(\ElggUser $recipient, string $method)
Get subject for the notification.
getEventEntity()
Get the entity from the notification event.
sendNotification(int $guid, string $method, array $params=[])
Send a notification to a subscriber.
getSubscriptions()
Returns subscriptions for the event.
if($item instanceof\ElggEntity) elseif($item instanceof\ElggRiverItem) elseif($item instanceof\ElggRelationship) elseif(is_callable([$item, 'getType']))
sendNotifications(array $subscriptions, array $params=[])
Sends the notifications based on subscriptions.
elgg_extract($key, $array, $default=null, bool $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
trait Loggable
Enables adding a logger.
Notification Event Handler handles preparation of a notification.
deliverNotification(Notification $notification, string $method)
Deliver a notification.
filterMutedSubscriptions()
Should muted subscribers be filtered.
excludeContainerSubscribers()
Exclude the NotificationEvent object container_guid when fetching the subscription records for this n...
Instant notification event.
getEventActor()
Get the acting user from the notification event.
addMuteLink()
Add a mute link in the email notification.
getNotificationBody(\ElggUser $recipient, string $method)
Get body for the notification.
getNotificationSubsciptionExclusionGUIDs()
Get an array of GUIDs to not get the subscription records for.
getLogger()
Returns logger.
if($email instanceof\Elgg\Email) $object
getNotificationSummary(\ElggUser $recipient, string $method)
Return the summary for a notification.
Notification event interface.
excludeEntitySubscribers()
Exclude the NotificationEvent object guid when fetching the subscription records for this notificatio...
if(!$owner instanceof ElggEntity) $summary
_elgg_services()
Get the global service provider.
static isConfigurableForGroup(\ElggGroup $group)
Can this event be configured for a specific group.
if(!$new_container instanceof\ElggEntity) if(!$new_container->canWriteToContainer(0, $entity->type, $entity->subtype)) $display_name
if(empty($methods)) $subscriptions
_elgg_view_under_viewtype(string $view, array $vars, string $viewtype)
Render a view while the global viewtype is temporarily changed.
elgg_view_exists(string $view, string $viewtype= '', bool $recurse=true)
Returns whether the specified view exists.
__construct(NotificationEvent $event, NotificationsService $service, array $params=[])
Constructor.
$guid
Reset an ElggUpgrade.