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 {
# 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;
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 %]>
[% ' ' FOR [0..pad_depth]; display_name | html %]