aboutsummaryrefslogtreecommitdiff
path: root/engine/lib/relationships.php
diff options
context:
space:
mode:
authormarcus <marcus@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-06-25 14:17:27 +0000
committermarcus <marcus@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-06-25 14:17:27 +0000
commit27009477e3f523721eacc784598a616bf438d772 (patch)
treed857ec16fed2d8f4eaff3915e4b5fa7e3812731f /engine/lib/relationships.php
parent98b32177eb900e779fd2c7976b1e77fb9dd77d63 (diff)
downloadelgg-27009477e3f523721eacc784598a616bf438d772.tar.gz
elgg-27009477e3f523721eacc784598a616bf438d772.tar.bz2
Refs #78: Email notifications on friending, comments
http://trac.elgg.org/elgg/ticket/78 git-svn-id: https://code.elgg.org/elgg/trunk@1124 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine/lib/relationships.php')
-rw-r--r--engine/lib/relationships.php47
1 files changed, 45 insertions, 2 deletions
diff --git a/engine/lib/relationships.php b/engine/lib/relationships.php
index b71f075e5..642b2f5c6 100644
--- a/engine/lib/relationships.php
+++ b/engine/lib/relationships.php
@@ -302,7 +302,9 @@
$id = (int)$id;
- return row_to_elggrelationship(get_data_row("delete from {$CONFIG->dbprefix}entity_relationships where id=$id"));
+ $result = delete_data("delete from {$CONFIG->dbprefix}entity_relationships where id=$id");
+
+ return $result;
}
/**
@@ -323,7 +325,18 @@
$relationship = sanitise_string($relationship);
$guid_two = (int)$guid_two;
- return insert_data("INSERT into {$CONFIG->dbprefix}entity_relationships (guid_one, relationship, guid_two) values ($guid_one, '$relationship', $guid_two)");
+ $result = insert_data("INSERT into {$CONFIG->dbprefix}entity_relationships (guid_one, relationship, guid_two) values ($guid_one, '$relationship', $guid_two)");
+
+ if ($result!==false) {
+ $obj = get_relationship($result);
+ if (trigger_elgg_event('create', $relationship, $obj)) {
+ return true;
+ } else {
+ delete_relationship($result);
+ }
+ }
+
+ return false;
}
/**
@@ -620,10 +633,40 @@
return $returnvalue;
}
+
+ /**
+ * An event listener which will notify users based on certain events.
+ *
+ * @param unknown_type $event
+ * @param unknown_type $object_type
+ * @param unknown_type $object
+ */
+ function relationship_notification_hook($event, $object_type, $object)
+ {
+ global $CONFIG;
+
+ if (
+ ($object instanceof ElggRelationship) &&
+ ($event == 'create') &&
+ ($object_type == 'friend')
+ )
+ {
+ $user_one = get_entity($object->guid_one);
+ $user_two = get_entity($object->guid_two);
+
+ // Notify target user
+ return notify_user($object->guid_two, $object->guid_one, sprintf(elgg_echo('friend:newfriend:subject'), $user_two->name),
+ sprintf(elgg_echo("friend:newfriend:body"), $user_one->name, $CONFIG->site->url . "pg/profile/" . $user_one->username)
+ );
+ }
+ }
/** Register the import hook */
register_plugin_hook("import", "all", "import_relationship_plugin_hook", 3);
/** Register the hook, ensuring entities are serialised first */
register_plugin_hook("export", "all", "export_relationship_plugin_hook", 3);
+
+ /** Register event to listen to some events **/
+ register_elgg_event_handler('create','friend','relationship_notification_hook');
?> \ No newline at end of file