group tree method and FM support
authormiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Fri, 16 Dec 2005 23:37:58 +0000 (23:37 +0000)
committermiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Fri, 16 Dec 2005 23:37:58 +0000 (23:37 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@2429 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/perlmods/OpenILS/Application/Actor.pm
Open-ILS/src/perlmods/OpenILS/Utils/Fieldmapper.pm

index bfc39da..78813d2 100644 (file)
@@ -1227,6 +1227,47 @@ sub retrieve_groups {
                "open-ils.storage.direct.permission.grp_tree.retrieve.all.atomic");
 }
 
+__PACKAGE__->register_method(
+       method  => "retrieve_groups_tree",
+       api_name        => "open-ils.actor.groups.tree.retrieve",
+       notes           => <<"  NOTES");
+       Returns a list of user groups
+       NOTES
+sub retrieve_groups_tree {
+       my( $self, $client ) = @_;
+       my $groups = $apputils->simple_scalar_request(
+               "open-ils.storage",
+               "open-ils.storage.direct.permission.grp_tree.retrieve.all.atomic");
+       return $self->build_group_tree($groups);        
+}
+
+
+# turns an org list into an org tree
+sub build_group_tree {
+
+       my( $self, $grplist) = @_;
+
+       return $grplist unless ( 
+                       ref($grplist) and @$grplist > 1 );
+
+       my @list = sort { $a->name cmp $b->name } @$grplist;
+
+       my $root;
+       for my $grp (@list) {
+
+               if ($grp and !defined($grp->parent)) {
+                       $root = $grp;
+                       next;
+               }
+               my ($parent) = grep { $_->id == $grp->parent} @list;
+
+               $parent->children([]) unless defined($parent->children); 
+               push( @{$parent->children}, $grp );
+       }
+
+       return $root;
+
+}
 
 
 
index d153d98..7591ff2 100644 (file)
@@ -208,7 +208,7 @@ sub _init {
                'Fieldmapper::asset::call_number_note'          => { hint => 'acnn'    },
 
                'Fieldmapper::permission::perm_list'            => { hint => 'ppl'    },
-               'Fieldmapper::permission::grp_tree'             => { hint => 'pgt'    },
+               'Fieldmapper::permission::grp_tree'             => { hint => 'pgt', proto_fields => { children => 1 } },
                'Fieldmapper::permission::usr_grp_map'          => { hint => 'pugm'   },
                'Fieldmapper::permission::usr_perm_map'         => { hint => 'pupm'   },
                'Fieldmapper::permission::grp_perm_map'         => { hint => 'pgpm'   },