If there's no sort org unit, just fall back to the usual sorting
authorLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Thu, 28 Jul 2011 20:59:59 +0000 (16:59 -0400)
committerLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Thu, 28 Jul 2011 20:59:59 +0000 (16:59 -0400)
Signed-off-by: Lebbeous Fogle-Weekley <lebbeous@esilibrary.com>

Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Record.pm

index f3391dd..dbfad54 100644 (file)
@@ -78,12 +78,6 @@ sub mk_copy_query {
     my $copy_limit = shift;
     my $copy_offset = shift;
 
-    # XXX In the future, $sort_org should be understood to be an abstration
-    # that refers to something configurable, not necessariyl orig_loc.
-
-    my $sort_org = $self->ctx->{orig_loc} || $org ||
-        $self->ctx->{aou_tree}->()->id;
-
     my $query = {
         select => {
             acp => ['id', 'barcode', 'circ_lib', 'create_date', 'age_protect', 'holdable'],
@@ -139,8 +133,6 @@ sub mk_copy_query {
 
         # Order is: copies with circ_lib=org, followed by circ_lib name, followed by call_number label
         order_by => [
-            {class => 'acp', field => 'circ_lib', transform => 'numeric_eq',
-                params => [$sort_org], direction => 'desc'},
             {class => 'aou', field => 'name'}, 
             {class => 'acn', field => 'label'}
         ],
@@ -149,6 +141,16 @@ 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 orig_loc.
+
+    if (my $sort_org = $self->ctx->{orig_loc}) {
+        unshift @{$query->{order_by}}, {
+            class => 'acp', field => 'circ_lib', transform => 'numeric_eq',
+            params => [$sort_org], direction => 'desc'
+        };
+    }
+
     # Filter hidden items if this is the public catalog
     unless($self->ctx->{is_staff}) { 
         $query->{where}->{'+acp'}->{opac_visible} = 't';