97 if (!isset($this->events[
$type])) {
98 $this->events[
$type] = array();
100 if (!isset($this->events[$type][
$subtype])) {
106 $action_list = array_unique(array_merge($action_list,
$actions));
107 } elseif (!in_array(
'create', $action_list)) {
108 $action_list[] =
'create';
118 if (!isset($this->events[
$type]) || !isset($this->events[$type][
$subtype])) {
122 unset($this->events[$type][$subtype]);
147 if (isset($this->methods[
$name])) {
148 unset($this->methods[$name]);
173 $object_type =
$object->getType();
174 $object_subtype =
$object->getSubtype();
177 if (!empty($this->events[$object_type][$object_subtype]) && in_array(
$action, $this->events[$object_type][$object_subtype])) {
186 $registered = $this->hooks->trigger(
'enqueue',
'notification',
$params, $registered);
207 $delivery_matrix = [];
213 $ia = $this->session->setIgnoreAccess(
true);
215 while (
time() < $stopTime) {
217 $event = $this->queue->dequeue();
244 if ($this->hooks->trigger(
'send:before',
'notifications',
$params,
true)) {
247 $params[
'deliveries'] = $deliveries;
248 $this->hooks->trigger(
'send:after',
'notifications',
$params);
251 $delivery_matrix[$event->getDescription()] = $deliveries;
256 $this->session->setIgnoreAccess($ia);
258 return $matrix ? $delivery_matrix :
$count;
283 if (!$this->methods) {
291 if (in_array($method, $this->methods)) {
297 $this->logger->notice(
"Results for the notification event {$event->getDescription()}: " . print_r(
$result,
true));
346 if (!$this->methods) {
350 $recipients = array_filter($recipients,
function(
$e) {
358 unset(
$params[
'methods_override']);
359 if ($methods_override && !is_array($methods_override)) {
360 $methods_override = [$methods_override];
370 foreach ($recipients as $recipient) {
376 $user_settings = $recipient->getNotificationSettings();
390 'methods_override' => $methods_override,
397 if ($this->hooks->trigger(
'send:before',
'notifications',
$params,
true)) {
400 $params[
'deliveries'] = $deliveries;
401 $this->hooks->trigger(
'send:after',
'notifications',
$params);
422 $recipient = $this->entities->get(
$guid);
428 $recipient = $this->entities->get(
$guid,
'user');
430 if (!$recipient || $recipient->isBanned()) {
450 $subject = $this->getNotificationSubject($event, $recipient);
451 $body = $this->getNotificationBody($event, $recipient);
461 $params[
'recipient'] = $recipient;
468 $notification = $this->hooks->trigger(
'prepare',
'notification',
$params, $notification);
474 if ($this->hooks->hasHandler(
'prepare',
$type)) {
475 $notification = $this->hooks->trigger(
'prepare',
$type,
$params, $notification);
476 if (!$notification instanceof Notification) {
484 $notification = $this->hooks->trigger(
'format',
"notification:$method", [], $notification);
485 if (!$notification instanceof Notification) {
489 if ($this->hooks->hasHandler(
'send',
"notification:$method")) {
492 'notification' => $notification,
496 $result = $this->hooks->trigger(
'send',
"notification:$method",
$params,
false);
498 $logger_data = print_r((array) $notification->toObject(),
true);
500 $this->logger->info(
"Notification sent: " . $logger_data);
502 $this->logger->info(
"Notification was not sent: " . $logger_data);
508 $userGuid = $notification->getRecipientGUID();
509 $senderGuid = $notification->getSenderGUID();
511 $body = $notification->body;
512 $params = $notification->params;
538 $subject_key =
"notification:{$event->getDescription()}:subject";
539 if ($this->translator->languageKeyExists($subject_key,
$language)) {
545 return $this->translator->translate($subject_key, array(
552 return $this->translator->translate(
'notification:subject', array($actor->name),
$language);
598 $body_key =
"notification:{$event->getDescription()}:body";
599 if ($this->translator->languageKeyExists($body_key,
$language)) {
602 $container_name =
'';
605 $container_name =
$container->getDisplayName();
609 $container_name =
'';
612 return $this->translator->translate($body_key, array(
623 return $this->translator->translate(
'notification:body', array(
$object->getURL()),
$language);
644 if (isset($this->deprHandlers[
$method])) {
645 return $this->deprHandlers[
$method];
659 foreach ($this->methods as
$method) {
676 return $notification;
689 $notification->body =
$body;
692 return $notification;
711 if (!isset($this->deprSubjects[
$type])) {
712 $this->deprSubjects[
$type] = array();
733 if (!isset($this->deprSubjects[
$type])) {
737 if (!isset($this->deprSubjects[$type][
$subtype])) {
757 'object_type' =>
$entity->getType(),
760 $hookresult = $this->hooks->trigger(
'object:notifications',
$entity->getType(),
$params,
false);
761 if ($hookresult ===
true) {
763 .
"by the hook 'send:before', 'notifications'", 1.9);
sendNotifications($event, $subscriptions, array $params=[])
Sends the notifications based on subscriptions.
getObject()
Get the object of the event.
getRecipient()
Get the recipient entity.
$object
These two snippets demonstrates triggering an event and how to register for that event.
if($guid==elgg_get_logged_in_user_guid()) $name
getDescription()
Get a description of the event.
const ORIGIN_SUBSCRIPTIONS
getActorGUID()
Get the GUID of the actor.
getAction()
Get the name of the action.
$guid
Removes an admin notice.
existsDeprecatedNotificationOverride(NotificationEvent $event)
Is someone using the deprecated override.
getMethodsAsDeprecatedGlobal()
Provides a way to incrementally wean Elgg's notifications code from the global $NOTIFICATION_HANDLERS...
getDeprecatedHandler($method)
Get a deprecated notification handler callback.
setDeprecatedNotificationSubject($type, $subtype, $subject)
Set message subject for deprecated notification code.
getActor()
Get the actor of the event.
__construct(SubscriptionsService $subscriptions, Queue $queue, PluginHooksService $hooks, ElggSession $session, Translator $translator, EntityTable $entities, Logger $logger)
Constructor.
elgg_instanceof($entity, $type=null, $subtype=null, $class=null)
Checks if $entity is an and optionally for type and subtype.
sendNotification(NotificationEvent $event, $guid, $method, array $params=[])
Send a notification to a subscriber.
Instant notification event.
elgg_deprecated_notice($msg, $dep_version, $backtrace_level=1)
Log a notice about deprecated use of a function, view, etc.
getDeprecatedNotificationBody(Notification $notification, NotificationEvent $event, $method)
Get the notification body using a pre-Elgg 1.9 plugin hook.
enqueueEvent($action, $type, $object)
Add a notification event to the queue.
sendInstantNotifications(\ElggEntity $sender, array $recipients=[], array $params=[])
Notify a user via their preferences.
elgg_extract($key, $array, $default=null, $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
getDeprecatedNotificationSubject($type, $subtype)
Get the deprecated subject.
has_access_to_entity($entity, $user=null)
Can a user access an entity.
unregisterEvent($type, $subtype)
processQueue($stopTime, $matrix=false)
Pull notification events from queue until stop time is reached.
registerEvent($type, $subtype, array $actions=array())
registerDeprecatedHandler($method, $handler)
Register a deprecated notification handler.
$enabled
CI CLI installer script.
http free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
_elgg_notify_user($to, $from, $subject, $message, array $params=null, $methods_override="")
Notify a user via their preferences.