aboutsummaryrefslogtreecommitdiff
path: root/engine/lib/notification.php
diff options
context:
space:
mode:
authorben <ben@36083f99-b078-4883-b0ff-0f9b5a30f544>2009-01-22 12:42:58 +0000
committerben <ben@36083f99-b078-4883-b0ff-0f9b5a30f544>2009-01-22 12:42:58 +0000
commit2f6790702c0a15e664c2d7e607c229025ecdbbaf (patch)
tree5ebe6d683eafc7b1d368b72d6f88cad33b4987fa /engine/lib/notification.php
parent82d5cde580dc98b22968c94258a59851426d91bb (diff)
downloadelgg-2f6790702c0a15e664c2d7e607c229025ecdbbaf.tar.gz
elgg-2f6790702c0a15e664c2d7e607c229025ecdbbaf.tar.bz2
Granular notification: a start
git-svn-id: https://code.elgg.org/elgg/trunk@2596 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine/lib/notification.php')
-rw-r--r--engine/lib/notification.php80
1 files changed, 79 insertions, 1 deletions
diff --git a/engine/lib/notification.php b/engine/lib/notification.php
index ade0bd59b..65d5f6a75 100644
--- a/engine/lib/notification.php
+++ b/engine/lib/notification.php
@@ -308,8 +308,86 @@
global $CONFIG;
@include($CONFIG->path . "actions/notifications/settings/usersettings/save.php");
+ }
+
+ /**
+ * Register an entity type and subtype to be eligible for notifications
+ *
+ * @param string $entity_type The type of entity
+ * @param string $object_subtype Its subtype
+ * @param string $english_name It's English notification string (eg "New blog post")
+ */
+ function register_notification_object($entity_type, $object_subtype, $english_name) {
+ global $CONFIG;
+ if (!isset($CONFIG->register_objects)) {
+ $CONFIG->register_objects = array();
+ }
+ if (!isset($CONFIG->register_objects[$entity_type])) {
+ $CONFIG->register_objects[$entity_type] = array();
+ }
+ $CONFIG->register_objects[$object_type][$object_subtype] = $english_name;
+ }
+
+ /**
+ * Establish a 'notify' relationship between the user and a content author
+ *
+ * @param int $user_guid The GUID of the user who wants to follow a user's content
+ * @param int $author_guid The GUID of the user whose content the user wants to follow
+ * @return true|false Depending on success
+ */
+ function register_notification_interest($user_guid, $author_guid) {
+ return add_entity_relationship($user_guid, 'notify', $author_guid);
+ }
+
+ /**
+ * Remove a 'notify' relationship between the user and a content author
+ *
+ * @param int $user_guid The GUID of the user who is following a user's content
+ * @param int $author_guid The GUID of the user whose content the user wants to unfollow
+ * @return true|false Depending on success
+ */
+ function remove_notification_interest($user_guid, $author_guid) {
+ return remove_entity_relationship($user_guid, 'notify', $author_guid);
+ }
+
+ /**
+ * Automatically triggered notification on 'create' events that looks at registered
+ * objects and attempts to send notifications to anybody who's interested
+ *
+ * @see register_notification_object
+ */
+ function object_notifications($event, $object_type, $object) {
+
+ // We only want to trigger notification events for ElggEntities
+ if ($object instanceof ElggEntity) {
+
+ // Get config data
+ global $CONFIG;
+
+ // Have we registered notifications for this type of entity?
+ if (isset($CONFIG->register_objects[$object->getType()][$object->getSubtype()])) {
+
+ $descr = $CONFIG->register_objects[$object->getType()][$object->getSubtype()];
+ $string = $descr . ": " . $object->getURL();
+
+ // Get users interested in content from this person and notify them
+ // (Person defined by container_guid so we can also subscribe to groups if we want)
+ if ($interested_users = get_entities_from_relationship('notify',$object->container_guid,true,'user','',0,'',99999)) {
+ if (is_array($interested_users))
+ foreach($interested_users as $user) {
+ if ($user instanceof ElggUser)
+ notify_user($user->guid,$object->container_guid,$descr,$string);
+ }
+ }
+
+ }
+
+ }
+
}
// Register a startup event
- register_elgg_event_handler('init','system','notification_init',0);
+ register_elgg_event_handler('init','system','notification_init',0);
+ register_elgg_event_handler('create','all','object_notifications');
+
?> \ No newline at end of file