TPAC: Add preferred library to search result ordering
authorDan Scott <dan@coffeecode.net>
Sun, 11 Mar 2012 02:14:15 +0000 (21:14 -0500)
committerDan Scott <dan@coffeecode.net>
Sat, 17 Mar 2012 18:24:38 +0000 (14:24 -0400)
Now that unapi.bre/unapi.holdings_xml has learned how to order copies by
ranked library, teach TPAC how to tell unapi what the preferred library
is. We do this by parsing the preferred search library separately from
the scoped search library, as follows (1st match wins):

1) A new GET param, "plib", specifying the number of the OU
2) User's library preference setting;
3) User's home OU;
4) Physical location in which the search is being issued

Signed-off-by: Dan Scott <dan@coffeecode.net>
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Search.pm
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm

index ecf8ef0..d96bbca 100644 (file)
@@ -279,6 +279,7 @@ sub load_rresults {
     my @facets = $cgi->param('facet');
     my $limit = $self->_get_search_limit;
     $ctx->{search_ou} = $self->_get_search_lib();
+    $ctx->{pref_ou} = $self->_get_pref_lib() || $ctx->{search_ou};
     my $offset = $page * $limit;
     my $metarecord = $cgi->param('metarecord');
     my $results; 
@@ -375,7 +376,8 @@ sub load_rresults {
         {
             flesh => '{holdings_xml,mra,acp,acnp,acns,bmp}',
             site => $site,
-            depth => $depth
+            depth => $depth,
+            pref_lib => $ctx->{pref_ou},
         }
     );
 
@@ -525,6 +527,7 @@ sub marc_expert_search {
     my $page = $self->cgi->param("page") || 0;
     my $limit = $self->_get_search_limit;
     $self->ctx->{search_ou} = $self->_get_search_lib();
+    $self->ctx->{pref_ou} = $self->_get_pref_lib();
     my $offset = $page * $limit;
 
     $self->ctx->{records} = [];
@@ -572,7 +575,10 @@ sub marc_expert_search {
     }
 
     my ($facets, @data) = $self->get_records_and_facets(
-        $self->ctx->{ids}, undef, {flesh => "{holdings_xml,mra,acnp,acns}"}
+        $self->ctx->{ids}, undef, {
+            flesh => "{holdings_xml,mra,acnp,acns}",
+            pref_lib => $self->ctx->{pref_ou},
+        }
     );
 
     $self->ctx->{records} = [@data];
index 6692387..5aced5b 100644 (file)
@@ -210,6 +210,7 @@ sub get_records_and_facets {
             $unapi_args->{site}, 
             $unapi_args->{depth}, 
             'acn=>' . $unapi_args->{flesh_depth} . ',acp=>' . $unapi_args->{flesh_depth}, 
+            undef, undef, $unapi_args->{pref_lib}
         ]}
     ) for @$rec_ids;
 
@@ -292,6 +293,20 @@ sub _get_search_lib {
     $loc = $self->cgi->param('loc');
     return $loc if $loc;
 
+    my $pref_lib = $self->_get_pref_lib();
+    return $pref_lib if $pref_lib;
+
+    return $ctx->{aou_tree}->()->id;
+}
+
+sub _get_pref_lib {
+    my $self = shift;
+    my $ctx = $self->ctx;
+
+    # plib param takes precedence
+    my $plib = $self->cgi->param('plib');
+    return $plib if $plib;
+
     if ($ctx->{user}) {
         # See if the user has a search library preference
         my $lset = $self->editor->search_actor_user_setting({
@@ -308,7 +323,6 @@ sub _get_search_lib {
         return $self->cgi->param('physical_loc');
     }
 
-    return $ctx->{aou_tree}->()->id;
 }
 
 # This is defensively coded since we don't do much manual reading from the