LP#1596595 Holdable formats filtering for metarecord holds
authorBill Erickson <berickxx@gmail.com>
Wed, 29 Jun 2016 21:22:00 +0000 (17:22 -0400)
committerBill Erickson <berickxx@gmail.com>
Fri, 26 Aug 2016 21:32:17 +0000 (17:32 -0400)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/perlmods/lib/OpenILS/Utils/HoldTargeter.pm

index d80c041..e55e276 100644 (file)
@@ -467,8 +467,6 @@ sub get_hold_copies {
     unless ($hold_type eq 'C' || $hold_type eq 'I' || $hold_type eq 'P') {
         # For volume and higher level holds, avoid targeting copies that
         # act as instances of monograph parts.
-        # TODO: Should this include 'R' holds?  The original hold
-        # targeter does not include them either.
         $query->{from}->{acp}->{acpm} = {
             type => 'left',
             field => 'target_copy',
@@ -535,6 +533,29 @@ sub get_hold_copies {
                 }
             }
         };
+
+        if ($hold->holdable_formats) {
+            # Compile the JSON-encoded metarecord holdable formats
+            # to an Intarray query_int string.
+            my $query_int = $e->json_query({
+                from => [
+                    'metabib.compile_composite_attr',
+                    $hold->holdable_formats
+                ]
+            })->[0];
+            # TODO: ^- any way to add this as a filter in the main query?
+
+            if ($query_int) {
+                # Only pull potential copies from records that satisfy
+                # the holdable formats query.
+                my $qint = $query_int->{'metabib.compile_composite_attr'};
+                $query->{from}->{acp}->{acn}->{join}->{bre}->{join}->{mravl} = {
+                    field  => 'source',
+                    fkey   => 'id',
+                    filter => {vlist => {'@@' => $qint}}
+                }
+            }
+        }
     }
 
     my $copies = $e->json_query($query);