Tree rest resource and sorting
David Steinberger <[email protected]>
| Newsgroups | gmane.comp.web.gallery.devel |
|---|---|
| Organization | FH - KufsteinTirol |
| Message-ID | <[email protected]> |
Team, I'm reworking the data model of my iPhone app. One thing I want to revisit is how I deal with the tree rest resource (tree_rest.php). Reason: I know that the tree_rest.php delivers the objects in the right order, but this doesn't help me much. I need to store and retrieve the array and by doing such an operation with an array the order might be lost. Proposed solution: The patch attached adds a relative_position attribute to each entity. Via this attribute the entity order can be reconstructed at any time. There's no impact on performance and overall structure. Please review and merge to master or propose something even better. Thanks, David --- FYI Details: I use core data to cache all objects (tree/album, items, tags, ...). Core data is kind of a database for objects on iOS. The tree is modeled via a Class that has a NSString property that holds the url (that's the primary key) and a NSArray that holds all the entities. But when I retrieve the object-graph iOS applies any sorting. ==> A sort-attribute is needed. ------------------------------------------------------------------------------ Simplify data backup and recovery for your virtual environment with vRanger. Installation's a snap, and flexible recovery options mean your data is safe, secure and there when you need it. Data protection magic? Nope - It's vRanger. Get your free trial download today. http://p.sf.net/sfu/quest-sfdev2dev __[ g a l l e r y - d e v e l ]_________________________ [ list info/archive --> http://gallery.sf.net/lists.php ] [ gallery info/FAQ/download --> http://gallery.sf.net ]
0001-enhanced-tree-rest-resource-by-relative-position.patch
(text/plain, 1.7 KB)
>From 129f58bc639944982df13f620be8e6f05c79523d Mon Sep 17 00:00:00 2001 From: David Steinberger <[email protected]> Date: Wed, 1 Jun 2011 19:35:05 +0200 Subject: [PATCH] enhanced tree rest resource by relative position Signed-off-by: David Steinberger <[email protected]> --- modules/gallery/helpers/tree_rest.php | 11 ++++++++--- 1 files changed, 8 insertions(+), 3 deletions(-) diff --git a/modules/gallery/helpers/tree_rest.php b/modules/gallery/helpers/tree_rest.php index d9468ed..87c629b 100644 --- a/modules/gallery/helpers/tree_rest.php +++ b/modules/gallery/helpers/tree_rest.php @@ -58,13 +58,18 @@ class tree_rest_Core { $fields = explode(",", $p->fields); $query_params[] = "fields={$p->fields}"; } + + $entity_fields = $item->as_restful_array($fields); + $entity_fields["relative_position"] = -1; $entity = array(array("url" => rest::url("item", $item), - "entity" => $item->as_restful_array($fields))); + "entity" => $entity_fields)); $members = array(); - foreach ($item->viewable()->descendants(null, null, $where) as $child) { + foreach ($item->viewable()->descendants(null, null, $where) as $i => $child) { + $entity_fields = $child->as_restful_array($fields); + $entity_fields["relative_position"] = $i; $entity[] = array("url" => rest::url("item", $child), - "entity" => $child->as_restful_array($fields)); + "entity" => $entity_fields); if (isset($lowest_depth) && $child->level == $lowest_depth) { $members[] = url::merge_querystring(rest::url("tree", $child), $query_params); } -- 1.7.5