aboutsummaryrefslogtreecommitdiff
path: root/engine
diff options
context:
space:
mode:
authormarcus <marcus@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-07-09 18:04:00 +0000
committermarcus <marcus@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-07-09 18:04:00 +0000
commitfe04f54b34210e6771fa06d8e4ca2849749c8477 (patch)
treefeaea79f1057a3313366fd7ec86ed1e3ce1db750 /engine
parentd7718ebc40f9e28c6126e65df54e99d5b9948447 (diff)
downloadelgg-fe04f54b34210e6771fa06d8e4ca2849749c8477.tar.gz
elgg-fe04f54b34210e6771fa06d8e4ca2849749c8477.tar.bz2
Closes #81: OpenDD aggregator
http://trac.elgg.org/elgg/ticket/81 git-svn-id: https://code.elgg.org/elgg/trunk@1377 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine')
-rw-r--r--engine/lib/river.php111
1 files changed, 111 insertions, 0 deletions
diff --git a/engine/lib/river.php b/engine/lib/river.php
index e1a374a31..d9578a195 100644
--- a/engine/lib/river.php
+++ b/engine/lib/river.php
@@ -137,6 +137,117 @@
);
return $river;
+ }
+
+ /**
+ * Extract entities from the system log and produce them as an OpenDD stream.
+ * This stream can be subscribed to and reconstructed on another system as an activity stream.
+ *
+ * @param int $by_user The user who initiated the event.
+ * @param string $relationship Limit return results to only those users who $by_user has $relationship with.
+ * @param int $limit Maximum number of events to show
+ * @param int $offset An offset
+ * @return ODDDocument
+ */
+ function get_river_entries_as_opendd($by_user = "", $relationship = "", $limit = 10, $offset = 0)
+ {
+ // set start limit and offset
+ $cnt = $limit; // Didn' cast to int here deliberately
+ $off = $offset; // here too
+
+ if (is_array($by_user) && sizeof($by_user) > 0) {
+ foreach($by_user as $key => $val) {
+ $by_user[$key] = (int) $val;
+ }
+ } else {
+ $by_user = (int)$by_user;
+ }
+
+ $exit = false;
+
+ // River objects
+ $river = new ODDDocument();
+
+ do
+ {
+ $log_events = get_system_log($by_user, "","", $cnt, $off);
+
+ if (!$log_events)
+ $exit = true;
+ else
+ {
+
+ foreach ($log_events as $log)
+ {
+ // See if we have access to the object we're talking about
+ $event = $log->event;
+ $class = $log->object_class;
+ $tmp = new $class();
+ $object = $tmp->getObjectFromID($log->object_id);
+
+ // Exists and we have access to it
+ // if (is_a($object, $class))
+ if ($object instanceof $class)
+ {
+ // If no relationship defined or it matches $relationship
+ if (
+ (!$relationship) ||
+ (
+ ($relationship) &&
+ (check_entity_relationship($by_user, $relationship, $tmp->getObjectOwnerGUID()))
+ )
+ )
+ {
+ $relationship_obj = NULL;
+
+ // Handle updates of entities
+ if ($object instanceof ElggEntity)
+ {
+ $relationship_obj = new ODDRelationship(
+ guid_to_uuid($log->performed_by_guid),
+ $log->event,
+ guid_to_uuid($log->object_id)
+ );
+ }
+
+ // Handle updates of metadata
+ if ($object instanceof ElggExtender)
+ {
+ $odd = $object->export();
+ $relationship_obj = new ODDRelationship(
+ guid_to_uuid($log->performed_by_guid),
+ $log->event,
+ $odd->getAttribute('uuid')
+ );
+ }
+
+ // Handle updates of relationships
+ if ($object instanceof ElggRelationship)
+ {
+ $relationship_obj = $object->export(); // I figure this is what you're actually interested in in this instance.
+ }
+
+ // If we have handled it then add it to the document
+ if ($relationship_obj) {
+ $relationship_obj->setPublished($log->time_created);
+ $river->addElement($relationship_obj);
+ }
+
+ }
+ }
+
+ // Increase offset
+ $off++;
+ }
+ }
+
+ } while (
+ ($cnt > 0) &&
+ (!$exit)
+ );
+
+ return $river;
+
}
/**