diff options
author | icewing <icewing@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2008-03-28 19:18:55 +0000 |
---|---|---|
committer | icewing <icewing@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2008-03-28 19:18:55 +0000 |
commit | 6441a960edc875a0c33fa8bbd735fd1faebaa552 (patch) | |
tree | 4127ac318d37bf0c36b454d1918dadce5e1343d2 /engine/lib/annotations.php | |
parent | 5aa0bbb5bef7265fb570b400f7966b8411295f9e (diff) | |
download | elgg-6441a960edc875a0c33fa8bbd735fd1faebaa552.tar.gz elgg-6441a960edc875a0c33fa8bbd735fd1faebaa552.tar.bz2 |
Marcus Povey <marcus@dushka.co.uk>
* Metadata and Annotations now exported.
git-svn-id: https://code.elgg.org/elgg/trunk@291 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine/lib/annotations.php')
-rw-r--r-- | engine/lib/annotations.php | 49 |
1 files changed, 48 insertions, 1 deletions
diff --git a/engine/lib/annotations.php b/engine/lib/annotations.php index e1570ac0d..cceb8fd05 100644 --- a/engine/lib/annotations.php +++ b/engine/lib/annotations.php @@ -16,7 +16,7 @@ * An annotation is similar to metadata each entity can contain more than one of each annotation. * @author Marcus Povey <marcus@dushka.co.uk> */ - class ElggAnnotation + class ElggAnnotation implements Exportable { /** * This contains the site's main properties (id, etc) @@ -105,6 +105,12 @@ return delete_annotation($this->id); } + public function export() + { + $tmp = new stdClass; + $tmp->attributes = $this->attributes; + return $tmp; + } } /** @@ -442,4 +448,45 @@ return delete_data(); } + /** + * Handler called by trigger_plugin_hook on the "export" event. + */ + function export_annotations_plugin_hook($hook, $entity_type, $returnvalue, $params) + { + global $CONFIG; + + // Sanity check values + if ((!is_array($params)) && (!isset($params['guid']))) + throw new InvalidParameterException("GUID has not been specified during export, this should never happen."); + + if (!is_array($returnvalue)) + throw new InvalidParameterException("Entity serialisation function passed a non-array returnvalue parameter"); + + $guid = (int)$params['guid']; + $access = get_access_list(); + + $where = array(); + + if ($guid != 0) + $where[] = "a.entity_guid=$guid"; + + $query = "SELECT a.*, n.string as name, v.string as value from {$CONFIG->dbprefix}annotations a JOIN {$CONFIG->dbprefix}entities e on a.entity_guid = e.guid JOIN {$CONFIG->dbprefix}metastrings v on a.value_id=v.id JOIN {$CONFIG->dbprefix}metastrings n on a.name_id = n.id where "; + foreach ($where as $w) + $query .= " $w and "; + $query .= " (a.access_id in {$access} or (a.access_id = 0 and a.owner_guid = {$_SESSION['id']}))"; // Add access controls + $query .= " order by a.time_created"; // Add order and limit + error_log($query); + $annotations = get_data($query, "row_to_elggannotation"); + + if ($annotations) + { + foreach ($annotations as $a) + $returnvalue[] = $a; + } + + return $returnvalue; + } + + /** Register the hook, ensuring entities are serialised first */ + register_plugin_hook("export", "all", "export_annotations_plugin_hook", 2); ?>
\ No newline at end of file |