From d04e4cea8ffbd0e9e9ab5bb11fa6e4b60c3443c5 Mon Sep 17 00:00:00 2001 From: Dan Scott Date: Tue, 27 Dec 2011 12:31:03 -0500 Subject: [PATCH] TPAC: Uniform search lib / depth settings The current TPAC code uses logic embedded within the templates to determine which org unit and depth to apply to searches. This commit attempts to standardize the logic within the new OpenILS::WWWW::EGCatLoader::Util::_get_search_lib() function and sets the result as a new context variable, "search_ou". The org unit is determined as follows (first matching condition wins): * specific CGI "loc" value * logged-in user's preferred search library * logged-in user's home org unit * specific CGI "physical_loc" value The depth is set as follows (first matching condition wins): * specific CGI "depth" value * depth of the chosen org_unit As of this commit, a library that wishes to set the a default search org unit for any given user should set the "physical_loc" CGI param; after the user performs their first search, the "loc" CGI param will propagate through most interfaces. When a user clicks "Your account log in", the user's preferred search library or home org unit will be set as the new search lib. At any time after that, the user can select a different org unit from the org unit selector to explicitly set the "loc" CGI param. Signed-off-by: Dan Scott Signed-off-by: Jason Stephenson --- .../perlmods/lib/OpenILS/WWW/EGCatLoader.pm | 1 + .../lib/OpenILS/WWW/EGCatLoader/Account.pm | 1 + .../lib/OpenILS/WWW/EGCatLoader/Record.pm | 4 +-- .../lib/OpenILS/WWW/EGCatLoader/Search.pm | 17 ++++++------ .../lib/OpenILS/WWW/EGCatLoader/Util.pm | 26 +++++++++++++++++++ .../templates/opac/parts/advanced/search.tt2 | 2 +- .../src/templates/opac/parts/searchbar.tt2 | 2 +- 7 files changed, 40 insertions(+), 13 deletions(-) diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm index 3c10db76f5..59a2cb1fba 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm @@ -183,6 +183,7 @@ sub redirect_auth { sub load_simple { my ($self, $page) = @_; $self->ctx->{page} = $page; + $self->ctx->{search_ou} = $self->_get_search_lib(); if (my $patron_barcode = $self->cgi->param("patron_barcode")) { # Special CGI variable from staff client; propagate henceforth as cookie diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm index 30d2cbaacc..526fbfa927 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm @@ -1239,6 +1239,7 @@ sub load_myopac_main { my $self = shift; my $limit = $self->cgi->param('limit') || 0; my $offset = $self->cgi->param('offset') || 0; + $self->ctx->{search_ou} = $self->_get_search_lib(); return $self->prepare_fines($limit, $offset) || Apache2::Const::OK; } diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Record.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Record.pm index 97a6fa559a..3d1d6c819e 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Record.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Record.pm @@ -14,8 +14,8 @@ sub load_record { my $ctx = $self->ctx; $ctx->{page} = 'record'; - my $org = $self->cgi->param('loc') || $ctx->{aou_tree}->()->id; - my $depth = $self->cgi->param('depth') || 0; + my $org = $self->_get_search_lib(); + my $depth = $self->cgi->param('depth') || $ctx->{get_aou}->($org)->ou_type->depth; my $copy_limit = int($self->cgi->param('copy_limit') || 10); my $copy_offset = int($self->cgi->param('copy_offset') || 0); 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 77cfb38ce3..7fa671d96e 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Search.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Search.pm @@ -97,7 +97,7 @@ sub _prepare_biblio_search { } my $site; - my $org = $cgi->param('loc'); + my $org = $ctx->{search_ou}; if (defined($org) and $org ne '' and ($org ne $ctx->{aou_tree}->()->id) and not $query =~ /site\(\S+\)/) { $site = $ctx->{get_aou}->($org)->shortname; $query .= " site($site)"; @@ -124,6 +124,8 @@ sub _prepare_biblio_search { $depth = $org->ou_type->depth; } $query .= " depth($depth)"; + } else { + $depth = $ctx->{get_aou}->($org)->ou_type->depth; } $logger->info("tpac: site=$site, depth=$depth, query=$query"); @@ -204,7 +206,7 @@ sub load_rresults { my $page = $cgi->param('page') || 0; my @facets = $cgi->param('facet'); my $limit = $self->_get_search_limit; - my $loc = $cgi->param('loc') || $ctx->{aou_tree}->()->id; + $ctx->{search_ou} = $self->_get_search_lib(); my $offset = $page * $limit; my $metarecord = $cgi->param('metarecord'); my $results; @@ -244,7 +246,7 @@ sub load_rresults { $results = $U->simplereq( 'open-ils.search', 'open-ils.search.biblio.metarecord_to_records', - $metarecord, {org => $loc, depth => $depth} + $metarecord, {org => $ctx->{search_ou}, depth => $depth} ); # force the metarecord result blob to match the format of regular search results @@ -348,10 +350,7 @@ sub check_1hit_redirect { } else { $sname = 'opac.patron.jump_to_details_on_single_hit'; - $org = ($ctx->{user}) ? - $ctx->{user}->home_ou : - $ctx->{physical_loc} || - $self->ctx->{aou_tree}->()->id; + $org = $self->_get_search_lib(); } return undef unless @@ -451,7 +450,7 @@ sub marc_expert_search { # loc, limit and offset my $page = $self->cgi->param("page") || 0; my $limit = $self->_get_search_limit; - my $org_unit = $self->cgi->param("loc") || $self->ctx->{aou_tree}->()->id; + $self->ctx->{search_ou} = $self->_get_search_lib(); my $offset = $page * $limit; $self->ctx->{records} = []; @@ -473,7 +472,7 @@ sub marc_expert_search { my $ses = OpenSRF::AppSession->create('open-ils.search'); my $req = $ses->request( 'open-ils.search.biblio.marc', - {searches => $query, org_unit => $org_unit}, + {searches => $query, org_unit => $self->ctx->{search_ou}}, $limit, $offset, $timeout); my $resp = $req->recv($timeout); 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 92cea9700b..5ea922f596 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm @@ -276,4 +276,30 @@ sub fetch_marc_xml_by_id { return $marc_xml; } +sub _get_search_lib { + my $self = shift; + + # loc param takes precedence + my $loc = $self->cgi->param('loc'); + return $loc if $loc; + + if ($self->ctx->{user}) { + # See if the user has a search library preference + my $lset = $self->editor->search_actor_user_setting({ + usr => $self->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; + } + + if ($self->cgi->param('physical_loc')) { + return $self->cgi->param('physical_loc'); + } + + return $self->ctx->{aou_tree}->()->id; +} + 1; diff --git a/Open-ILS/src/templates/opac/parts/advanced/search.tt2 b/Open-ILS/src/templates/opac/parts/advanced/search.tt2 index 378b9f6e3e..f14aaa8246 100644 --- a/Open-ILS/src/templates/opac/parts/advanced/search.tt2 +++ b/Open-ILS/src/templates/opac/parts/advanced/search.tt2 @@ -67,7 +67,7 @@ [% l("Search Library") %]
[% PROCESS "opac/parts/org_selector.tt2"; - PROCESS build_org_selector name='loc' value=CGI.param('loc') %] + PROCESS build_org_selector name='loc' value=ctx.search_ou %]
[%- INCLUDE "opac/parts/qtype_selector.tt2"; - l(' in '); PROCESS build_org_selector name='loc' value=CGI.param('loc'); + l(' in '); PROCESS build_org_selector name='loc' value=ctx.search_ou; %]