From 200d821e40d08c8acd1aa042b253d4d773765bc6 Mon Sep 17 00:00:00 2001 From: ben Date: Mon, 9 Feb 2009 18:16:06 +0000 Subject: A single notification is now sent out on forum topic creation. This also contains an update to $entity->countAnnotations, which no longer requires you to specify the annotation type. git-svn-id: https://code.elgg.org/elgg/trunk@2699 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/lib/entities.php | 2 +- engine/lib/notification.php | 35 ++++++++++++++++++----------------- mod/groups/start.php | 25 ++++++++++++++++++++++++- 3 files changed, 43 insertions(+), 19 deletions(-) diff --git a/engine/lib/entities.php b/engine/lib/entities.php index 8eee20857..c6c0f6fb2 100644 --- a/engine/lib/entities.php +++ b/engine/lib/entities.php @@ -393,7 +393,7 @@ * * @param string $name The type of annotation. */ - function countAnnotations($name) + function countAnnotations($name = "") { return count_annotations($this->getGUID(), "","",$name); } diff --git a/engine/lib/notification.php b/engine/lib/notification.php index b19725ea6..01d29990b 100644 --- a/engine/lib/notification.php +++ b/engine/lib/notification.php @@ -372,11 +372,12 @@ // Get config data global $CONFIG, $SESSION; - if (trigger_plugin_hook('object:notifications',$object_type,array( + $hookresult = trigger_plugin_hook('object:notifications',$object_type,array( 'event' => $event, 'object_type' => $object_type, 'object' => $object, - ),true)) return true; + ),false); + if ($hookresult === true) return true; // Have we registered notifications for this type of entity? $object_type = $object->getType(); if (empty($object_type)) $object_type = '__BLANK__'; @@ -398,20 +399,20 @@ $object->access_id == ACCESS_LOGGED_IN) && $object->access_id != ACCESS_PRIVATE && $user->guid != $SESSION['user']->guid) { - $tmp = (array)get_user_notification_settings($guid); - $methods = array(); - - // TODO: get the specific method to contact each user with - for now just go with their prefs - foreach($tmp as $k => $v) - if ($v) { - - $methodstring = trigger_plugin_hook('notify:entity:message',$entity->getType(),array( - 'entity' => $object, - 'to_entity' => $user, - 'method' => $v - ),$string); - notify_user($user->guid,$object->container_guid,$descr,$methodstring,NULL,array($v)); - } + $tmp = (array)get_user_notification_settings($guid); + $methods = array(); + + // TODO: get the specific method to contact each user with - for now just go with their prefs + foreach($tmp as $k => $v) + if ($v) { + + $methodstring = trigger_plugin_hook('notify:entity:message',$entity->getType(),array( + 'entity' => $object, + 'to_entity' => $user, + 'method' => $v + ),$string); + notify_user($user->guid,$object->container_guid,$descr,$methodstring,NULL,array($v)); + } } } } @@ -425,6 +426,6 @@ // Register a startup event register_elgg_event_handler('init','system','notification_init',0); - register_elgg_event_handler('create','all','object_notifications'); + register_elgg_event_handler('create','object','object_notifications'); ?> \ No newline at end of file diff --git a/mod/groups/start.php b/mod/groups/start.php index fbace7971..ee4c3d319 100644 --- a/mod/groups/start.php +++ b/mod/groups/start.php @@ -70,6 +70,7 @@ if (is_callable('register_notification_object')) register_notification_object('object', 'groupforumtopic', elgg_echo('groupforumtopic:new')); register_elgg_event_handler('annotate','all','group_object_notifications'); + register_plugin_hook('object:notifications','object','group_object_notifications_intercept'); // Listen to notification events and supply a more useful message register_plugin_hook('notify:entity:message', 'object', 'groupforumtopic_notify_message'); @@ -87,12 +88,34 @@ if (is_callable('object_notifications')) if ($object instanceof ElggObject) { if ($object->getSubtype() == 'groupforumtopic') { - object_notifications($event, $object_type, $object); + if ($object->countAnnotations() > 0) + object_notifications($event, $object_type, $object); } } } + /** + * Intercepts the notification on group topic creation and prevents a notification from going out + * (because one will be sent on the annotation) + * + * @param unknown_type $hook + * @param unknown_type $entity_type + * @param unknown_type $returnvalue + * @param unknown_type $params + * @return unknown + */ + function group_object_notifications_intercept($hook, $entity_type, $returnvalue, $params) { + if (isset($params)) { + if ($params['event'] == 'create' && $params['object'] instanceof ElggObject) { + if ($params['object']->getSubtype() == 'groupforumtopic') { + return true; + } + } + } + return null; + } + /** * Returns a more meaningful message * -- cgit v1.2.3