LP#1053397 collectin MR hold filter bits into API calls
authorBill Erickson <berick@esilibrary.com>
Fri, 31 Jan 2014 20:23:32 +0000 (15:23 -0500)
committerBill Erickson <berick@esilibrary.com>
Fri, 31 Jan 2014 20:23:32 +0000 (15:23 -0500)
Signed-off-by: Bill Erickson <berick@esilibrary.com>
Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Holds.pm

index 6e3b31f..ca0859d 100644 (file)
@@ -4200,4 +4200,98 @@ sub calculate_expire_time
     return undef;
 }
 
+
+__PACKAGE__->register_method(
+    method    => 'mr_hold_filter_attrs',
+    api_name  => 'open-ils.circ.mmr.holds.filters',
+    authoritative => 1,
+    stream => 1,
+    signature => {
+        desc => q/
+            Returns the set of available formats and languages for the
+            constituent records of the provided metarcord.
+            If an array of hold IDs is also provided, information about
+            each is returned as well.  This information includes:
+            1. a slightly easier to read version of holdable_formats
+            2. attributes describing the set of format icons included
+               in the set of desired, constituent records.
+        /,
+        params => [
+            {desc => 'Metarecord ID', type => 'number'},
+            {desc => 'Hold ID List', type => 'array'},
+        ],
+        return => {
+            desc => q/
+                Stream of objects.  The first will have a 'metarecord' key
+                containing non-hold-specific metarecord information, subsequent
+                responses will contain a 'hold' key containing hold-specific
+                information
+            /, 
+            type => 'object'
+        }
+    }
+);
+
+sub mr_hold_filter_attrs {
+    my ($self, $client, $mr_id, $hold_ids) = @_;
+    my $e = new_editor();
+
+    my $mr = $e->retrieve_metabib_metarecord($mr_id) or return $e->event;
+    my $bre_ids = $e->json_query({
+        select => {mmrsm => ['source']},
+        from => 'mmrsm',
+        where => {'+mmrsm' => {metarecord => $mr_id}}
+    });
+    $bre_ids = [map {$_->{source}} @$bre_ids];
+
+    my $format_attr = $e->retrieve_config_global_flag(
+        'opac.metarecord.holds.format_attr')->value;
+
+    # helper sub for fetching ccvms for a batch of record IDs
+    sub get_batch_ccvms {
+        my ($e, $attr, $bre_ids) = @_;
+        my $vals = $e->search_metabib_record_attr_flat({
+            attr => $attr,
+            id => $bre_ids
+        });
+        return [] unless @$vals;
+        return $e->search_config_coded_value_map({
+            ctype => $attr,
+            code => [map {$_->value} @$vals]
+        });
+    }
+
+    my $langs = get_batch_ccvms($e, 'item_lang', $bre_ids);
+    my $formats = get_batch_ccvms($e, $format_attr, $bre_ids);
+
+    $client->respond({
+        metarecord => {
+            id => $mr_id,
+            formats => $formats,
+            langs => $langs
+        }
+    });
+
+    return unless $hold_ids;
+    my $icon_attr = $e->retrieve_config_global_flag('opac.icon_attr')->value;
+
+    for my $hold_id (@$hold_ids) {
+        my $hold = $e->retrieve_action_hold_request($hold_id) 
+            or return $e->event;
+
+        next unless $hold->hold_type eq 'M';
+
+        # find all of the bib records within this metarcord whose 
+        # format / language match the holdable formats on the hold
+        my @bre_ids = $self->method_lookup(
+            'open-ils.circ.holds.metarecord.filterd_records')->run(
+                $hold->target, $hold->holdable_formats);
+
+        my $icons = get_batch_ccvms($e, $icon_attr, \@bre_ids);
+        $client->respond({hold => {id => $hold_id, icons => $icons}});
+    }
+
+    return;
+}
+
 1;