From 675d8cf5e85ff45b5a6d8d015c8f2b5923f78014 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Mon, 20 Feb 2012 16:30:11 -0500 Subject: [PATCH] copy loc groups: tpac Signed-off-by: Bill Erickson --- .../src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm | 56 +++++++++++++++------- .../perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm | 17 +++++-- 2 files changed, 50 insertions(+), 23 deletions(-) diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm index 5546e4b98b..1d2d4d0f85 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm @@ -252,12 +252,9 @@ sub load_common { } } - # load copy location search groups and see if there is a "logc" - # paremeter set. If so, use it to set/override the "loc" parameter - # as well as the copy_location_group context var - $self->load_copy_location_groups; - + $self->extract_copy_location_group_info; $ctx->{search_ou} = $self->_get_search_lib(); + $self->load_copy_location_groups; $self->staff_saved_searches_set_expansion_state if $ctx->{is_staff}; return Apache2::Const::OK; @@ -287,24 +284,47 @@ sub staff_saved_searches_set_expansion_state { $self->ctx->{saved_searches_expanded} = $value; } -# If "locg" is set, we extract the org unit and copy location. -# The org unit from 'locg' overrides the local CGI variable 'loc'. -# Overridding it here will not override it globaly though (i.e. in -# the template environment), unless the same CGI ref is used everywhere, -# which is usually isn't. To be safe, always use ctx.search_ou -# to determine the context org unit. +# 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} = $grp if $grp; + $ctx->{copy_location_group_org} = $org; + } +} + sub load_copy_location_groups { my $self = shift; - my $grps = $self->editor->search_asset_copy_location_group({opac_visible => 't'}); + 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} + } + } + }); + my %buckets; push(@{$buckets{$_->owner}}, $_) for @$grps; - $self->ctx->{copy_location_groups} = \%buckets; - if (my $clump = $self->cgi->param('locg')) { - my ($org, $grp) = split(/:/, $clump); - $self->ctx->{copy_location_group} = $grp if $grp; - $self->cgi->param('loc', $org); - } + $ctx->{copy_location_groups} = \%buckets; } # physical_loc (i.e. "original location") passed in as a URL 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 5ea922f596..43857757b0 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm @@ -278,28 +278,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; } 1; -- 2.11.0