From ac8dc55c78d5f64b91a1eeda023cd1caff900511 Mon Sep 17 00:00:00 2001 From: ben Date: Thu, 12 Feb 2009 12:53:32 +0000 Subject: Alternative river system trial. This is a test. git-svn-id: https://code.elgg.org/elgg/trunk@2723 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/lib/river2.php | 252 ++++++++++++++++++++++++++++++++++ engine/schema/mysql.sql | 19 +++ engine/schema/upgrades/2009021201.sql | 19 +++ version.php | 4 +- views/default/river/item/list.php | 17 +++ views/default/river/item/wrapper.php | 38 +++++ 6 files changed, 347 insertions(+), 2 deletions(-) create mode 100644 engine/lib/river2.php create mode 100644 engine/schema/upgrades/2009021201.sql create mode 100644 views/default/river/item/list.php create mode 100644 views/default/river/item/wrapper.php diff --git a/engine/lib/river2.php b/engine/lib/river2.php new file mode 100644 index 000000000..577cefc16 --- /dev/null +++ b/engine/lib/river2.php @@ -0,0 +1,252 @@ +access_id; + + $type = $object->getType(); + $subtype = $object->getSubtype(); + + $action_type = sanitise_string($action_type); + + // Load config + global $CONFIG; + + // Attempt to save river item; return success status + return insert_data("insert into {$CONFIG->dbprefix}river " . + " set type = '{$type}', " . + " subtype = '{$subtype}', " . + " action_type = '{$action_type}', " . + " access_id = {$access_id}, " . + " view = '{$view}', " . + " subject_guid = {$subject_guid}, " . + " object_guid = {$object_guid}, " . + " posted = {$posted} "); + + } + + /** + * Removes all items relating to a particular acting entity from the river + * + * @param int $subject_guid The GUID of the entity + * @return true|false Depending on success + */ + function remove_from_river_by_subject( + $subject_guid + ) { + + // Sanitise + $subject_guid = (int) $subject_guid; + + // Load config + global $CONFIG; + + // Remove + return delete_data("delete from {$CONFIG->dbprefix}river where subject_guid = {$subject_guid}"); + + } + + /** + * Removes all items relating to a particular entity being acted upon from the river + * + * @param int $object_guid The GUID of the entity + * @return true|false Depending on success + */ + function remove_from_river_by_object( + $object_guid + ) { + + // Sanitise + $object_guid = (int) $object_guid; + + // Load config + global $CONFIG; + + // Remove + return delete_data("delete from {$CONFIG->dbprefix}river where object_guid = {$object_guid}"); + + } + + /** + * Retrieves items from the river. All parameters are optional. + * + * @param int|array $subject_guid Acting entity to restrict to. Default: all + * @param int|array $object_guid Entity being acted on to restrict to. Default: all + * @param string $subject_relationship If set to a relationship type, this will use $subject_guid as the starting point and set the subjects to be all users this entity has this relationship with (eg 'friend'). Default: blank + * @param string $type The type of entity to restrict to. Default: all + * @param string $subtype The subtype of entity to restrict to. Default: all + * @param string $action_type The type of river action to restrict to. Default: all + * @param int $limit The number of items to retrieve. Default: 20 + * @param int $offset The page offset. Default: 0 + * @param int $posted_min The minimum time period to look at. Default: none + * @param int $posted_max The maximum time period to look at. Default: none + * @return array|false Depending on success + */ + function get_river_items( + $subject_guid = 0, + $object_guid = 0, + $subject_relationship = '', + $type = '', + $subtype = '', + $action_type = '', + $limit = 20, + $offset = 0, + $posted_min = 0, + $posted_max = 0 + ) { + + // Sanitise variables + if (!is_array($subject_guid)) { + $subject_guid = (int) $subject_guid; + } else { + foreach($subject_guid as $key => $temp) { + $subject_guid[$key] = (int) $temp; + } + } + if (!is_array($object_guid)) { + $object_guid = (int) $object_guid; + } else { + foreach($object_guid as $key => $temp) { + $object_guid[$key] = (int) $temp; + } + } + if (!empty($type)) $action_type = sanitise_string($type); + if (!empty($subtype)) $action_type = sanitise_string($subtype); + if (!empty($action_type)) $action_type = sanitise_string($action_type); + $limit = (int) $limit; + $offset = (int) $offset; + $posted_min = (int) $posted_min; + $posted_max = (int) $posted_max; + + // Construct 'where' clauses for the river + $where = array(); + $where[] = get_access_sql_suffix(); + + if (empty($subject_relationship)) { + if (!empty($subject_guid)) + if (!is_array($subject_guid)) { + $where[] = " subject_guid = {$subject_guid} "; + } else { + $where[] = " subject_guid in (" . implode(',',$subject_guid) . ") "; + } + } else { + if (!is_array($subject_guid)) + if ($entities = get_entities_from_relationship($subject_relationship,$subject_guid,false,'','',0,'',9999)) { + $guids = array(); + foreach($entities as $entity) $guids[] = (int) $entity->guid; + $guids[] = $subject_guid; + $where[] = " subject_guid in (" . implode(',',$guids) . ") "; + } + } + if (!empty($object_guid)) + if (!is_array($object_guid)) { + $where[] = " object_guid = {$object_guid} "; + } else { + $where[] = " object_guid in (" . implode(',',$object_guid) . ") "; + } + if (!empty($type)) $where[] = " type = '{$type}' "; + if (!empty($subtype)) $where[] = " subtype = '{$subtype}' "; + if (!empty($action_type)) $where[] = " action_type = '{$action_type}' "; + if (!empty($posted_min)) $where[] = " posted > {$posted_min} "; + if (!empty($posted_max)) $where[] = " posted < {$posted_max} "; + + $whereclause = implode(' and ', $where); + + // Construct main SQL + $sql = "select id,type,subtype,action_type,access_id,view,subject_guid,object_guid,posted from {$CONFIG->dbprefix}river where {$whereclause} limit {$offset},{$limit}"; + + // Get data + return get_data($sql); + + } + + /** + * Returns a human-readable representation of a river item + * + * @see get_river_items + * + * @param stdClass $item A river item object as returned from get_river_items + * @return string|false Depending on success + */ + function elgg_view_river_item($item) { + if (isset($item->view)) { + + if (elgg_view_exists($item->view)) { + $body = elgg_view($item->view,array( + 'item' => $item + )); + } + return elgg_view('river/item/wrapper',array( + 'item' => $item, + 'body' => $body + )); + + } + return false; + } + + function elgg_view_river_items($subject_guid = 0, + $object_guid = 0, + $subject_relationship = '', + $type = '', + $subtype = '', + $action_type = '', + $limit = 20, + $posted_min = 0, + $posted_max = 0) { + + // Get input from outside world and sanitise it + $offset = (int) get_input('offset',0); + + // Get river items, if they exist + if ($riveritems = get_river_items($subject_guid,$object_guid,$subject_relationship,$type,$subtype,$action_type,$limit,$offset,$posted_min,$posted_max)) { + + return elgg_view('river/item/list',array( + 'limit' => $limit, + 'offset' => $offset, + 'items' => $riveritems, + )); + + } + + return ''; + + } + +?> \ No newline at end of file diff --git a/engine/schema/mysql.sql b/engine/schema/mysql.sql index 2a62d3c92..87e8adafb 100644 --- a/engine/schema/mysql.sql +++ b/engine/schema/mysql.sql @@ -349,3 +349,22 @@ CREATE TABLE `prefix_system_log` ( KEY `river_key` (`object_type`, `object_subtype`, `event`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; +-- River + CREATE TABLE `prefix_river` ( + `id` INT NOT NULL AUTO_INCREMENT , + `type` VARCHAR( 8 ) NOT NULL , + `subtype` VARCHAR( 32 ) NOT NULL , + `action_type` VARCHAR( 32 ) NOT NULL , + `access_id` INT NOT NULL , + `view` TEXT NOT NULL , + `subject_guid` INT NOT NULL , + `object_guid` INT NOT NULL , + `posted` INT NOT NULL , + PRIMARY KEY ( `id` ) , + KEY `type` (`type`), + KEY `action_type` (`action_type`), + KEY `access_id` (`access_id`), + KEY `subject_guid` (`subject_guid`), + KEY `object_guid` (`object_guid`,), + KEY `posted` (`posted`) +) ENGINE = MYISAM DEFAULT CHARSET=utf8; \ No newline at end of file diff --git a/engine/schema/upgrades/2009021201.sql b/engine/schema/upgrades/2009021201.sql new file mode 100644 index 000000000..e3edf66ba --- /dev/null +++ b/engine/schema/upgrades/2009021201.sql @@ -0,0 +1,19 @@ +-- River + CREATE TABLE IF NOT EXISTS `prefix_river` ( + `id` INT NOT NULL AUTO_INCREMENT , + `type` VARCHAR( 8 ) NOT NULL , + `subtype` VARCHAR( 32 ) NOT NULL , + `action_type` VARCHAR( 32 ) NOT NULL , + `access_id` INT NOT NULL , + `view` TEXT NOT NULL , + `subject_guid` INT NOT NULL , + `object_guid` INT NOT NULL , + `posted` INT NOT NULL , + PRIMARY KEY ( `id` ) , + KEY `type` (`type`), + KEY `action_type` (`action_type`), + KEY `access_id` (`access_id`), + KEY `subject_guid` (`subject_guid`), + KEY `object_guid` (`object_guid`), + KEY `posted` (`posted`) +) ENGINE = MYISAM DEFAULT CHARSET=utf8; \ No newline at end of file diff --git a/version.php b/version.php index f5c3d5c8f..8ce8f88db 100644 --- a/version.php +++ b/version.php @@ -13,9 +13,9 @@ * @link http://elgg.org/ */ - $version = 2009012301; // YYYYMMDD = Elgg Date + $version = 2009021201; // YYYYMMDD = Elgg Date // XX = Interim incrementer - $release = '1.2'; // Human-friendly version name + $release = '1.4'; // Human-friendly version name ?> \ No newline at end of file diff --git a/views/default/river/item/list.php b/views/default/river/item/list.php new file mode 100644 index 000000000..781c18a48 --- /dev/null +++ b/views/default/river/item/list.php @@ -0,0 +1,17 @@ + +
+ +
\ No newline at end of file diff --git a/views/default/river/item/wrapper.php b/views/default/river/item/wrapper.php new file mode 100644 index 000000000..efa377ceb --- /dev/null +++ b/views/default/river/item/wrapper.php @@ -0,0 +1,38 @@ + + +
+
+
+
+
+ + + (posted); + + ?>) + +
+
+
+
+
\ No newline at end of file -- cgit v1.2.3