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
Signed-off-by: Magnus Enger <magnus@enger.priv.no>
Tested with marcflavour = NORMARC, on one book and one periodical record.
* Book
- Before the patch:
ISSN: {ISSN}
ISBN: 0375726446
001:
- After the patch:
ISSN:
ISBN: 0375726446
001: 022976914
* Journal
- Before the patch:
ISSN: {ISSN}
ISBN:
001:
- After the patch:
ISSN: 1890-6931
ISBN:
001: 080721370
Looks good in all 3 views! Thanks for fixing the 001 thing for NORMARC!
Also tested with marcflavour = MARC21, on the same records with the same good
results. Signing off!
Signed-off-by: Paul Poulain <paul.poulain@biblibre.com>
Tested marcflavour= UNIMARC, works fine too
This commit is contained in:
parent
628eec4926
commit
a529262501
41
C4/Biblio.pm
41
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
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Reference in New Issue