From 32458ad85b11e517eca78ebb3aead3300e31b4b2 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Fri, 17 Feb 2012 11:57:19 -0500 Subject: [PATCH] Copy Location Search Groups : TPac org unit selector Adds support for viewing and searching on copy location groups in the tpac. Groups appear within the org unit selector, when the selector is used in a search context. Groups display below the owning org unit similar to a child org unit. Groups are displayed for all org units that meet the following criteria: search org unit, physical location, patron home org unit, plus ancestors and descendents of each. To support this, TPac gets a new "locg" CGI parameter, which contains the org unit and copy location group. It takes the form org_id:group_id. The TPac mod_perl code will extract this value and popuplate the search_ou accordingly. For consistency, we also use ctx.search_ou instead of directly checking CGI.param('loc') within the template environment. This also includes a rewrite of the org_selector.tt2 template. It changes it from a recursive routine to a depth-first while loop. I did this mainly because the recursive approach was suffering from global variable clobbering in the template environment. In theory, this new approach should be faster as well. Signed-off-by: Bill Erickson Signed-off-by: Dan Scott --- .../perlmods/lib/OpenILS/WWW/EGCatLoader.pm | 7 +- .../lib/OpenILS/WWW/EGCatLoader/Search.pm | 4 + .../lib/OpenILS/WWW/EGCatLoader/Util.pm | 64 ++++++++++++-- Open-ILS/src/templates/opac/advanced.tt2 | 4 +- .../templates/opac/myopac/prefs_notify.tt2 | 2 +- .../templates/opac/parts/advanced/expert.tt2 | 1 - .../templates/opac/parts/advanced/search.tt2 | 2 +- .../src/templates/opac/parts/org_selector.tt2 | 87 +++++++++++++------ .../src/templates/opac/parts/place_hold.tt2 | 2 +- .../templates/opac/parts/preserve_params.tt2 | 2 +- .../opac/parts/record/copy_counts.tt2 | 2 +- .../opac/parts/record/copy_table.tt2 | 2 +- .../templates/opac/parts/record/refworks.tt2 | 5 +- .../templates/opac/parts/record/series.tt2 | 2 +- .../templates/opac/parts/record/subjects.tt2 | 1 - .../src/templates/opac/parts/searchbar.tt2 | 2 +- 16 files changed, 138 insertions(+), 51 deletions(-) diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm index b1ffd40587..76b3f63353 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm @@ -251,10 +251,13 @@ sub load_common { return $self->load_logout($self->apache->unparsed_uri); } } - $ctx->{search_ou} = $self->_get_search_lib(); + $self->extract_copy_location_group_info; + $ctx->{search_ou} = $self->_get_search_lib(); $self->staff_saved_searches_set_expansion_state if $ctx->{is_staff}; $self->load_eg_cache_hash; + $self->load_copy_location_groups; + $self->staff_saved_searches_set_expansion_state if $ctx->{is_staff}; return Apache2::Const::OK; } @@ -303,8 +306,6 @@ sub get_physical_loc { return $self->cgi->cookie(COOKIE_PHYSICAL_LOC); } - - # ----------------------------------------------------------------------------- # Log in and redirect to the redirect_to URL (or home) # ----------------------------------------------------------------------------- diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Search.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Search.pm index b8907a6148..ecf8ef0b04 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Search.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Search.pm @@ -112,6 +112,10 @@ sub _prepare_biblio_search { $query .= " site($site)"; } + if (my $grp = $ctx->{copy_location_group}) { + $query .= " location_groups($grp)"; + } + if(!$site) { ($site) = ($query =~ /site\(([^\)]+)\)/); $site ||= $ctx->{aou_tree}->()->shortname; diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm index f10ccb796c..e672eac1f7 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm @@ -280,28 +280,35 @@ sub fetch_marc_xml_by_id { sub _get_search_lib { my $self = shift; + my $ctx = $self->ctx; + + # avoid duplicate lookups + return $ctx->{search_ou} if $ctx->{search_ou}; + + my $loc = $ctx->{copy_location_group_org}; + return $loc if $loc; # loc param takes precedence - my $loc = $self->cgi->param('loc'); + $loc = $self->cgi->param('loc'); return $loc if $loc; - if ($self->ctx->{user}) { + if ($ctx->{user}) { # See if the user has a search library preference my $lset = $self->editor->search_actor_user_setting({ - usr => $self->ctx->{user}->id, + usr => $ctx->{user}->id, name => 'opac.default_search_location' })->[0]; return OpenSRF::Utils::JSON->JSON2perl($lset->value) if $lset; # Otherwise return the user's home library - return $self->ctx->{user}->home_ou; + return $ctx->{user}->home_ou; } if ($self->cgi->param('physical_loc')) { return $self->cgi->param('physical_loc'); } - return $self->ctx->{aou_tree}->()->id; + return $ctx->{aou_tree}->()->id; } # This is defensively coded since we don't do much manual reading from the @@ -340,4 +347,51 @@ sub load_eg_cache_hash { } } +# Extracts the copy location org unit and group from the +# "logc" param, which takes the form org_id:grp_id. +sub extract_copy_location_group_info { + my $self = shift; + my $ctx = $self->ctx; + if (my $clump = $self->cgi->param('locg')) { + my ($org, $grp) = split(/:/, $clump); + $ctx->{copy_location_group_org} = $org; + $ctx->{copy_location_group} = $grp if $grp; + } +} + +sub load_copy_location_groups { + my $self = shift; + my $ctx = $self->ctx; + + # User can access to the search location groups at the current + # search lib, the physical location lib, and the patron's home ou. + my @ctx_orgs = $ctx->{search_ou}; + push(@ctx_orgs, $ctx->{physical_loc}) if $ctx->{physical_loc}; + push(@ctx_orgs, $ctx->{user}->home_ou) if $ctx->{user}; + + my $grps = $self->editor->search_asset_copy_location_group([ + { + opac_visible => 't', + owner => { + in => { + select => {aou => [{ + column => 'id', + transform => 'actor.org_unit_full_path', + result_field => 'id', + }]}, + from => 'aou', + where => {id => \@ctx_orgs} + } + } + }, + {order_by => {acplg => 'pos'}} + ]); + + my %buckets; + push(@{$buckets{$_->owner}}, $_) for @$grps; + $ctx->{copy_location_groups} = \%buckets; +} + + + 1; diff --git a/Open-ILS/src/templates/opac/advanced.tt2 b/Open-ILS/src/templates/opac/advanced.tt2 index 17cb74f334..220c56fd20 100644 --- a/Open-ILS/src/templates/opac/advanced.tt2 +++ b/Open-ILS/src/templates/opac/advanced.tt2 @@ -1,9 +1,9 @@ -[%- PROCESS "opac/parts/header.tt2"; +[%- PROCESS "opac/parts/header.tt2"; WRAPPER "opac/parts/base.tt2"; INCLUDE "opac/parts/topnav.tt2"; ctx.page_title = l("Advanced Search"); pane = CGI.param("pane") || "advanced"; - loc = CGI.param("loc"); + loc = ctx.search_ou; -%]