aboutsummaryrefslogtreecommitdiff
path: root/engine/lib/entities.php
diff options
context:
space:
mode:
authoricewing <icewing@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-04-11 17:39:24 +0000
committericewing <icewing@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-04-11 17:39:24 +0000
commit46b7bce71977b0762d38acf5f7d597af221bab68 (patch)
tree5a05bbd6952ef2a7289b3855f08dee78fc210a98 /engine/lib/entities.php
parentdf73163e0492bc8589dc65ba3ebff71be23be60f (diff)
downloadelgg-46b7bce71977b0762d38acf5f7d597af221bab68.tar.gz
elgg-46b7bce71977b0762d38acf5f7d597af221bab68.tar.bz2
Marcus Povey <marcus@dushka.co.uk>
* Entity ODD export git-svn-id: https://code.elgg.org/elgg/trunk@435 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine/lib/entities.php')
-rw-r--r--engine/lib/entities.php64
1 files changed, 54 insertions, 10 deletions
diff --git a/engine/lib/entities.php b/engine/lib/entities.php
index 788a559d8..ab682fb2f 100644
--- a/engine/lib/entities.php
+++ b/engine/lib/entities.php
@@ -379,12 +379,49 @@
*/
public function export()
{
- $tmp = new stdClass;
- $tmp->attributes = $this->attributes;
- $tmp->attributes['uuid'] = guid_to_uuid($this->getGUID());
- $tmp->attributes['owner_uuid'] = guid_to_uuid($this->owner_guid);
- $tmp->attributes['subtype'] = get_subtype_from_id($tmp->attributes['subtype']);
- return $tmp;
+ global $CONFIG;
+
+ $tmp = array();
+
+ // Generate uuid
+ $uuid = guid_to_uuid($this->getGUID());
+
+ // Create entity
+ $tmp[] = new ODDEntity(
+ $uuid,
+ $this->attributes['type'],
+ get_subtype_from_id($tmp->attributes['subtype'])
+ );
+
+ // Now add its attributes
+ foreach ($this->attributes as $k => $v)
+ {
+ switch ($k)
+ {
+ case 'guid' : break; // Dont use guid
+ case 'subtype' : break; // Hide subtype
+ case 'type' : break; // Don't use type
+ case 'access_id' : break; // Don't use access - if can export then its public for you, then importer decides what access to give this object.
+
+ case 'owner_guid' : // Convert owner guid to uuid
+ $k = 'owner_uuid';
+ $v = guid_to_uuid($v);
+ $tmp[] = new ODDMetadata($uuid . "attr/$k/", $uuid, $k, $v, "attribute");
+ break;
+
+ case 'time_created' : // Convert to RFC 822
+ case 'time_updated' : // Convert to RFC 822
+ $v = date('r', $v);
+ $tmp[] = new ODDMetadata($uuid . "attr/$k/", $uuid, $k, $v, "attribute");
+ break;
+
+ default :
+ $tmp[] = new ODDMetadata($uuid . "attr/$k/", $uuid, $k, $v, "attribute");
+ }
+ }
+
+
+ return $tmp;
}
// IMPORTABLE INTERFACE ////////////////////////////////////////////////////////////
@@ -395,7 +432,7 @@
* @param array $data
* @param int $version
*/
- public function import(array $data, $version = 1)
+ public function import(ODD $data)
{
if ($version == 1)
{
@@ -772,10 +809,17 @@
// Get the entity
$entity = get_entity($guid);
+ if (!($entity instanceof ElggEntity))
+ throw new InvalidClassException("GUID:$guid is not an ElggEntity");
+
+ $export = $entity->export();
+
+ if (is_array($export))
+ foreach ($export as $e)
+ $returnvalue[] = $e;
+ else
+ $returnvalue[] = $export;
- if ($entity instanceof ElggEntity)
- $returnvalue[] = $entity; // Add object to list of things to serialise - actual serialisation done later
-
return $returnvalue;
}