diff options
author | cash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2010-08-22 21:53:48 +0000 |
---|---|---|
committer | cash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2010-08-22 21:53:48 +0000 |
commit | be37104ac63cd25f2eac831ca03d6d2b19976e1c (patch) | |
tree | 5b168134f2b07933831daedd8cf2641ffb6c5c7d /mod/notifications | |
parent | d45a24be28b2eb2d0c2731708b589788a5b87215 (diff) | |
download | elgg-be37104ac63cd25f2eac831ca03d6d2b19976e1c.tar.gz elgg-be37104ac63cd25f2eac831ca03d6d2b19976e1c.tar.bz2 |
Merged r6684:6694 from 1.7 branch to trunk (pages plugin was manually merged due to standardization of code in trunk but not branch)
git-svn-id: http://code.elgg.org/elgg/trunk@6848 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'mod/notifications')
-rw-r--r-- | mod/notifications/start.php | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/mod/notifications/start.php b/mod/notifications/start.php index fa36d5d69..3349d0194 100644 --- a/mod/notifications/start.php +++ b/mod/notifications/start.php @@ -27,6 +27,10 @@ function notifications_plugin_init() { // update notifications based on relationships changing register_elgg_event_handler('delete', 'member', 'notifications_relationship_remove'); register_elgg_event_handler('delete', 'friend', 'notifications_relationship_remove'); + + // update notifications when new friend or access collection membership + register_elgg_event_handler('create', 'friend', 'notifications_update_friend_notify'); + register_plugin_hook('access:collections:add_user', 'collection', 'notifications_update_collection_notify'); } /** @@ -88,7 +92,89 @@ function notifications_relationship_remove($event, $object_type, $relationship) } } +/** + * Turn on notifications for new friends if all friend notifications is on + * + * @param string $event + * @param string $object_type + * @param object $relationship + */ +function notifications_update_friend_notify($event, $object_type, $relationship) { + global $NOTIFICATION_HANDLERS; + + $user_guid = $relationship->guid_one; + $friend_guid = $relationship->guid_two; + + $user = get_entity($user_guid); + + // loop through all notification types + foreach ($NOTIFICATION_HANDLERS as $method => $foo) { + $metaname = 'collections_notifications_preferences_' . $method; + $collections_preferences = $user->$metaname; + if ($collections_preferences) { + if (!empty($collections_preferences) && !is_array($collections_preferences)) { + $collections_preferences = array($collections_preferences); + } + if (is_array($collections_preferences)) { + // -1 means all friends is on - should be a define + if (in_array(-1, $collections_preferences)) { + add_entity_relationship($user_guid, 'notify' . $method, $friend_guid); + } + } + } + } +} + +/** + * Update notifications for changes in access collection membership. + * + * This function assumes that only friends can belong to access collections. + * + * @param string $event + * @param string $object_type + * @param bool $returnvalue + * @param array $params + */ +function notifications_update_collection_notify($event, $object_type, $returnvalue, $params) { + global $NOTIFICATION_HANDLERS; + + // only update notifications for user owned collections + $collection_id = $params['collection_id']; + $collection = get_access_collection($collection_id); + $user = get_entity($collection->owner_guid); + if (!($user instanceof ElggUser)) { + return $returnvalue; + } + $member_guid = $params['user_guid']; + + // loop through all notification types + foreach ($NOTIFICATION_HANDLERS as $method => $foo) { + $metaname = 'collections_notifications_preferences_' . $method; + $collections_preferences = $user->$metaname; + if (!$collections_preferences) { + continue; + } + if (!is_array($collections_preferences)) { + $collections_preferences = array($collections_preferences); + } + if (in_array(-1, $collections_preferences)) { + // if "all friends" notify is on, we don't change any notifications + // since must be a friend to be in an access collection + continue; + } + if (in_array($collection_id, $collections_preferences)) { + // notifications are on for this collection so we add/remove + if ($event == 'access:collections:add_user') { + add_entity_relationship($user->guid, "notify$method", $member_guid); + } elseif ($event == 'access:collections:remove_user') { + // removing someone from an access collection is not a guarantee + // that they should be removed from notifications + //remove_entity_relationship($user->guid, "notify$method", $member_guid); + } + } + } +} register_elgg_event_handler('init', 'system', 'notifications_plugin_init', 1000); |