Custom Org Tree : tpac
authorBill Erickson <berick@esilibrary.com>
Mon, 19 Mar 2012 20:31:08 +0000 (16:31 -0400)
committerBill Erickson <berick@esilibrary.com>
Fri, 30 Mar 2012 13:10:17 +0000 (09:10 -0400)
If configured and active, the tpac will now use the custom 'opac' tree
for the org unit selectors.  This will be true in both the public
catalog and the staff client catalog.  The staff client catalog will
continue to display hidden org units.

If the opac.org_unit.non_inheritied_visibility global flag is set, the
public catalog will display child nodes of hidden org units in the
custom tree.

Signed-off-by: Bill Erickson <berick@esilibrary.com>
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm
Open-ILS/src/templates/opac/parts/org_selector.tt2

index e9b61f4..a864ff6 100644 (file)
@@ -122,6 +122,47 @@ sub init_ro_object_cache {
         return [ values %{$cache{map}{aou}} ];
     };
 
+    $ro_object_subs->{aouct_tree} = sub {
+
+        # fetch the org unit tree
+        unless(exists $cache{aouct_tree}) {
+            $cache{aouct_tree} = undef;
+
+            my $tree_id = $e->search_actor_org_unit_custom_tree(
+                {purpose => 'opac', active => 't'},
+                {idlist => 1}
+            )->[0];
+
+            if ($tree_id) {
+                my $node_tree = $e->search_actor_org_unit_custom_tree_node([
+                {parent_node => undef, tree => $tree_id},
+                {   flesh        => -1,
+                    flesh_fields => {aouctn => ['children', 'org_unit']},
+                    order_by     => {aouctn => 'sibling_order'}
+                }
+                ])->[0];
+
+                # tree-ify the org units.  note that since the orgs are fleshed
+                # upon retrieval, this org tree will not clobber ctx->{aou_tree}.
+                my @nodes = ($node_tree);
+                while (my $node = shift(@nodes)) {
+                    my $aou = $node->org_unit;
+                    $aou->children([]);
+                    for my $cnode (@{$node->children}) {
+                        my $child_org = $cnode->org_unit;
+                        $child_org->parent_ou($aou->id);
+                        $child_org->ou_type( $ro_object_subs->{get_aout}->($child_org->ou_type) );
+                        push(@{$aou->children}, $child_org);
+                        push(@nodes, $cnode);
+                    }
+                }
+
+                $cache{aouct_tree} = $node_tree->org_unit;
+            }
+        }
+
+        return $cache{aouct_tree};
+    };
 
     # turns an ISO date into something TT can understand
     $ro_object_subs->{parse_datetime} = sub {
index 49775c4..3e32040 100644 (file)
@@ -7,7 +7,7 @@
 # Use of PROCESS results in internal variables, such as value or org_unit, to "leak" out
 
 BLOCK build_org_selector;
-    node_stack = [{org => org_unit || ctx.aou_tree}];
+    node_stack = [{org => org_unit || ctx.aouct_tree || ctx.aou_tree}];
     inherited_vis = ctx.get_cgf('opac.org_unit.non_inheritied_visibility').enabled == 'f';
 
     IF !name; 
@@ -79,26 +79,22 @@ BLOCK build_org_selector;
                 disabled = 'disabled="disabled"';
             ELSIF node_value == value;
                 selected = 'selected="selected"';
-            END;
+            END; 
 
-            pad_depth = org_unit.ou_type.depth;
+            pad_depth = 0;
 
-            # copy loc groups appear as children of the owner (current) org
+            # copy loc groups appear as children of the owning org unit
             SET pad_depth = pad_depth + 1 IF loc_grp;
 
-            # for each parent org unit that is hidden, decrease the pad depth by one.  
-            IF !ctx.is_staff; 
-                porg = ctx.get_aou(org_unit.parent_ou);
-                WHILE porg;
-                    SET pad_depth = pad_depth - 1 IF porg.opac_visible == 'f';
-                    porg = ctx.get_aou(porg.parent_ou);
-                END;
+            # determine the depth by calculating the distance from the root
+            porg = ctx.get_aou(org_unit.parent_ou);
+            WHILE porg;
+                SET pad_depth = pad_depth + 1 IF porg.opac_visible == 't' OR ctx.is_staff;
+                porg = ctx.get_aou(porg.parent_ou);
             END;
 
             pad_depth = pad_depth * 2;
-            display_name = loc_grp ? loc_grp.name : org_unit.name;
-            
-            %] 
+            display_name = loc_grp ? loc_grp.name : org_unit.name %]
 
             <option value='[% node_value %]' [% selected %] [% disabled %] [% css_class %]> 
                 [% '&nbsp;' FOR [0..pad_depth]; display_name | html %]