adding file
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Mon, 17 Jul 2006 13:52:28 +0000 (13:52 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Mon, 17 Jul 2006 13:52:28 +0000 (13:52 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@5037 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/perlmods/OpenILS/Application/Search/CNBrowse.pm [new file with mode: 0644]

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 (file)
index 0000000..0f2beb4
--- /dev/null
@@ -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;
+