From 866c3dd616202ad198276ea654388bb2fd7189f3 Mon Sep 17 00:00:00 2001 From: Joshua Ferraro Date: Sun, 18 Nov 2007 11:05:59 -0600 Subject: [PATCH] adding endnote export and 'related items' Signed-off-by: Chris Cormack Signed-off-by: Joshua Ferraro --- C4/Record.pm | 37 ++++++++++ C4/XISBN.pm | 6 +- catalogue/detail.pl | 52 +++++++++++++- catalogue/export.pl | 6 +- .../data/mysql/en/mandatory/sysprefs.sql | 1 + .../prog/en/modules/catalogue/detail.tmpl | 71 ++++++++++++++++--- 6 files changed, 157 insertions(+), 16 deletions(-) diff --git a/C4/Record.pm b/C4/Record.pm index 0a740864b3..7751bc09b9 100644 --- a/C4/Record.pm +++ b/C4/Record.pm @@ -25,6 +25,7 @@ use strict;# use warnings; #FIXME: turn off warnings before release use MARC::Record; # marc2marcxml, marcxml2marc, html2marc, changeEncoding use MARC::File::XML; # marc2marcxml, marcxml2marc, html2marcxml, changeEncoding use MARC::Crosswalk::DublinCore; # marc2dcxml +use Biblio::EndnoteStyle; use Unicode::Normalize; # _entity_encode use XML::LibXSLT; use XML::LibXML; @@ -39,6 +40,7 @@ $VERSION = 3.00; # only export API methods @EXPORT = qw( + &marc2endnote &marc2marc &marc2marcxml &marcxml2marc @@ -286,6 +288,41 @@ sub marc2modsxml { my $newxmlrecord = $stylesheet->output_string($results); return ($newxmlrecord); } + +sub marc2endnote { + my ($marc) = @_; + my $marc_rec_obj = MARC::Record->new_from_usmarc($marc); + my $f260 = $marc_rec_obj->field('260'); + my $f260a = $f260->subfield('a') if $f260; + my $f710 = $marc_rec_obj->field('710'); + my $f710a = $f710->subfield('a') if $f710; + my $f500 = $marc_rec_obj->field('500'); + my $abstract = $f500->subfield('a') if $f500; + my $fields = { + DB => C4::Context->preference("LibraryName"), + Title => $marc_rec_obj->title(), + Author => $marc_rec_obj->author(), + Publisher => $f710a, + City => $f260a, + Year => $marc_rec_obj->publication_date, + Abstract => $abstract, + }; + my $endnote; + my $style = new Biblio::EndnoteStyle(); + my $template; + $template.= "DB - DB\n" if C4::Context->preference("LibraryName"); + $template.="T1 - Title\n" if $marc_rec_obj->title(); + $template.="A1 - Author\n" if $marc_rec_obj->author(); + $template.="PB - Publisher\n" if $f710a; + $template.="CY - City\n" if $f260a; + $template.="Y1 - Year\n" if $marc_rec_obj->publication_date; + $template.="AB - Abstract\n" if $abstract; + my ($text, $errmsg) = $style->format($template, $fields); + return ($text); + +} + + =head2 html2marcxml =over 4 diff --git a/C4/XISBN.pm b/C4/XISBN.pm index 7d0c916dce..ab934a1e28 100755 --- a/C4/XISBN.pm +++ b/C4/XISBN.pm @@ -47,11 +47,11 @@ This module provides facilities for retrieving XISBN, ThingISBN and XISBN conten ); sub get_biblio_from_xisbn { - my $xisbn_data = shift; + my $xisbn = shift; my $dbh = C4::Context->dbh; my $query = "SELECT biblionumber FROM biblioitems WHERE isbn=?"; my $sth = $dbh->prepare($query); - $sth->execute($xisbn_data->{content}); + $sth->execute($xisbn); my $xbib_data = $sth->fetchrow_hashref(); my $xbiblio; if ($xbib_data->{biblionumber}) { @@ -101,7 +101,7 @@ sub get_xisbns { for my $response_data( @{ $response->{ isbn } } ) { next if $unique_xisbns->{ $response_data->{content} }; $unique_xisbns->{ $response_data->{content} }++; - my $xbiblio= get_biblio_from_xisbn($response_data); + my $xbiblio= get_biblio_from_xisbn($response_data->{content}); push @xisbns, $xbiblio if $xbiblio; #response_data->{xbiblio}; #->{biblionumber}; # if $xbiblionumber; } diff --git a/catalogue/detail.pl b/catalogue/detail.pl index d41d090671..f0815b5206 100755 --- a/catalogue/detail.pl +++ b/catalogue/detail.pl @@ -24,7 +24,8 @@ use C4::Serials; #uses getsubscriptionfrom biblionumber use C4::Output; use C4::Biblio; use C4::Serials; -use C4::XISBN qw(get_xisbns); +use C4::XISBN qw(get_xisbns get_biblio_from_xisbn); +use C4::Amazon; my $query = new CGI; my ( $template, $borrowernumber, $cookie ) = get_template_and_user( @@ -103,10 +104,11 @@ $template->param( ); # XISBN Stuff +my $xisbn=$dat->{'isbn'}; +$xisbn =~ s/(p|-| |:)//g; +$template->param(amazonisbn => $xisbn); if (C4::Context->preference("FRBRizeEditions")==1) { eval { - my $xisbn=$dat->{'isbn'}; - $xisbn =~ s/(p|-|:| )//g; $template->param( xisbn => $xisbn, XISBNS => get_xisbns($xisbn) @@ -114,5 +116,49 @@ if (C4::Context->preference("FRBRizeEditions")==1) { }; if ($@) { warn "XISBN Failed $@"; } } +if ( C4::Context->preference("AmazonContent") == 1 ) { + my $amazon_details = &get_amazon_details( $xisbn ); + foreach my $result ( @{ $amazon_details->{Details} } ) { + $template->param( item_description => $result->{ProductDescription} ); + $template->param( image => $result->{ImageUrlMedium} ); + $template->param( list_price => $result->{ListPrice} ); + $template->param( amazon_url => $result->{url} ); + } + + my @products; + my @reviews; + for my $details ( @{ $amazon_details->{Details} } ) { + next unless $details->{SimilarProducts}; + for my $product ( @{ $details->{SimilarProducts}->{Product} } ) { + if (C4::Context->preference("AmazonSimilarItems") ) { + my $xbiblios; + my @xisbns; + + if (C4::Context->preference("XISBNAmazonSimilarItems") ) { + my $xbiblio = get_biblio_from_xisbn($product); + push @xisbns, $xbiblio; + $xbiblios = \@xisbns; + } + else { + $xbiblios = get_xisbns($product); + } + push @products, +{ product => $xbiblios }; + } + } + next unless $details->{Reviews}; + for my $product ( @{ $details->{Reviews}->{AvgCustomerRating} } ) { + $template->param( rating => $product * 20 ); + } + for my $reviews ( @{ $details->{Reviews}->{CustomerReview} } ) { + push @reviews, + +{ + summary => $reviews->{Summary}, + comment => $reviews->{Comment}, + }; + } + } + $template->param( SIMILAR_PRODUCTS => \@products ); + $template->param( AMAZONREVIEWS => \@reviews ); +} output_html_with_http_headers $query, $cookie, $template->output; diff --git a/catalogue/export.pl b/catalogue/export.pl index a6b7cb0e96..11ec6d51c0 100755 --- a/catalogue/export.pl +++ b/catalogue/export.pl @@ -23,7 +23,11 @@ if ($op eq "export") { while (my ($marc) = $sth->fetchrow) { if ($marc){ - if ($format =~ /marcxml/) { + if ($format =~ /endnote/) { + $marc = marc2endnote($marc); + $format = 'endnote'; + } + elsif ($format =~ /marcxml/) { $marc = marc2marcxml($marc); } elsif ($format=~ /mods/) { diff --git a/installer/data/mysql/en/mandatory/sysprefs.sql b/installer/data/mysql/en/mandatory/sysprefs.sql index 4d86ed2251..b7d807c90d 100644 --- a/installer/data/mysql/en/mandatory/sysprefs.sql +++ b/installer/data/mysql/en/mandatory/sysprefs.sql @@ -1,6 +1,7 @@ INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('acquisitions','normal','Choose Normal, budget-based acquisitions, or Simple bibliographic-data acquisitions','simple|normal','Choice'); INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('advancedMARCeditor','0','If ON, the MARC editor won\'t display field/subfield descriptions','','YesNo'); INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('AmazonContent','0','Turn ON Amazon Content - You MUST set AmazonDevKey and AmazonAssocTag if enabled','','YesNo'); +INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('AmazonSimilarItems','0','Turn ON Amazon Similar Items feature - You MUST set AmazonDevKey and AmazonAssocTag if enabled','','YesNo'); INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('AmazonDevKey','','See: aws-portal.amazon.com/gp/aws/developer/registration/index.html','','free'); INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('AmazonAssocTag','','See: associates.amazon.com/gp/flex/associates/apply-login.html','','free'); INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('AnonSuggestions','0','Set to anonymous borrowernumber to enable Anonymous suggestions',NULL,'free'); diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tmpl index 6949508691..a15030b6c6 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tmpl +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tmpl @@ -68,12 +68,12 @@ - - - + + /ref=sib_dp_pt/002-7879865-0184864#reader-link">.01._PIdp-schmooS,TopRight,7,-26_SCMZZZZZZZ_.jpg" alt="Book Cover Image" /> + + +
    @@ -197,11 +197,12 @@ -

    Editions

    +

    Editions

    • .gif" title="" /> "> by ©
    • +.01._THUMBZZZ_PU_PU-5_.jpg" /> .gif" title="" /> @@ -212,12 +213,64 @@
    + + +
    +

    Amazon Reader Reviews:

    +

    + + &store=books">Add your own review

    + + +

    Rating (from Amazon.com):

    +
    px">
    + +
    + +

    + + +

    + +
    + + + +
    +

    Sorry, there are no reviews available for this title.

    +
    + + +
    + + + +

    Similar Items

    + + + + +
  • .gif" title="" /> +"> by ©
  • +.01._THUMBZZZ_PU_PU-5_.jpg" /> + + .gif" title="" /> + barcode: + + + + + +
    - @@ -249,7 +302,7 @@ -
    Save Record
    Select Download Format:
    Select Download Format:
    Waited + Awaited Arrived -- 2.39.5