Elgg  Version master
notification.php
Go to the documentation of this file.
1 <?php
52 
73 function elgg_register_notification_event(string $object_type, string $object_subtype, array $actions = [], string $handler = NotificationEventHandler::class): void {
74  _elgg_services()->notifications->registerEvent($object_type, $object_subtype, $actions, $handler);
75 }
76 
88 function elgg_unregister_notification_event(string $object_type, string $object_subtype, array $actions = []): void {
89  _elgg_services()->notifications->unregisterEvent($object_type, $object_subtype, $actions);
90 }
91 
105 function elgg_register_notification_method(string $name): void {
106  _elgg_services()->notifications->registerMethod($name);
107 }
108 
121 function elgg_get_notification_methods(): array {
122  return _elgg_services()->notifications->getMethods();
123 }
124 
135  _elgg_services()->notifications->unregisterMethod($name);
136 }
137 
153 function elgg_get_notification_events(): array {
154  return _elgg_services()->notifications->getEvents();
155 }
156 
172  $methods = _elgg_services()->notifications->getMethods();
173 
174  return _elgg_services()->subscriptions->getSubscriptionsForContainer($container_guid, $methods);
175 }
176 
201 function notify_user(int|array $to, int $from = 0, string $subject = '', string $message = '', array $params = [], $methods_override = null): array {
202 
203  $params['subject'] = $subject;
204  $params['body'] = $message;
205  $params['methods_override'] = $methods_override;
206 
207  if (!empty($from)) {
208  $sender = get_entity($from);
209  } else {
210  $sender = elgg_get_site_entity();
211  }
212 
213  if (!$sender instanceof \ElggEntity) {
214  return [];
215  }
216 
217  $recipients = [];
218  $to = (array) $to;
219  foreach ($to as $guid) {
221  if (!$recipient instanceof \ElggEntity) {
222  continue;
223  }
224 
225  $recipients[] = $recipient;
226  }
227 
228  return _elgg_services()->notifications->sendInstantNotifications($sender, $recipients, $params);
229 }
230 
239 function elgg_send_email(\Elgg\Email $email): bool {
240  return _elgg_services()->emails->send($email);
241 }
242 
257  _elgg_services()->notifications->enqueueEvent($action, $object, $actor);
258 }
$guid
Reset an ElggUpgrade.
Definition: reset.php:6
$email
Definition: change_email.php:7
if(! $user||! $user->canDelete()) $name
Definition: delete.php:22
$recipient
Definition: mute.php:8
$params
Saves global plugin settings.
Definition: save.php:13
$subject
Definition: useradd.php:54
$handler
Definition: add.php:7
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'=>[],]
Definition: actions.php:73
A generic class that contains shared code among \ElggExtender, \ElggEntity, and \ElggRelationship.
Definition: ElggData.php:12
Notification Event Handler handles preparation of a notification.
$container_guid
if($email instanceof \Elgg\Email) $object
Definition: body.php:24
_elgg_services()
Get the global service provider.
Definition: elgglib.php:353
get_entity(int $guid)
Loads and returns an entity object from a guid.
Definition: entities.php:70
elgg_get_site_entity()
Get the current site entity.
Definition: entities.php:101
notify_user(int|array $to, int $from=0, string $subject='', string $message='', array $params=[], $methods_override=null)
Notify a user via their preferences.
elgg_unregister_notification_event(string $object_type, string $object_subtype, array $actions=[])
Unregister a notification event.
elgg_enqueue_notification_event(string $action, \ElggData $object, ?\ElggEntity $actor=null)
Enqueue a notification event for delivery.
elgg_register_notification_event(string $object_type, string $object_subtype, array $actions=[], string $handler=NotificationEventHandler::class)
Register a notification event.
elgg_get_subscriptions_for_container(int $container_guid)
Get the subscriptions for the content created inside this container.
elgg_send_email(\Elgg\Email $email)
Send an email to any email address.
elgg_register_notification_method(string $name)
Register a delivery method for notifications.
elgg_unregister_notification_method(string $name)
Unregister a delivery method for notifications.
elgg_get_notification_events()
Get the registered notification events in the format.
elgg_get_notification_methods()
Returns registered delivery methods for notifications [ 'email' => 'email', 'sms' => 'sms',...
$methods
Definition: subscribe.php:8
$action
Definition: subscribe.php:11
if(! $menu instanceof \Elgg\Menu\PreparedMenu) $actions
Definition: user_hover.php:21
if(($owner instanceof \ElggGroup|| $owner instanceof \ElggUser) &&!in_array($owner->guid, $mute_guids)) $actor
Definition: mute.php:78