From 6f2026334b3662dca267a44542ab880954000e8b Mon Sep 17 00:00:00 2001 From: Katrin Fischer Date: Thu, 23 Feb 2012 08:21:10 +0100 Subject: [PATCH] Bug 7576: Add ISSN to SearchForTitleIn preference Adds a new placeholder {ISSN} to the system preference SearchForTitleIn. For a record with multiple ISSNs only the first ISSN will be used. Addition: Makes a small change to GetMarcControlnumber so that it checks for NORMARC too. If you set your system preference to NORMARC, it should output {CONTROLNUMBER} correctly now. For testing add following code to the system preference and check output of SearchForTitleIn for different records in your OPAC and all 3 available views (normal, MARC and ISBD):
  • ISSN: {ISSN}
  • ISBN: {ISBN}
  • 001: {CONTROLNUMBER}
  • Patch also includes some unit tests: perl t/db_dependent/Biblio.t --- C4/Biblio.pm | 31 +++++++++++++++++++++++++++++-- opac/opac-ISBDdetail.pl | 5 ++++- opac/opac-MARCdetail.pl | 5 ++++- opac/opac-detail.pl | 7 +++++-- t/db_dependent/Biblio.t | 44 ++++++++++++++++++++++++++++++++++++++++++-- 5 files changed, 84 insertions(+), 8 deletions(-) diff --git a/C4/Biblio.pm b/C4/Biblio.pm index b3a95b8..014d651 100644 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -70,6 +70,7 @@ BEGIN { &GetMarcControlnumber &GetMarcNotes &GetMarcISBN + &GetMarcISSN &GetMarcSubjects &GetMarcBiblio &GetMarcAuthors @@ -1374,9 +1375,9 @@ Get the control number / record Identifier from the MARC record and return it. sub GetMarcControlnumber { my ( $record, $marcflavour ) = @_; my $controlnumber = ""; - # Control number or Record identifier are the same field in MARC21 and UNIMARC + # Control number or Record identifier are the same field in MARC21, UNIMARC and NORMARC # Keep $marcflavour for possible later use - if ($marcflavour eq "MARC21" || $marcflavour eq "UNIMARC") { + if ($marcflavour eq "MARC21" || $marcflavour eq "UNIMARC" || $marcflavour eq "NORMARC") { my $controlnumberField = $record->field('001'); if ($controlnumberField) { $controlnumber = $controlnumberField->data(); @@ -1425,6 +1426,32 @@ sub GetMarcISBN { return \@marcisbns; } # end GetMarcISBN + +=head2 GetMarcISSN + + $marcissnsarray = GetMarcISSN( $record, $marcflavour ); + +Get all valid ISSNs from the MARC record and returns them in an array. +ISSNs are stored in differents fields and subfields depending on MARC flavour + +=cut + +sub GetMarcISSN { + my ( $record, $marcflavour ) = @_; + my $scope; + if ( $marcflavour eq "UNIMARC" ) { + $scope = '011'; + } + else { # assume MARC21 or NORMARC + $scope = '022'; + } + my @marcissns; + foreach my $field ( $record->field($scope) ) { + push @marcissns, $field->subfield( 'a' ); + } + return \@marcissns; +} # end GetMarcISSN + =head2 GetMarcNotes $marcnotesarray = GetMarcNotes( $record, $marcflavour ); diff --git a/opac/opac-ISBDdetail.pl b/opac/opac-ISBDdetail.pl index 3373787..bd2b838 100755 --- a/opac/opac-ISBDdetail.pl +++ b/opac/opac-ISBDdetail.pl @@ -165,7 +165,9 @@ my @export_options = split(/\|/,$OpacExportOptions); $template->{VARS}->{'export_options'} = \@export_options; #Search for title in links -my $marccontrolnumber = GetMarcControlnumber ($record, $marcflavour); +my $marccontrolnumber = GetMarcControlnumber ($record, $marcflavour); +my $marcissns = GetMarcISSN ( $record, $marcflavour ); +my $issn = $marcissns->[0] || ''; if (my $search_for_title = C4::Context->preference('OPACSearchForTitleIn')){ $dat->{author} ? $search_for_title =~ s/{AUTHOR}/$dat->{author}/g : $search_for_title =~ s/{AUTHOR}//g; @@ -173,6 +175,7 @@ if (my $search_for_title = C4::Context->preference('OPACSearchForTitleIn')){ $dat->{title} =~ s/\s+$//; # remove trailing space $dat->{title} ? $search_for_title =~ s/{TITLE}/$dat->{title}/g : $search_for_title =~ s/{TITLE}//g; $isbn ? $search_for_title =~ s/{ISBN}/$isbn/g : $search_for_title =~ s/{ISBN}//g; + $issn ? $search_for_title =~ s/{ISSN}/$issn/g : $search_for_title =~ s/{ISSN}//g; $marccontrolnumber ? $search_for_title =~ s/{CONTROLNUMBER}/$marccontrolnumber/g : $search_for_title =~ s/{CONTROLNUMBER}//g; $search_for_title =~ s/{BIBLIONUMBER}/$biblionumber/g; $template->param('OPACSearchForTitleIn' => $search_for_title); diff --git a/opac/opac-MARCdetail.pl b/opac/opac-MARCdetail.pl index 519791c..695e4ad 100755 --- a/opac/opac-MARCdetail.pl +++ b/opac/opac-MARCdetail.pl @@ -279,7 +279,9 @@ $template->{VARS}->{'export_options'} = \@export_options; my $marcflavour = C4::Context->preference("marcflavour"); my $dat = TransformMarcToKoha( $dbh, $record ); my $isbn = GetNormalizedISBN(undef,$record,$marcflavour); -my $marccontrolnumber = GetMarcControlnumber ($record, $marcflavour); +my $marccontrolnumber = GetMarcControlnumber ($record, $marcflavour); +my $marcissns = GetMarcISSN( $record, $marcflavour ); +my $issn = $marcissns->[0] || ''; if (my $search_for_title = C4::Context->preference('OPACSearchForTitleIn')){ $dat->{author} ? $search_for_title =~ s/{AUTHOR}/$dat->{author}/g : $search_for_title =~ s/{AUTHOR}//g; @@ -287,6 +289,7 @@ if (my $search_for_title = C4::Context->preference('OPACSearchForTitleIn')){ $dat->{title} =~ s/\s+$//; # remove trailing space $dat->{title} ? $search_for_title =~ s/{TITLE}/$dat->{title}/g : $search_for_title =~ s/{TITLE}//g; $isbn ? $search_for_title =~ s/{ISBN}/$isbn/g : $search_for_title =~ s/{ISBN}//g; + $issn ? $search_for_title =~ s/{ISSN}/$issn/g : $search_for_title =~ s/{ISSN}//g; $marccontrolnumber ? $search_for_title =~ s/{CONTROLNUMBER}/$marccontrolnumber/g : $search_for_title =~ s/{CONTROLNUMBER}//g; $search_for_title =~ s/{BIBLIONUMBER}/$biblionumber/g; $template->param('OPACSearchForTitleIn' => $search_for_title); diff --git a/opac/opac-detail.pl b/opac/opac-detail.pl index b5a25a8..07b1ddb 100755 --- a/opac/opac-detail.pl +++ b/opac/opac-detail.pl @@ -896,7 +896,9 @@ my @export_options = split(/\|/,$OpacExportOptions); $template->{VARS}->{'export_options'} = \@export_options; #Search for title in links -my $marccontrolnumber = GetMarcControlnumber ($record, $marcflavour); +my $marccontrolnumber = GetMarcControlnumber ($record, $marcflavour); +my $marcissns = GetMarcISSN ( $record, $marcflavour ); +my $issn = $marcissns->[0] || ''; if (my $search_for_title = C4::Context->preference('OPACSearchForTitleIn')){ $dat->{author} ? $search_for_title =~ s/{AUTHOR}/$dat->{author}/g : $search_for_title =~ s/{AUTHOR}//g; @@ -904,9 +906,10 @@ if (my $search_for_title = C4::Context->preference('OPACSearchForTitleIn')){ $dat->{title} =~ s/\s+$//; # remove trailing space $dat->{title} ? $search_for_title =~ s/{TITLE}/$dat->{title}/g : $search_for_title =~ s/{TITLE}//g; $isbn ? $search_for_title =~ s/{ISBN}/$isbn/g : $search_for_title =~ s/{ISBN}//g; + $issn ? $search_for_title =~ s/{ISSN}/$issn/g : $search_for_title =~ s/{ISSN}//g; $marccontrolnumber ? $search_for_title =~ s/{CONTROLNUMBER}/$marccontrolnumber/g : $search_for_title =~ s/{CONTROLNUMBER}//g; $search_for_title =~ s/{BIBLIONUMBER}/$biblionumber/g; - $template->param('OPACSearchForTitleIn' => $search_for_title); + $template->param('OPACSearchForTitleIn' => $search_for_title); } # We try to select the best default tab to show, according to what diff --git a/t/db_dependent/Biblio.t b/t/db_dependent/Biblio.t index dd827f0..4725e53 100755 --- a/t/db_dependent/Biblio.t +++ b/t/db_dependent/Biblio.t @@ -5,12 +5,12 @@ use strict; use warnings; -use Test::More tests => 9; +use Test::More tests => 17; use MARC::Record; use C4::Biblio; BEGIN { - use_ok('C4::Biblio'); + use_ok('C4::Biblio'); } my $isbn = '0590353403'; @@ -69,5 +69,45 @@ eval { }; ok($success, "ModBiblio handles 655 with no subfields"); +# Testing GetMarcISSN +my $issns; +$issns = GetMarcISSN( $marc_record, 'MARC21' ); +is( $issns->[0], undef, + 'GetMarcISSN handles records without 022 (list is empty)' ); +is( scalar @$issns, 0, 'GetMarcISSN handles records without 022 (number of elements correct)' ); + +my $issn = '1234-1234'; +$field = MARC::Field->new( '022', '', '', 'a', => $issn ); +$marc_record->append_fields($field); +$issns = GetMarcISSN( $marc_record, 'MARC21' ); +is( $issns->[0], $issn, + 'GetMarcISSN handles records with single 022 (first element is correct)' ); +is( scalar @$issns, 1, 'GetMARCISSN handles records with single 022 (number of elements correct)' +); + +my @more_issns = qw/1111-1111 2222-2222 3333-3333/; +foreach (@more_issns) { + $field = MARC::Field->new( '022', '', '', 'a', => $_ ); + $marc_record->append_fields($field); +} +$issns = GetMarcISSN( $marc_record, 'MARC21' ); +is( scalar @$issns, 4, 'GetMARCISSN handles records with multiple 022 (number of elements correct)' +); + +# Testing GetMarcControlnumber +my $controlnumber; +$controlnumber = GetMarcControlnumber( $marc_record, 'MARC21' ); +is( $controlnumber, '', 'GetMarcControlnumber handles records without 001' ); + +$field = MARC::Field->new( '001', '' ); +$marc_record->append_fields($field); +$controlnumber = GetMarcControlnumber( $marc_record, 'MARC21' ); +is( $controlnumber, '', 'GetMarcControlnumber handles records with empty 001' ); + +$field = $marc_record->field('001'); +$field->update('123456789X'); +$controlnumber = GetMarcControlnumber( $marc_record, 'MARC21' ); +is( $controlnumber, '123456789X', 'GetMarcControlnumber handles records with 001' ); + # clean up after ourselves DelBiblio($biblionumber); -- 1.7.5.4