From af8567c87e8c67f32ce21eda2fa83428f561f78a Mon Sep 17 00:00:00 2001 From: erickson Date: Mon, 17 Jul 2006 13:52:28 +0000 Subject: [PATCH] adding file git-svn-id: svn://svn.open-ils.org/ILS/trunk@5037 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../OpenILS/Application/Search/CNBrowse.pm | 97 ++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 Open-ILS/src/perlmods/OpenILS/Application/Search/CNBrowse.pm diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Search/CNBrowse.pm b/Open-ILS/src/perlmods/OpenILS/Application/Search/CNBrowse.pm new file mode 100644 index 0000000000..0f2beb4c48 --- /dev/null +++ b/Open-ILS/src/perlmods/OpenILS/Application/Search/CNBrowse.pm @@ -0,0 +1,97 @@ +package OpenILS::Application::Search::CNBrowse; +use base qw/OpenSRF::Application/; +use strict; use warnings; + +use OpenSRF::EX qw(:try); +use OpenILS::Application::AppUtils; +use Data::Dumper; +use OpenSRF::Utils::Logger qw/:logger/; +use OpenSRF::AppSession; +my $U = "OpenILS::Application::AppUtils"; + + +__PACKAGE__->register_method( + method => "cn_browse_start", + api_name => "open-ils.search.callnumber.browse.target", + notes => "Starts a callnumber browse" + ); + +__PACKAGE__->register_method( + method => "cn_browse_up", + api_name => "open-ils.search.callnumber.browse.page_up", + notes => "Returns the previous page of callnumbers", + ); + +__PACKAGE__->register_method( + method => "cn_browse_down", + api_name => "open-ils.search.callnumber.browse.page_down", + notes => "Returns the next page of callnumbers", + ); + +# XXX Deprecate me + +sub cn_browse_start { + my( $self, $client, @params ) = @_; + my $method; + $method = 'open-ils.storage.asset.call_number.browse.target.atomic' + if( $self->api_name =~ /target/ ); + $method = 'open-ils.storage.asset.call_number.browse.page_up' + if( $self->api_name =~ /page_up/ ); + $method = 'open-ils.storage.asset.call_number.browse.page_down' + if( $self->api_name =~ /page_down/ ); + + return $U->simplereq( 'open-ils.storage', $method, @params ); +} + + + + +__PACKAGE__->register_method( + method => "cn_browse", + api_name => "open-ils.search.callnumber.browse", + notes => "Starts a callnumber browse" +); + +sub cn_browse { + my( $self, $conn, $cn, $orgid, $size, $offset ) = @_; + my $ses = OpenSRF::AppSession->create('open-ils.supercat'); + + my $tree = $U->get_slim_org_tree; + my $name = _find_shortname($orgid, $tree); + + $logger->debug("cn browse found or name $name"); + + my $data = $ses->request( + 'open-ils.supercat.call_number.browse', + $cn, $name, $size, $offset )->gather(1); + + return [] unless $data; + + my @res; + for my $d (@$data) { + my $mods = $U->record_to_mvr($d->record); + $d->owning_lib( $d->owning_lib->id ); + $d->record($mods->doc_id); + push( @res, { cn => $d, mods => $mods }); + } + + return \@res; +} + + +sub _find_shortname { + my $id = shift; + my $node = shift; + return undef unless $node; + return $node->shortname if $node->id == $id; + if( $node->children ) { + for my $c (@{$node->children()}) { + my $d = _find_shortname($id, $c); + return $d if $d; + } + } + return undef; +} + +1; + -- 2.11.0