tpac: sort copies by physical loc when searching parent
authorBill Erickson <berick@esilibrary.com>
Mon, 18 Jun 2012 14:16:39 +0000 (10:16 -0400)
committerJason Stephenson <jason@sigio.com>
Wed, 30 Jan 2013 20:11:47 +0000 (15:11 -0500)
If a physical location is set and it is a child of the current search
location, sort copies living at the physical location to the top of the
copy grid in the record detail page.

Signed-off-by: Bill Erickson <berick@esilibrary.com>
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Record.pm

index a4af2c6..7cef318 100644 (file)
@@ -225,6 +225,26 @@ sub mk_copy_query {
         }
     );
 
+
+    # If a physical location is set and is a child of the search location,
+    # sort copies living at the physical location to the front.
+    if (my $phys_loc = $self->ctx->{physical_loc}) {
+
+        my $ou = $self->ctx->{get_aou}->($phys_loc);
+        $ou = $ou->parent_ou;
+
+        while ($ou) {
+            if ($org == $ou) {
+                unshift @{$query->{order_by}}, {
+                    class => 'acp', field => 'circ_lib', transform => 'numeric_eq',
+                    params => [$phys_loc], direction => 'desc'
+                };
+                last;
+            }
+            $ou = $self->ctx->{get_aou}->($ou)->parent_ou;
+        }
+    }
+
     return $query;
 }