$self->load_eg_cache_hash;
$self->load_copy_location_groups;
$self->staff_saved_searches_set_expansion_state if $ctx->{is_staff};
+ $self->load_search_filter_groups($ctx->{search_ou});
return Apache2::Const::OK;
}
$query .= " $1($term)" if length $term;
}
+ # filter group entries. Entries from like filters are grouped into a single
+ # filter_group_entry() filter (ORed). Each collection is ANDed together.
+ # fg:foo_group=foo_entry_id
+ foreach (grep /^fg:/, $cgi->param) {
+ /:(-?\w+)$/ or next;
+ my $term = join(",", $cgi->param($_));
+ $query .= " filter_group_entry($term)" if length $term;
+ }
+
if ($cgi->param("bookbag")) {
$query .= " container(bre,bookbag," . int($cgi->param("bookbag")) . ")";
}
list => {},
search => {},
org_settings => {},
- eg_cache_hash => undef
+ eg_cache_hash => undef,
+ search_filter_groups => {}
);
sub init_ro_object_cache {
return;
}
+sub load_search_filter_groups {
+ my $self = shift;
+ my $ctx_org = shift;
+ my $org_list = $U->get_org_ancestors($ctx_org, 1);
+
+ my %seen;
+ for my $org_id (@$org_list) {
+
+ my $grps;
+ if (!$cache{search_filter_groups}{$org_id}) {
+ $grps = $self->editor->search_actor_search_filter_group([
+ {owner => $org_id},
+ { flesh => 2,
+ flesh_fields => {
+ asfg => ['entries'],
+ asfge => ['query']
+ }
+ }
+ ]);
+ $cache{search_filter_groups}{$org_id} = $grps;
+ }
+
+ # for the current context, if a descendant org has a group
+ # with a matching code replace the group from the parent.
+ $seen{$_->code} = $_ for @$grps;
+ }
+
+ return $self->ctx->{search_filter_groups} = \%seen;
+}
+
+
1;
--- /dev/null
+[%-
+ # If caller passes a list of possible filter_groups
+ # search all until we find some values
+ IF !filter_group.size; filter_group = [filter_group]; END;
+ group = '';
+ FOR code IN filter_group;
+ group = ctx.search_filter_groups.$code;
+ LAST IF group AND group.entries.size;
+ END;
+ name = name || "fg:" _ group.code;
+ id = id || group.code _ "_selector";
+ values = values || CGI.param(name);
+-%]
+
+<select id='[% id %]' name='[% name %]'[%
+ multiple ? ' multiple="multiple"' : '';
+ size ? (' size="' _ size _ '"') : ''; %]>
+[% IF none_ok %]
+ <option value=''>[% none_label ? none_label : l('-- Any --') %]</option>
+[% END;
+# turn the list of objects into a list of hashes to
+# leverage TT's array.sort('<hashkey>') behavior
+sorter = [];
+FOR o IN group.entries;
+ sorter.push({id => o.id, label => o.query.label});
+END;
+FOR o IN sorter.sort('label') %]
+ <option value='[% o.id %]'[% values.grep(o.id).size ? ' selected="selected"' : '' %]>[% o.label | html %]</option>
+[% END -%]
+</select>
+