From 932771970016270b6516946b92e1703b998fdc71 Mon Sep 17 00:00:00 2001 From: miker Date: Tue, 6 Jun 2006 02:54:08 +0000 Subject: [PATCH] adding holdings data to marcxml/htmlcard output git-svn-id: svn://svn.open-ils.org/ILS/trunk@4513 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../perlmods/OpenILS/Application/SuperCat.pm | 122 +++++++++++++++--- Open-ILS/src/perlmods/OpenILS/WWW/SuperCat.pm | 22 +++- .../src/perlmods/OpenILS/WWW/SuperCat/Feed.pm | 19 +++ Open-ILS/xsl/MARC21slim2HTMLCard.xsl | 40 +++++- 4 files changed, 175 insertions(+), 28 deletions(-) diff --git a/Open-ILS/src/perlmods/OpenILS/Application/SuperCat.pm b/Open-ILS/src/perlmods/OpenILS/Application/SuperCat.pm index becceb3ff1..b85aaa0596 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/SuperCat.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/SuperCat.pm @@ -168,6 +168,107 @@ sub entityize { return $stuff; } +sub new_record_holdings { + my $self = shift; + my $client = shift; + my $bib = shift; + my $ou = shift; + + my $_storage = OpenSRF::AppSession->create( 'open-ils.storage' ); + my $_cstore = OpenSRF::AppSession->create( 'open-ils.cstore' ); + + my $tree = $_cstore->request( + "open-ils.cstore.direct.biblio.record_entry.retrieve", + $bib, + {flesh => 3, flesh_fields => [qw/call_numbers copies location status owning_lib circ_lib/] } + )->gather(1); + + my ($year,$month,$day) = reverse( (localtime)[3,4,5] ); + $year += 1900; + $month += 1; + + my $xml = ""; + + for my $cn (@{$tree->call_numbers}) { + + if ($ou ne '-') { + next unless grep {$_->circ_lib->shortname =~ /^$ou/} @{$cn->copies}; + } + + (my $cn_class = $cn->class_name) =~ s/::/-/gso; + $cn_class =~ s/Fieldmapper-//gso; + my $cn_tag = sprintf("tag:open-ils.org,$year-\%0.2d-\%0.2d:$cn_class/".$cn->id, $month, $day); + + my $cn_lib = $cn->owning_lib->shortname; + + my $cn_label = $cn->label; + + $xml .= ""; + + for my $cp (@{$cn->copies}) { + + if ($ou ne '-') { + next unless $cp->circ_lib->shortname =~ /^$ou/; + } + + (my $cp_class = $cp->class_name) =~ s/::/-/gso; + $cp_class =~ s/Fieldmapper-//gso; + my $cp_tag = sprintf("tag:open-ils.org,$year-\%0.2d-\%0.2d:$cp_class/".$cp->id, $month, $day); + + my $cp_stat = $cp->status->name; + + my $cp_loc = $cp->location->name; + + my $cp_lib = $cp->circ_lib->shortname; + + my $cp_bc = $cp->barcode; + + $xml .= "$cp_stat$cp_loc$cp_lib"; + + #for my $note ( @{$_storage->request( "open-ils.storage.direct.asset.copy_note.search.atomic" => {id => $cp->id, pub => "t" })->gather(1)} ) { + # $xml .= sprintf('%s',$note->create_date, escape($note->title), escape($note->value)); + #} + + $xml .= ""; + + #for my $sce ( @{$_storage->request( "open-ils.storage.direct.asset.stat_cat_entry_copy_map.search.atomic" => { owning_copy => $cp->id })->gather(1)} ) { + # my $sc = $holdings_data_cache{statcat}{$sce->stat_cat_entry}; + # $xml .= sprintf('%s',escape($sc->value)); + #} + + $xml .= ""; + } + + $xml .= ""; + } + + $xml .= ""; + + return $xml; +} +__PACKAGE__->register_method( + method => 'new_record_holdings', + api_name => 'open-ils.supercat.record.holdings_xml.retrieve', + api_level => 1, + argc => 1, + signature => + { desc => <<" DESC", +Returns the XML representation of the requested bibliographic record's holdings + DESC + params => + [ + { name => 'bibId', + desc => 'An OpenILS biblio::record_entry id', + type => 'number' }, + ], + 'return' => + { desc => 'The bib record holdings hierarchy in XML', + type => 'string' } + } +); + + + sub record_holdings { my $self = shift; my $client = shift; @@ -246,27 +347,6 @@ sub record_holdings { return $xml; } -__PACKAGE__->register_method( - method => 'record_holdings', - api_name => 'open-ils.supercat.record.holdings_xml.retrieve', - api_level => 1, - argc => 1, - signature => - { desc => <<" DESC", -Returns the XML representation of the requested bibliographic record's holdings - DESC - params => - [ - { name => 'bibId', - desc => 'An OpenILS biblio::record_entry id', - type => 'number' }, - ], - 'return' => - { desc => 'The bib record holdings hierarchy in XML', - type => 'string' } - } -); - sub escape { my $text = shift; diff --git a/Open-ILS/src/perlmods/OpenILS/WWW/SuperCat.pm b/Open-ILS/src/perlmods/OpenILS/WWW/SuperCat.pm index b1fbdffdb7..82840ea166 100644 --- a/Open-ILS/src/perlmods/OpenILS/WWW/SuperCat.pm +++ b/Open-ILS/src/perlmods/OpenILS/WWW/SuperCat.pm @@ -93,13 +93,14 @@ sub unapi { my $host = $cgi->virtual_host || $cgi->server_name; my $format = $cgi->param('format'); - my ($id,$type,$command) = ('','',''); + my ($id,$type,$command,$lib) = ('','',''); if (!$format) { print "Content-type: application/xml; charset=utf-8\n"; if ($uri =~ m{^tag:[^:]+:([^\/]+)/(\d+)}o) { $id = $2; + $lib = $3; $type = 'record'; $type = 'metarecord' if ($1 =~ /^m/o); @@ -163,8 +164,9 @@ sub unapi { } - if ($uri =~ m{^tag:[^:]+:([^\/]+)/(\d+)}o) { + if ($uri =~ m{^tag:[^:]+:([^\/]+)/(\d+)(?:/(.+))?}o) { $id = $2; + $lib = $3; $type = 'record'; $type = 'metarecord' if ($1 =~ /^m/o); $command = 'retrieve'; @@ -176,10 +178,12 @@ sub unapi { print "Location: $root/../../en-US/skin/default/xml/rdetail.xml?r=$id\n\n" if ($type eq 'record'); return 302; - } elsif ($format =~ /^html/o) { + } else { + #} elsif ($format =~ /^html/o) { my $feed = create_record_feed( $format => [ $id ], $base, + $lib, ); $feed->root($root); @@ -663,6 +667,7 @@ sub opensearch_feed { $type, [ map { $_->[0] } @{$recs->{ids}}[$offset .. $offset + $limit - 1] ], $unapi, + $org ); $feed->root($root); $feed->lib($org); @@ -743,6 +748,8 @@ sub create_record_feed { my $records = shift; my $unapi = shift; + my $lib = shift || ''; + my $cgi = new CGI; my $base = $cgi->url; my $host = $cgi->virtual_host || $cgi->server_name; @@ -759,7 +766,7 @@ sub create_record_feed { for my $rec (@$records) { next unless($rec); - my $item_tag = "tag:$host,$year:biblio-record_entry/" . $rec; + my $item_tag = "tag:$host,$year:biblio-record_entry/$rec/$lib"; my $xml = $supercat->request( @@ -769,8 +776,13 @@ sub create_record_feed { my $node = $feed->add_item($xml); + if ($lib && $type eq 'marcxml') { + $xml = $supercat->request( "open-ils.supercat.record.holdings_xml.retrieve", $rec, $lib )->gather(1); + $node->add_holdings($xml); + } + $node->id($item_tag); - $node->link(alternate => $feed->unapi . "?id=$item_tag&format=opac" => 'text/html'); + $node->link(alternate => $feed->unapi . "?id=$item_tag&format=htmlcard" => 'text/html'); $node->link(opac => $feed->unapi . "?id=$item_tag&format=opac"); $node->link(unapi => $feed->unapi . "?id=$item_tag"); $node->link('unapi-id' => $item_tag); diff --git a/Open-ILS/src/perlmods/OpenILS/WWW/SuperCat/Feed.pm b/Open-ILS/src/perlmods/OpenILS/WWW/SuperCat/Feed.pm index 80a3aba8e7..ffd86db9e2 100644 --- a/Open-ILS/src/perlmods/OpenILS/WWW/SuperCat/Feed.pm +++ b/Open-ILS/src/perlmods/OpenILS/WWW/SuperCat/Feed.pm @@ -136,6 +136,20 @@ sub add_item { return $entry; } +sub add_holdings { + my $self = shift; + my $holdings_xml = shift; + + $parser = new XML::LibXML if (!$parser); + my $new_doc = $parser->parse_string($holdings_xml); + + for my $root ( $self->{doc}->findnodes($self->{holdings_xpath}) ) { + $root->appendChild($new_doc->documentElement); + last; + } + return $self; +} + sub composeDoc { my $self = shift; for my $root ( $self->{doc}->findnodes($self->{item_xpath}) ) { @@ -228,6 +242,7 @@ sub new { my $self = $class->SUPER::build($xml); $self->{doc}->documentElement->setNamespace('http://www.w3.org/2005/Atom', 'atom'); $self->{item_xpath} = '/atom:entry'; + $self->{holdings_xpath} = '/atom:entry'; $self->{type} = 'application/xml'; return $self; } @@ -292,6 +307,7 @@ sub new { my $self = $class->SUPER::build($xml); $self->{type} = 'application/xml'; $self->{item_xpath} = '/item'; + $self->{holdings_xpath} = '/item'; return $self; } @@ -318,6 +334,7 @@ sub new { my $self = $class->SUPER::build($xml); $self->{doc}->documentElement->setNamespace('http://www.loc.gov/mods/', 'mods'); $self->{type} = 'application/xml'; + $self->{holdings_xpath} = '/mods:mods'; return $self; } @@ -369,6 +386,7 @@ sub new { my $self = $class->SUPER::build($xml); $self->{doc}->documentElement->setNamespace('http://www.loc.gov/mods/v3', 'mods'); $self->{type} = 'application/xml'; + $self->{holdings_xpath} = '/mods:mods'; return $self; } @@ -395,6 +413,7 @@ sub new { my $self = $class->SUPER::build($xml); $self->{doc}->documentElement->setNamespace('http://www.loc.gov/MARC21/slim', 'marc'); $self->{type} = 'application/xml'; + $self->{holdings_xpath} = '/marc:record'; return $self; } diff --git a/Open-ILS/xsl/MARC21slim2HTMLCard.xsl b/Open-ILS/xsl/MARC21slim2HTMLCard.xsl index 4bcb087a43..5ac8c4c4e3 100755 --- a/Open-ILS/xsl/MARC21slim2HTMLCard.xsl +++ b/Open-ILS/xsl/MARC21slim2HTMLCard.xsl @@ -3,7 +3,8 @@ @@ -27,8 +28,43 @@
+ Holdings + +
- + + +
    + + + +
+
+ + +
  • + +
  • +
    + + +
      + + + +
    +
    + + +
  • +
      +
    • Circulating from
    • +
    • Located at
    • +
    • Status is
    • +
    +
  • +
    + # -- 2.43.2