dev-master
9999999-devExtended notifications functionality on certain events for Elgg communites
GPL-2.0
The Requires
by Nikos Lyberakis
plugin notifications elgg
Extended notifications functionality on certain events for Elgg communites
, (*1)
Extended notifications functionality on certain events for Elgg communites., (*2)
This plugin can be used from developers for sending notifications to users automatically based on certain conditions, if these conditions are not being satisfied., (*3)
For example if a specific profile field is missing for current user, then this user should be notified., (*4)
elgg_register_plugin_hook_handler('special_notifications:config', 'notify', "snotify_profile_location"); function snotify_profile_location($hook, $type, $return, $params) { $key = 'profile_location'; if (!$params || (is_array($params) && $params['notifier'] == $key)) { $return[$key] = [ 'active' => true, 'hook' => 'profile_location_missing', 'methods' => [SpecialNotificationsOptions::SN_METHOD_INLINE], ]; } return $return; }
function special_notification_profile_location_missing($hook, $type, $return, $params) { if ($type !== 'user') { return; } $user = elgg_get_logged_in_user_entity(); if (!$user) { return; } $key = 'profile_location'; $settings = elgg_trigger_plugin_hook('special_notifications:config', 'notify', ['notifier' => $key], []); if (!$settings[$key]['active']) { return; } // check the condition for notify the user $notify = false; if (!$user->location) { $notify = true; } if ($notify) { $methods = $settings[$key]['methods']; foreach ($methods as $m) { switch ($m) { case "inline": $close_btn = elgg_format_element('a', ['class' => 'close', 'data-dismiss' => 'alert', 'aria-label' => 'close'], '×'); $inline = elgg_view('special_notifications/inline',[ 'content' => $close_btn.elgg_echo('special_notifications:profile_location:message'), 'class' => 'alert alert-warning fade in', ]); break; case "elgg_error": register_error(elgg_echo('special_notifications:profile_location:message')); break; } } if ($inline) { return $inline; } } return; }
if (elgg_is_active_plugin('special_notifications') && elgg_get_logged_in_user_guid()==$user->getGUID()) { if ($notifications = elgg_trigger_plugin_hook('special_notifications', "user", [], false)) { $content = elgg_format_element('div', ['class' => 'col-md-12 col-sm-12 col-xs-12'], $notifications); } } ... echo content; ...
As an example, a checking event is available on this plugin: Check if user has entered location on profile. If location is empty, then notify the user., (*5)
Extended notifications functionality on certain events for Elgg communites
GPL-2.0
plugin notifications elgg