aboutsummaryrefslogtreecommitdiff
path: root/engine/lib/river.php
diff options
context:
space:
mode:
authormarcus <marcus@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-10-13 16:29:21 +0000
committermarcus <marcus@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-10-13 16:29:21 +0000
commit7256cae388a9d568a4c9f38ba0cec6159a430974 (patch)
tree91da9ff2f9ba94a957b0883efee568d3b244da59 /engine/lib/river.php
parent4a69d27cfa15dd7d5e073970dd407b56c607d8b9 (diff)
downloadelgg-7256cae388a9d568a4c9f38ba0cec6159a430974.tar.gz
elgg-7256cae388a9d568a4c9f38ba0cec6159a430974.tar.bz2
Closes #412
git-svn-id: https://code.elgg.org/elgg/trunk@2250 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine/lib/river.php')
-rw-r--r--engine/lib/river.php275
1 files changed, 134 insertions, 141 deletions
diff --git a/engine/lib/river.php b/engine/lib/river.php
index a446886d8..36e9b9eb1 100644
--- a/engine/lib/river.php
+++ b/engine/lib/river.php
@@ -145,41 +145,20 @@
}
/**
- * 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
- * the view "river/CLASSNAME/EVENT" where CLASSNAME is the class of the object the system event is referring to,
- * and EVENT is the event (create, update, delete etc).
- *
- * This view will be passed the log entry (as 'log_entry') and the object (as 'object') which will be accessable
- * through the $vars[] array.
- *
- * It returns an array of the result of each of these views.
- *
- * \TODO: Limit to just one user or just one user's friends
- * \TODO: Make this more efficient / reduce DB queries.
+ * Perform a somewhat complicated query to extract river data from the system log based on available views.
*
- * @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 array of river entities rendered with the appropriate view.
+ * NOTE: Do not use this function directly. It is called elsewhere and is subject to change without warning.
+ *
+ * @param unknown_type $by_user
+ * @param unknown_type $relationship
+ * @param unknown_type $limit
+ * @param unknown_type $offset
+ * @return unknown
*/
- function get_river_entries($by_user = "", $relationship = "", $limit = 10, $offset = 0)
+ function __get_river_from_log($by_user = "", $relationship = "", $limit = 10, $offset = 0)
{
global $CONFIG;
- $limit = (int)$limit;
- $offset = (int)$offset;
- $relationship = sanitise_string($relationship);
-
- if (is_array($by_user) && sizeof($by_user) > 0) {
- foreach($by_user as $key => $val) {
- $by_user[$key] = (int) $val;
- }
- } else {
- $by_user = array((int)$by_user);
- }
-
// Get all potential river events from available view
$river_events = array();
foreach (elgg_view_tree('river') as $view)
@@ -209,42 +188,80 @@
}
// Construct query
- // Objects
- $n = 0;
- foreach ($river_events as $details)
- {
- // Get what we're talking about
-
- if ($details['subtype'] == 'default') $details['subtype'] = '';
-
- if (($details['type']) && ($details['event'])) {
- if ($n>0) $obj_query .= " or ";
-
- $obj_query .= "( sl.object_type='{$details['type']}' and sl.object_subtype='{$details['subtype']}' and sl.event='{$details['event']}' )";
-
- $n++;
- }
-
- }
+ // Objects
+ $n = 0;
+ foreach ($river_events as $details)
+ {
+ // Get what we're talking about
- // User
- $user = "sl.performed_by_guid in (".implode(',', $by_user).")";
+ if ($details['subtype'] == 'default') $details['subtype'] = '';
- // Relationship
- $relationship_query = "";
- $relationship_join = "";
- if ($relationship)
- {
- $relationship_join = " join {$CONFIG->dbprefix}entity_relationships r on sl.performed_by_guid=r.entity_guid ";
- $relationship_query = "r.relationship = '$relationship'";
+ if (($details['type']) && ($details['event'])) {
+ if ($n>0) $obj_query .= " or ";
+
+ $obj_query .= "( sl.object_type='{$details['type']}' and sl.object_subtype='{$details['subtype']}' and sl.event='{$details['event']}' )";
+
+ $n++;
}
-
- $query = "SELECT sl.* from {$CONFIG->dbprefix}system_log sl $relationship_join where $user and $relationship_query ($obj_query) order by sl.time_created desc limit $offset, $limit";
+
+ }
+ // User
+ $user = "sl.performed_by_guid in (".implode(',', $by_user).")";
+
+ // Relationship
+ $relationship_query = "";
+ $relationship_join = "";
+ if ($relationship)
+ {
+ $relationship_join = " join {$CONFIG->dbprefix}entity_relationships r on sl.performed_by_guid=r.entity_guid ";
+ $relationship_query = "r.relationship = '$relationship'";
+ }
+
+ $query = "SELECT sl.* from {$CONFIG->dbprefix}system_log sl $relationship_join where $user and $relationship_query ($obj_query) order by sl.time_created desc limit $offset, $limit";
// fetch data from system log (needs optimisation)
- $log_data = get_data($query);
+ return get_data($query);
+ }
+
+ /**
+ * 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
+ * the view "river/CLASSNAME/EVENT" where CLASSNAME is the class of the object the system event is referring to,
+ * and EVENT is the event (create, update, delete etc).
+ *
+ * This view will be passed the log entry (as 'log_entry') and the object (as 'object') which will be accessable
+ * through the $vars[] array.
+ *
+ * It returns an array of the result of each of these views.
+ *
+ * \TODO: Limit to just one user or just one user's friends
+ * \TODO: Make this more efficient / reduce DB queries.
+ *
+ * @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 array of river entities rendered with the appropriate view.
+ */
+ function get_river_entries($by_user = "", $relationship = "", $limit = 10, $offset = 0)
+ {
+ global $CONFIG;
+ $limit = (int)$limit;
+ $offset = (int)$offset;
+ $relationship = sanitise_string($relationship);
+
+ if (is_array($by_user) && sizeof($by_user) > 0) {
+ foreach($by_user as $key => $val) {
+ $by_user[$key] = (int) $val;
+ }
+ } else {
+ $by_user = array((int)$by_user);
+ }
+
+ // Get river data
+ $log_data = __get_river_from_log($by_user, $relationship, $limit, $offset);
// until count reached, loop through and render
$river = array();
@@ -334,107 +351,83 @@
*/
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
+ global $CONFIG;
+
+ $limit = (int)$limit;
+ $offset = (int)$offset;
+ $relationship = sanitise_string($relationship);
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;
+ $by_user = array((int)$by_user);
}
- $exit = false;
+ // Get river data
+ $log_data = __get_river_from_log($by_user, $relationship, $limit, $offset);
// River objects
- $river = new ODDDocument();
-
- do
+ $river = new ODDDocument();
+ if ($log_data)
{
- $log_events = get_system_log($by_user, "","", $cnt, $off);
-
- if (!$log_events)
- $exit = true;
- else
- {
-
- foreach ($log_events as $log)
+ foreach ($log_data as $log)
+ {
+ $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);
+
+ // Belts and braces
+ if ($object instanceof $class)
{
- // 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;
+ $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 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 relationships
- if ($object instanceof ElggRelationship)
- {
- $odd = $object->export();
- $relationship_obj = new ODDRelationship(
- guid_to_uuid($log->performed_by_guid),
- $log->event,
- $odd->getAttribute('uuid')
- );
- //$relationship_obj = $object->export(); // I figure this is what you're actually interested in in this instance.
- }
+ // 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')
+ );
+ }
- // If we have handled it then add it to the document
- if ($relationship_obj) {
- $relationship_obj->setPublished($log->time_created);
- $river->addElement($relationship_obj);
- }
+ // Handle updates of relationships
+ if ($object instanceof ElggRelationship)
+ {
+ $odd = $object->export();
+ $relationship_obj = new ODDRelationship(
+ guid_to_uuid($log->performed_by_guid),
+ $log->event,
+ $odd->getAttribute('uuid')
+ );
+ }
- }
+ // 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;
}