Bugzilla – Attachment 7843 Details for
Bug 7576
Add ISSN to SearchForTitleIn
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 7576: Add ISSN to SearchForTitleIn preference
Bug-7576-Add-ISSN-to-SearchForTitleIn-preference.patch (text/plain), 12.04 KB, created by
Katrin Fischer
on 2012-02-23 23:06:49 UTC
(
hide
)
Description:
Bug 7576: Add ISSN to SearchForTitleIn preference
Filename:
MIME Type:
Creator:
Katrin Fischer
Created:
2012-02-23 23:06:49 UTC
Size:
12.04 KB
patch
obsolete
>From 2ce052e5e27b2c2da5f83110496b1b4484dab905 Mon Sep 17 00:00:00 2001 >From: Katrin Fischer <Katrin.Fischer.83@web.de> >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): ><li>ISSN: {ISSN}</li> ><li>ISBN: {ISBN}</li> ><li>001: {CONTROLNUMBER}</li> > >Patch also includes some unit tests: >perl t/db_dependent/Biblio.t >--- > C4/Biblio.pm | 41 +++++++++++++++--- > .../prog/en/modules/admin/preferences/opac.pref | 2 +- > opac/opac-ISBDdetail.pl | 5 ++- > opac/opac-MARCdetail.pl | 5 ++- > opac/opac-detail.pl | 7 ++- > t/db_dependent/Biblio.t | 44 +++++++++++++++++++- > 6 files changed, 90 insertions(+), 14 deletions(-) > >diff --git a/C4/Biblio.pm b/C4/Biblio.pm >index b3a95b8..732e3c5 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(); >@@ -1390,7 +1391,7 @@ sub GetMarcControlnumber { > $marcisbnsarray = GetMarcISBN( $record, $marcflavour ); > > Get all ISBNs from the MARC record and returns them in an array. >-ISBNs stored in differents places depending on MARC flavour >+ISBNs stored in different fields depending on MARC flavour > > =cut > >@@ -1425,12 +1426,38 @@ 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 different fields 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 ); > > Get all notes from the MARC record and returns them in an array. >-The note are stored in differents places depending on MARC flavour >+The note are stored in different fields depending on MARC flavour > > =cut > >@@ -1470,7 +1497,7 @@ sub GetMarcNotes { > $marcsubjcts = GetMarcSubjects($record,$marcflavour); > > Get all subjects from the MARC record and returns them in an array. >-The subjects are stored in differents places depending on MARC flavour >+The subjects are stored in different fields depending on MARC flavour > > =cut > >@@ -1545,7 +1572,7 @@ sub GetMarcSubjects { > authors = GetMarcAuthors($record,$marcflavour); > > Get all authors from the MARC record and returns them in an array. >-The authors are stored in differents places depending on MARC flavour >+The authors are stored in different fields depending on MARC flavour > > =cut > >@@ -1682,7 +1709,7 @@ sub GetMarcUrls { > $marcseriesarray = GetMarcSeries($record,$marcflavour); > > Get all series from the MARC record and returns them in an array. >-The series are stored in differents places depending on MARC flavour >+The series are stored in different fields depending on MARC flavour > > =cut > >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref >index be86733..24856b8 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref >@@ -173,7 +173,7 @@ OPAC: > class: code > - > - 'Include a "More Searches" box on the detail pages of items on the OPAC, with the following HTML (leave blank to disable):' >- - '<br />Note: The placeholders {BIBLIONUMBER}, {CONTROLNUMBER}, {TITLE}, {ISBN} and {AUTHOR} will be replaced with information from the displayed record.' >+ - '<br />Note: The placeholders {BIBLIONUMBER}, {CONTROLNUMBER}, {TITLE}, {ISBN}, {ISSN} and {AUTHOR} will be replaced with information from the displayed record.' > - pref: OPACSearchForTitleIn > type: textarea > class: code >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
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 7576
:
7842
|
7843
|
7850