From bddb9abb6b16c0fe89deb87a614c5a4435ec2e3d Mon Sep 17 00:00:00 2001 From: marcus Date: Wed, 5 Nov 2008 16:21:49 +0000 Subject: Slight rejig in the way the river works git-svn-id: https://code.elgg.org/elgg/trunk@2406 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/lib/river.php | 78 +++++++++++++++++++++++++++++++++++----------------- 1 file changed, 53 insertions(+), 25 deletions(-) (limited to 'engine') diff --git a/engine/lib/river.php b/engine/lib/river.php index 22f1b6c26..e6a6e12dc 100644 --- a/engine/lib/river.php +++ b/engine/lib/river.php @@ -229,6 +229,56 @@ return get_data($query); } + /** + * Construct a river statement out of an entry in the system log. + * + * @param stdClass $log_entry + * @return mixed Either an ElggRiverStatement or false + */ + function construct_riverstatement_from_log($log_entry) + { + if (!($log_entry instanceof stdClass)) return false; + + $log = $log_entry; + + // See if we have access to the object we're talking about + $event = $log->event; + $class = $log->object_class; + $type = $log->object_type; + $subtype = $log->object_subtype; + $tmp = new $class(); + $object = $tmp->getObjectFromID($log->object_id); + $by_user_obj = get_entity($log->performed_by_guid); + + if ( ($object) && ($object instanceof $class)) + { + // Construct the statement + $statement_object = $object; // Simple object, we don't need to do more + + // This is a relationship, slighty more complicated + if ($object instanceof ElggRelationship) { + + $statement_object = array( + 'subject' => get_entity($object->guid_one), + 'relationship' => $object->relationship,// Didn' cast to int here deliberately + 'object' => get_entity($object->guid_two) + ); + + // Metadata or annotations, also slightly more complicated + } else if ($object instanceof ElggExtender) { + $statement_object = array( + 'subject' => $object, + 'object' => get_entity($object->entity_guid) + ); + } + + // Put together a river statement + return new ElggRiverStatement($by_user_obj, $event, $statement_object); + } + + return false; + } + /** * Extract a list of river events from the current system log. * This function retrieves the objects from the system log and will attempt to render @@ -275,7 +325,8 @@ { foreach ($log_data as $log) { - // See if we have access to the object we're talking about + $statement = construct_riverstatement_from_log($log); + $event = $log->event; $class = $log->object_class; $type = $log->object_type; @@ -285,33 +336,10 @@ $by_user_obj = get_entity($log->performed_by_guid); // Belts and braces - if ($object instanceof $class) + if ($statement) { $tam = ""; - // Construct the statement - $statement_object = $object; // Simple object, we don't need to do more - - // This is a relationship, slighty more complicated - if ($object instanceof ElggRelationship) { - - $statement_object = array( - 'subject' => get_entity($object->guid_one), - 'relationship' => $object->relationship,// Didn' cast to int here deliberately - 'object' => get_entity($object->guid_two) - ); - - // Metadata or annotations, also slightly more complicated - } else if ($object instanceof ElggExtender) { - $statement_object = array( - 'subject' => $object, - 'object' => get_entity($object->entity_guid) - ); - } - - // Put together a river statement - $statement = new ElggRiverStatement($by_user_obj, $event, $statement_object); - // Now construct and call the appropriate views if ($subtype == "widget") { // Special case for widgets -- cgit v1.2.3