TPAC: Teach record details how to sort by preferred library
authorDan Scott <dan@coffeecode.net>
Sun, 11 Mar 2012 03:05:36 +0000 (22:05 -0500)
committerDan Scott <dan@coffeecode.net>
Thu, 15 Mar 2012 04:34:32 +0000 (00:34 -0400)
Using the same _get_pref_lib() function to grab our preferred library,
replace the order_by clause in mk_copy_query() with the
evergreen.rank_ou() routine. Copies in record details display now sort
in the same library order as in search results.

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

index 2daaf2f..476d539 100644 (file)
@@ -15,6 +15,7 @@ sub load_record {
     $ctx->{page} = 'record';  
 
     my $org = $self->_get_search_lib();
+    my $pref_ou = $self->_get_pref_lib();
     my $depth = $self->cgi->param('depth');
     $depth = $ctx->{get_aou}->($org)->ou_type->depth 
         unless defined $depth; # can be 0
@@ -41,7 +42,7 @@ sub load_record {
     my $cstore = OpenSRF::AppSession->create('open-ils.cstore');
     my $copy_rec = $cstore->request(
         'open-ils.cstore.json_query.atomic', 
-        $self->mk_copy_query($rec_id, $org, $copy_depth, $copy_limit, $copy_offset)
+        $self->mk_copy_query($rec_id, $org, $copy_depth, $copy_limit, $copy_offset, $pref_ou)
     );
 
     my (undef, @rec_data) = $self->get_records_and_facets([$rec_id], undef, {flesh => '{holdings_xml,bmp,mra,acp,acnp,acns}'});
@@ -143,6 +144,7 @@ sub mk_copy_query {
     my $depth = shift;
     my $copy_limit = shift;
     my $copy_offset = shift;
+    my $pref_ou = shift;
 
     my $query = {
         select => {
@@ -203,6 +205,9 @@ sub mk_copy_query {
         },
 
         order_by => [
+            { class => "aou", field => 'id', 
+              transform => 'evergreen.rank_ou', params => [$pref_ou, $org]
+            },
             {class => 'aou', field => 'name'}, 
             {class => 'acn', field => 'label'}
         ],
@@ -211,16 +216,6 @@ sub mk_copy_query {
         offset => $copy_offset
     };
 
-    # XXX In the future, $sort_org should be understood to be an abstration
-    # that refers to something configurable, not necessariyl physical_loc.
-
-    if (my $sort_org = $self->ctx->{physical_loc}) {
-        unshift @{$query->{order_by}}, {
-            class => 'acp', field => 'circ_lib', transform => 'numeric_eq',
-            params => [$sort_org], direction => 'desc'
-        };
-    }
-
     if($org != $self->ctx->{aou_tree}->()->id) { 
         # no need to add the org join filter if we're not actually filtering
         $query->{from}->{acp}->{aou} = {