3 namespace Elgg\Notifications;
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(),
131 return (bool) $this->getParam(
'apply_muting', true);
140 return _elgg_services()->subscriptions->getNotificationEventSubscriptions($this->event, $this->getMethods(), $this->getNotificationSubscriptionExclusionGUIDs());
149 $object = $this->event->getObject();
155 if ($this->excludeOwnerSubscribers()) {
156 $exclude[] =
$object->owner_guid;
159 if ($this->excludeContainerSubscribers()) {
160 $exclude[] =
$object->container_guid;
163 if ($this->excludeEntitySubscribers()) {
206 return $this->service->getMethods();
229 if (empty($this->getMethods())) {
234 $current_language = $translator->getCurrentLanguage();
244 $translator->setCurrentLanguage(
$recipient->getLanguage());
251 if ($this->service->isRegisteredMethod($method)) {
255 }
catch (\Throwable $t) {
256 $translator->setCurrentLanguage($current_language);
260 $translator->setCurrentLanguage($current_language);
263 $this->
getLogger()->info(
"Results for the notification event {$this->event->getDescription()}: " . print_r(
$result,
true));
277 if (!
_elgg_services()->events->hasHandler(
'send',
"notification:{$method}")) {
282 $actor = $this->
event->getActor();
283 $object = $this->
event->getObject();
312 $params[
'event'] = $this->event;
318 $params[
'action'] = $this->
event->getAction();
338 'event' => $this->event,
343 if ($this->getLogger()->isLoggable(LogLevel::INFO)) {
344 $logger_data = print_r((array)
$notification->toObject(),
true);
346 $this->getLogger()->info(
'Notification sent: ' . $logger_data);
348 $this->getLogger()->info(
'Notification was not sent: ' . $logger_data);
368 throw new RuntimeException(
"'prepare','notification' event must return an instance of " . Notification::class);
371 $type =
'notification:' . $this->
event->getDescription();
374 throw new RuntimeException(
"'prepare','{$type}' event must return an instance of " . Notification::class);
384 throw new RuntimeException(
"'format','notification:{$params['method']}' event must return an instance of " . Notification::class);
402 $actor = $this->event->getActor() ?: null;
403 $object = $this->
event->getObject();
406 $subject_key =
"notification:{$this->event->getDescription()}:subject";
407 if (
_elgg_services()->translator->languageKeyExists($subject_key)) {
409 $actor?->getDisplayName(),
415 return _elgg_services()->translator->translate(
'notification:subject', [
$actor?->getDisplayName()]);
441 $actor = $this->event->getActor() ?: null;
442 $object = $this->
event->getObject() ?:
null;
445 $body_key =
"notification:{$this->event->getDescription()}:body";
448 $container_name =
'';
451 $container_name =
$object->getContainerEntity()?->getDisplayName();
455 $actor?->getDisplayName(),
488 $object = $this->event->getObject() ?: null;
490 return (
string)
$object?->getURL();
512 $actor = $this->event->getActor();
524 $object = $this->event->getObject();
550 return static::isConfigurableForUser(
$entity);
552 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/clear'=>['access'=> 'admin'], 'admin/site/cache/invalidate'=>['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', 'controller'=> \Elgg\Diagnostics\DownloadController::class,], '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.
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...
getNotificationSubscriptionExclusionGUIDs()
Get an array of GUIDs to not get the subscription records for.
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