From: Bill Erickson Date: Wed, 5 Sep 2018 20:02:56 +0000 (-0400) Subject: LP#1775466 Public API wrapper for mk_copy_query X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=6bcefced08f07d783b1d46bb4ee441ecde70df02;p=evergreen%2Fmasslnc.git LP#1775466 Public API wrapper for mk_copy_query Adds 2 new APIs: open-ils.search.bib.copies open-ils.search.bib.copies.staff Used by the in-progress Angular staff catalog. Signed-off-by: Bill Erickson Signed-off-by: Galen Charlton --- diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Search/Biblio.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Search/Biblio.pm index d0c6bc4c01..159ecd78b9 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Search/Biblio.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Search/Biblio.pm @@ -2663,6 +2663,86 @@ sub copies_by_cn_label { return [ map { ($U->is_true($_->location->opac_visible) && $U->is_true($_->status->opac_visible)) ? ($_->id) : () } @$copies ]; } +__PACKAGE__->register_method( + method => 'bib_copies', + api_name => 'open-ils.search.bib.copies', + stream => 1 +); +__PACKAGE__->register_method( + method => 'bib_copies', + api_name => 'open-ils.search.bib.copies.staff', + stream => 1 +); + +sub bib_copies { + my ($self, $client, $rec_id, $org, $depth, $limit, $offset, $pref_ou) = @_; + my $is_staff = ($self->api_name =~ /staff/); + + my $cstore = OpenSRF::AppSession->create('open-ils.cstore'); + my $req = $cstore->request( + 'open-ils.cstore.json_query', mk_copy_query( + $rec_id, $org, $depth, $limit, $offset, $pref_ou, $is_staff)); + + my $resp; + while ($resp = $req->recv) { + $client->respond($resp->content); + } + + return undef; +} + +# TODO: this comes almost directly from WWW/EGCatLoader/Record.pm +# Refactor to share +sub mk_copy_query { + my $rec_id = shift; + my $org = shift; + my $depth = shift; + my $copy_limit = shift; + my $copy_offset = shift; + my $pref_ou = shift; + my $is_staff = shift; + + my $query = $U->basic_opac_copy_query( + $rec_id, undef, undef, $copy_limit, $copy_offset, $is_staff + ); + + if ($org) { # TODO: root org test + # no need to add the org join filter if we're not actually filtering + $query->{from}->{acp}->[1] = { aou => { + fkey => 'circ_lib', + field => 'id', + filter => { + id => { + in => { + select => {aou => [{ + column => 'id', + transform => 'actor.org_unit_descendants', + result_field => 'id', + params => [$depth] + }]}, + from => 'aou', + where => {id => $org} + } + } + } + }}; + }; + + # Unsure if we want these in the shared function, leaving here for now + unshift(@{$query->{order_by}}, + { class => "aou", field => 'id', + transform => 'evergreen.rank_ou', params => [$org, $pref_ou] + } + ); + push(@{$query->{order_by}}, + { class => "acp", field => 'id', + transform => 'evergreen.rank_cp' + } + ); + + return $query; +} + 1;