6 use Elgg\Traits\Loggable;
41 unset(
$params[
'methods_override']);
68 return $this->methods_override;
86 final public function send(): array {
91 $params[
'event'] = $this->event;
92 $params[
'subscriptions'] = $this->prepareSubscriptions();
96 $deliveries = $this->sendNotifications(
$params[
'subscriptions'],
$params);
99 $params[
'deliveries'] = $deliveries;
114 'event' => $this->event,
115 'methods' => $this->getMethods(),
116 'methods_override' => $this->getMethodsOverride(),
130 return (bool) $this->getParam(
'apply_muting', true);
139 return _elgg_services()->subscriptions->getNotificationEventSubscriptions($this->event, $this->getMethods(), $this->getNotificationSubsciptionExclusionGUIDs());
148 $object = $this->event->getObject();
154 if ($this->excludeOwnerSubscribers()) {
155 $exclude[] =
$object->owner_guid;
158 if ($this->excludeContainerSubscribers()) {
159 $exclude[] =
$object->container_guid;
162 if ($this->excludeEntitySubscribers()) {
205 return $this->service->getMethods();
228 if (empty($this->getMethods())) {
233 $current_language = $translator->getCurrentLanguage();
243 $translator->setCurrentLanguage(
$recipient->getLanguage());
250 if ($this->service->isRegisteredMethod($method)) {
254 }
catch (\Throwable $t) {
255 $translator->setCurrentLanguage($current_language);
259 $translator->setCurrentLanguage($current_language);
262 $this->
getLogger()->info(
"Results for the notification event {$this->event->getDescription()}: " . print_r(
$result,
true));
276 if (!
_elgg_services()->events->hasHandler(
'send',
"notification:{$method}")) {
281 $actor = $this->
event->getActor();
282 $object = $this->
event->getObject();
311 $params[
'event'] = $this->event;
317 $params[
'action'] = $this->
event->getAction();
337 'event' => $this->event,
342 if ($this->getLogger()->isLoggable(LogLevel::INFO)) {
343 $logger_data = print_r((array)
$notification->toObject(),
true);
345 $this->getLogger()->info(
'Notification sent: ' . $logger_data);
347 $this->getLogger()->info(
'Notification was not sent: ' . $logger_data);
367 throw new RuntimeException(
"'prepare','notification' event must return an instance of " . Notification::class);
370 $type =
'notification:' . $this->
event->getDescription();
373 throw new RuntimeException(
"'prepare','{$type}' event must return an instance of " . Notification::class);
383 throw new RuntimeException(
"'format','notification:{$params['method']}' event must return an instance of " . Notification::class);
401 $actor = $this->event->getActor() ?: null;
402 $object = $this->
event->getObject();
405 $subject_key =
"notification:{$this->event->getDescription()}:subject";
406 if (
_elgg_services()->translator->languageKeyExists($subject_key)) {
408 $actor?->getDisplayName(),
414 return _elgg_services()->translator->translate(
'notification:subject', [
$actor?->getDisplayName()]);
440 $actor = $this->event->getActor() ?: null;
441 $object = $this->
event->getObject() ?:
null;
444 $body_key =
"notification:{$this->event->getDescription()}:body";
447 $container_name =
'';
450 $container_name =
$object->getContainerEntity()?->getDisplayName();
454 $actor?->getDisplayName(),
487 $object = $this->event->getObject() ?: null;
489 return (
string)
$object?->getURL();
511 $actor = $this->event->getActor();
523 $object = $this->event->getObject();
549 return static::isConfigurableForUser(
$entity);
551 return static::isConfigurableForGroup(
$entity);
getLogger()
Returns logger.
$guid
Reset an ElggUpgrade.
if(! $new_container instanceof \ElggEntity) if(! $new_container->canWriteToContainer(0, $entity->type, $entity->subtype)) $display_name
$params
Saves global plugin settings.
return[ 'admin/delete_admin_notices'=>['access'=> 'admin'], 'admin/menu/save'=>['access'=> 'admin'], 'admin/plugins/activate'=>['access'=> 'admin'], 'admin/plugins/activate_all'=>['access'=> 'admin'], 'admin/plugins/deactivate'=>['access'=> 'admin'], 'admin/plugins/deactivate_all'=>['access'=> 'admin'], 'admin/plugins/set_priority'=>['access'=> 'admin'], 'admin/security/security_txt'=>['access'=> 'admin'], 'admin/security/settings'=>['access'=> 'admin'], 'admin/security/regenerate_site_secret'=>['access'=> 'admin'], 'admin/site/cache/invalidate'=>['access'=> 'admin'], 'admin/site/flush_cache'=>['access'=> 'admin'], 'admin/site/icons'=>['access'=> 'admin'], 'admin/site/set_maintenance_mode'=>['access'=> 'admin'], 'admin/site/set_robots'=>['access'=> 'admin'], 'admin/site/theme'=>['access'=> 'admin'], 'admin/site/unlock_upgrade'=>['access'=> 'admin'], 'admin/site/settings'=>['access'=> 'admin'], 'admin/upgrade'=>['access'=> 'admin'], 'admin/upgrade/reset'=>['access'=> 'admin'], 'admin/user/ban'=>['access'=> 'admin'], 'admin/user/bulk/ban'=>['access'=> 'admin'], 'admin/user/bulk/delete'=>['access'=> 'admin'], 'admin/user/bulk/unban'=>['access'=> 'admin'], 'admin/user/bulk/validate'=>['access'=> 'admin'], 'admin/user/change_email'=>['access'=> 'admin'], 'admin/user/delete'=>['access'=> 'admin'], 'admin/user/login_as'=>['access'=> 'admin'], 'admin/user/logout_as'=>[], 'admin/user/makeadmin'=>['access'=> 'admin'], 'admin/user/resetpassword'=>['access'=> 'admin'], 'admin/user/removeadmin'=>['access'=> 'admin'], 'admin/user/unban'=>['access'=> 'admin'], 'admin/user/validate'=>['access'=> 'admin'], 'annotation/delete'=>[], 'avatar/upload'=>[], 'comment/save'=>[], 'diagnostics/download'=>['access'=> 'admin'], 'entity/chooserestoredestination'=>[], 'entity/delete'=>[], 'entity/mute'=>[], 'entity/restore'=>[], 'entity/subscribe'=>[], 'entity/trash'=>[], 'entity/unmute'=>[], 'entity/unsubscribe'=>[], 'login'=>['access'=> 'logged_out'], 'logout'=>[], 'notifications/mute'=>['access'=> 'public'], 'plugins/settings/remove'=>['access'=> 'admin'], 'plugins/settings/save'=>['access'=> 'admin'], 'plugins/usersettings/save'=>[], 'register'=>['access'=> 'logged_out', 'middleware'=>[\Elgg\Router\Middleware\RegistrationAllowedGatekeeper::class,],], 'river/delete'=>[], 'settings/notifications'=>[], 'settings/notifications/subscriptions'=>[], 'user/changepassword'=>['access'=> 'public'], 'user/requestnewpassword'=>['access'=> 'public'], 'useradd'=>['access'=> 'admin'], 'usersettings/save'=>[], 'widgets/add'=>[], 'widgets/delete'=>[], 'widgets/move'=>[], 'widgets/save'=>[],]
if(! $owner instanceof ElggEntity) $summary
$attachments
Outputs attachments.
foreach($categories as $key=> $category) $body
Exception thrown if an error which can only be found on runtime occurs.
Instant notification event.
Notification Event Handler handles preparation of a notification.
__construct(protected NotificationEvent $event, protected NotificationsService $service, array $params=[])
Constructor.
sendNotification(\ElggEntity $recipient, string $method, array $params=[])
Send a notification to a subscriber.
deliverNotification(Notification $notification, string $method)
Deliver a notification.
addMuteLink()
Add a mute link in the email notification.
getMethods()
Returns methods to be used for this notification.
getNotificationSummary(\ElggUser $recipient, string $method)
Return the summary for a notification.
setMethodsOverride(array $methods)
Override the default user preferred delivery methods with the given methods.
filterMutedSubscriptions()
Should muted subscribers be filtered.
getEventActor()
Get the acting user from the notification event.
static isConfigurableByUser()
Is this event configurable by the user on the notification settings page.
excludeOwnerSubscribers()
Exclude the NotificationEvent object owner_guid when fetching the subscription records for this notif...
getEventEntity()
Get the entity from the notification event.
static isConfigurableForUser(\ElggUser $user)
Can this event be configured for a specific user.
static isConfigurableForGroup(\ElggGroup $group)
Can this event be configured for a specific group.
prepareNotification(array $params)
Prepares a notification for delivery.
getNotificationAttachments(\ElggUser $recipient, string $method)
Get the attachments for this notification.
getNotificationMethods()
Get the notification methods to use.
prepareSubscriptions()
Returns subscriptions.
sendNotifications(array $subscriptions, array $params=[])
Sends the notifications based on subscriptions.
getNotificationSubject(\ElggUser $recipient, string $method)
Get subject for the notification.
getNotificationSubsciptionExclusionGUIDs()
Get an array of GUIDs to not get the subscription records for.
static isConfigurableForEntity(\ElggEntity $entity)
Can this event be configured for a specific entity.
getNotificationBody(\ElggUser $recipient, string $method)
Get body for the notification.
excludeEntitySubscribers()
Exclude the NotificationEvent object guid when fetching the subscription records for this notificatio...
getMethodsOverride()
Get the delivery methods override.
getParam(string $param, mixed $default=null)
Get a parameter from the notification parameters.
excludeContainerSubscribers()
Exclude the NotificationEvent object container_guid when fetching the subscription records for this n...
getSubscriptions()
Returns subscriptions for the event.
getNotificationURL(\ElggUser $recipient, string $method)
Returns the url related to this notification.
foreach($plugin_guids as $guid) if(empty($deactivated_plugins)) $url
if($email instanceof \Elgg\Email) $object
$subject
HTML body of an email.
if($item instanceof \ElggEntity) elseif($item instanceof \ElggRiverItem) elseif($item instanceof \ElggRelationship) elseif(is_callable([ $item, 'getType']))
_elgg_services()
Get the global service provider.
elgg_extract($key, $array, $default=null, bool $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
Notification event interface.
elgg_view_exists(string $view, string $viewtype='', bool $recurse=true)
Returns whether the specified view exists.
_elgg_view_under_viewtype(string $view, array $vars, string $viewtype)
Render a view while the global viewtype is temporarily changed.
if(!elgg_get_config('trash_enabled')) $group
if(parse_url(elgg_get_site_url(), PHP_URL_PATH) !=='/') if(file_exists(elgg_get_root_path() . 'robots.txt'))
Set robots.txt.
if(empty($methods)) $subscriptions