@@ -, +, @@ - t/Biblio.t - t/db_dependent/Koha/Biblio.t --- C4/Biblio.pm | 100 ------------------------------------------- Koha/Biblio.pm | 96 +++++++++++++++++++++++++++++++++++++++++ basket/basket.pl | 3 +- basket/sendbasket.pl | 3 +- opac/opac-basket.pl | 3 +- opac/opac-detail.pl | 2 +- opac/opac-sendbasket.pl | 3 +- opac/opac-sendshelf.pl | 3 +- t/Biblio.t | 8 +--- t/db_dependent/Koha/Biblio.t | 30 ++++++++++++- virtualshelves/sendshelf.pl | 3 +- 11 files changed, 139 insertions(+), 115 deletions(-) --- a/C4/Biblio.pm +++ a/C4/Biblio.pm @@ -36,7 +36,6 @@ BEGIN { GetMarcISBN GetMarcISSN GetMarcSubjects - GetMarcAuthors GetMarcSeries GetMarcUrls GetUsedMarcStructure @@ -1694,105 +1693,6 @@ sub GetMarcSubjects { return \@marcsubjects; } #end getMARCsubjects -=head2 GetMarcAuthors - - authors = GetMarcAuthors($record,$marcflavour); - -Get all authors from the MARC record and returns them in an array. -The authors are stored in different fields depending on MARC flavour - -=cut - -sub GetMarcAuthors { - my ( $record, $marcflavour ) = @_; - if (!$record) { - carp 'GetMarcAuthors called on undefined record'; - return; - } - my ( $mintag, $maxtag, $fields_filter ); - - # tagslib useful only for UNIMARC author responsibilities - my $tagslib; - if ( $marcflavour eq "UNIMARC" ) { - # FIXME : we don't have the framework available, we take the default framework. May be buggy on some setups, will be usually correct. - $tagslib = GetMarcStructure( 1, '', { unsafe => 1 }); - $mintag = "700"; - $maxtag = "712"; - $fields_filter = '7..'; - } else { # marc21/normarc - $mintag = "700"; - $maxtag = "720"; - $fields_filter = '7..'; - } - - my @marcauthors; - my $AuthoritySeparator = C4::Context->preference('AuthoritySeparator'); - - foreach my $field ( $record->field($fields_filter) ) { - next unless $field->tag() >= $mintag && $field->tag() <= $maxtag; - my @subfields_loop; - my @link_loop; - my @subfields = $field->subfields(); - my $count_auth = 0; - - # if there is an authority link, build the link with Koha-Auth-Number: subfield9 - my $subfield9 = $field->subfield('9'); - if ($subfield9) { - my $linkvalue = $subfield9; - $linkvalue =~ s/(\(|\))//g; - @link_loop = ( { 'limit' => 'an', 'link' => $linkvalue } ); - } - - # other subfields - my $unimarc3; - for my $authors_subfield (@subfields) { - next if ( $authors_subfield->[0] eq '9' ); - - # unimarc3 contains the $3 of the author for UNIMARC. - # For french academic libraries, it's the "ppn", and it's required for idref webservice - $unimarc3 = $authors_subfield->[1] if $marcflavour eq 'UNIMARC' and $authors_subfield->[0] =~ /3/; - - # don't load unimarc subfields 3, 5 - next if ( $marcflavour eq 'UNIMARC' and ( $authors_subfield->[0] =~ /3|5/ ) ); - - my $code = $authors_subfield->[0]; - my $value = $authors_subfield->[1]; - my $linkvalue = $value; - $linkvalue =~ s/(\(|\))//g; - # UNIMARC author responsibility - if ( $marcflavour eq 'UNIMARC' and $code eq '4' ) { - $value = GetAuthorisedValueDesc( $field->tag(), $code, $value, '', $tagslib ); - $linkvalue = "($value)"; - } - # if no authority link, build a search query - unless ($subfield9) { - push @link_loop, { - limit => 'au', - 'link' => $linkvalue, - operator => (scalar @link_loop) ? ' and ' : undef - }; - } - my @this_link_loop = @link_loop; - # do not display $0 - unless ( $code eq '0') { - push @subfields_loop, { - tag => $field->tag(), - code => $code, - value => $value, - link_loop => \@this_link_loop, - separator => (scalar @subfields_loop) ? $AuthoritySeparator : '' - }; - } - } - push @marcauthors, { - MARCAUTHOR_SUBFIELDS_LOOP => \@subfields_loop, - authoritylink => $subfield9, - unimarc3 => $unimarc3 - }; - } - return \@marcauthors; -} - =head2 GetMarcUrls $marcurls = GetMarcUrls($record,$marcflavour); --- a/Koha/Biblio.pm +++ a/Koha/Biblio.pm @@ -797,6 +797,102 @@ sub cover_images { return Koha::CoverImages->_new_from_dbic($cover_images_rs); } +=head3 get_authors_from_MARC + + my $authors = $biblio->get_authors_from_MARC; + +Get all authors from the MARC record and returns them in an array. +The authors are stored in different fields depending on MARC flavour + +=cut + +sub get_authors_from_MARC { + my ( $self, $params ) = @_; + + my ( $mintag, $maxtag, $fields_filter ); + my $marcflavour = C4::Context->preference('marcflavour'); + + # tagslib useful only for UNIMARC author responsibilities + my $tagslib; + if ( $marcflavour eq "UNIMARC" ) { + # FIXME : we don't have the framework available, we take the default framework. May be buggy on some setups, will be usually correct. + $tagslib = C4::Biblio::GetMarcStructure( 1, '', { unsafe => 1 }); + $mintag = "700"; + $maxtag = "712"; + $fields_filter = '7..'; + } else { # marc21/normarc + $mintag = "700"; + $maxtag = "720"; + $fields_filter = '7..'; + } + + my @marcauthors; + my $AuthoritySeparator = C4::Context->preference('AuthoritySeparator'); + + foreach my $field ( $self->metadata->record->field($fields_filter) ) { + next unless $field->tag() >= $mintag && $field->tag() <= $maxtag; + my @subfields_loop; + my @link_loop; + my @subfields = $field->subfields(); + my $count_auth = 0; + + # if there is an authority link, build the link with Koha-Auth-Number: subfield9 + my $subfield9 = $field->subfield('9'); + if ($subfield9) { + my $linkvalue = $subfield9; + $linkvalue =~ s/(\(|\))//g; + @link_loop = ( { 'limit' => 'an', 'link' => $linkvalue } ); + } + + # other subfields + my $unimarc3; + for my $authors_subfield (@subfields) { + next if ( $authors_subfield->[0] eq '9' ); + + # unimarc3 contains the $3 of the author for UNIMARC. + # For french academic libraries, it's the "ppn", and it's required for idref webservice + $unimarc3 = $authors_subfield->[1] if $marcflavour eq 'UNIMARC' and $authors_subfield->[0] =~ /3/; + + # don't load unimarc subfields 3, 5 + next if ( $marcflavour eq 'UNIMARC' and ( $authors_subfield->[0] =~ /3|5/ ) ); + + my $code = $authors_subfield->[0]; + my $value = $authors_subfield->[1]; + my $linkvalue = $value; + $linkvalue =~ s/(\(|\))//g; + # UNIMARC author responsibility + if ( $marcflavour eq 'UNIMARC' and $code eq '4' ) { + $value = C4::Biblio::GetAuthorisedValueDesc( $field->tag(), $code, $value, '', $tagslib ); + $linkvalue = "($value)"; + } + # if no authority link, build a search query + unless ($subfield9) { + push @link_loop, { + limit => 'au', + 'link' => $linkvalue, + operator => (scalar @link_loop) ? ' and ' : undef + }; + } + my @this_link_loop = @link_loop; + # do not display $0 + unless ( $code eq '0') { + push @subfields_loop, { + tag => $field->tag(), + code => $code, + value => $value, + link_loop => \@this_link_loop, + separator => (scalar @subfields_loop) ? $AuthoritySeparator : '' + }; + } + } + push @marcauthors, { + MARCAUTHOR_SUBFIELDS_LOOP => \@subfields_loop, + authoritylink => $subfield9, + unimarc3 => $unimarc3 + }; + } + return \@marcauthors; +} =head3 to_api --- a/basket/basket.pl +++ a/basket/basket.pl @@ -61,9 +61,10 @@ foreach my $biblionumber ( @bibs ) { my $dat = &GetBiblioData($biblionumber); next unless $dat; + my $biblio = Koha::Biblios->find( $biblionumber ); my $record = &GetMarcBiblio({ biblionumber => $biblionumber }); my $marcnotesarray = GetMarcNotes( $record, $marcflavour ); - my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour ); + my $marcauthorsarray = $biblio->get_authors_from_MARC; my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour ); my $marcseriesarray = GetMarcSeries ($record,$marcflavour); my $marcurlsarray = GetMarcUrls ($record,$marcflavour); --- a/basket/sendbasket.pl +++ a/basket/sendbasket.pl @@ -69,10 +69,11 @@ if ( $email_add ) { my $dat = GetBiblioData($biblionumber); next unless $dat; + my $biblio = Koha::Biblios->find( $biblionumber ); my $record = GetMarcBiblio({ biblionumber => $biblionumber, embed_items => 1 }); - my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour ); + my $marcauthorsarray = $biblio->get_authors_from_MARC; my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour ); my @items = GetItemsInfo( $biblionumber ); --- a/opac/opac-basket.pl +++ a/opac/opac-basket.pl @@ -70,6 +70,7 @@ foreach my $biblionumber ( @bibs ) { my $dat = &GetBiblioData($biblionumber); next unless $dat; + my $biblio = Koha::Biblios->find( $biblionumber ); # No filtering on the item records needed for the record itself # since the only reason item information is grabbed is because of branchcodes. @@ -82,7 +83,7 @@ foreach my $biblionumber ( @bibs ) { $record_processor->process($record); next unless $record; my $marcnotesarray = GetMarcNotes( $record, $marcflavour, 1 ); - my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour ); + my $marcauthorsarray = $biblio->get_authors_from_MARC; my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour ); my $marcseriesarray = GetMarcSeries ($record,$marcflavour); my $marcurlsarray = GetMarcUrls ($record,$marcflavour); --- a/opac/opac-detail.pl +++ a/opac/opac-detail.pl @@ -802,7 +802,7 @@ if (scalar(@itemloop) == 0 || scalar(@otheritemloop) == 0) { ## get notes and subjects from MARC record if (!C4::Context->preference("OPACXSLTDetailsDisplay") ) { my $marcisbnsarray = GetMarcISBN ($record,$marcflavour); - my $marcauthorsarray = GetMarcAuthors ($record,$marcflavour); + my $marcauthorsarray = $biblio->get_authors_from_MARC; my $marcsubjctsarray = GetMarcSubjects($record,$marcflavour); my $marcseriesarray = GetMarcSeries ($record,$marcflavour); my $marcurlsarray = GetMarcUrls ($record,$marcflavour); --- a/opac/opac-sendbasket.pl +++ a/opac/opac-sendbasket.pl @@ -77,12 +77,13 @@ if ( $email_add ) { my $dat = GetBiblioData($biblionumber); next unless $dat; + my $biblio = Koha::Biblios->find( $biblionumber ); my $record = GetMarcBiblio({ biblionumber => $biblionumber, embed_items => 1, opac => 1, borcat => $borcat }); - my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour ); + my $marcauthorsarray = $biblio->get_authors_from_MARC; my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour ); my @items = GetItemsInfo( $biblionumber ); --- a/opac/opac-sendshelf.pl +++ a/opac/opac-sendshelf.pl @@ -86,10 +86,11 @@ if ( $email ) { opac => 1, borcat => $borcat }); next unless $record; + my $biblio = Koha::Biblios->find( $biblionumber ); my $fw = GetFrameworkCode($biblionumber); my $dat = GetBiblioData($biblionumber); - my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour ); + my $marcauthorsarray = $biblio->get_authors_from_MARC; my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour ); my @items = GetItemsInfo( $biblionumber ); --- a/t/Biblio.t +++ a/t/Biblio.t @@ -21,7 +21,7 @@ use Test::More; use Test::MockModule; use Test::Warn; -plan tests => 41; +plan tests => 39; use_ok('C4::Biblio'); @@ -99,12 +99,6 @@ warning_is { $ret = GetMarcSubjects() } ok( !defined $ret, 'GetMarcSubjects returns undef if not passed rec'); -warning_is { $ret = GetMarcAuthors() } - { carped => 'GetMarcAuthors called on undefined record'}, - "GetMarcAuthors returns carped warning on undef record"; - -ok( !defined $ret, 'GetMarcAuthors returns undef if not passed rec'); - warning_is { $ret = GetMarcUrls() } { carped => 'GetMarcUrls called on undefined record'}, "GetMarcUrls returns carped warning on undef record"; --- a/t/db_dependent/Koha/Biblio.t +++ a/t/db_dependent/Koha/Biblio.t @@ -17,7 +17,7 @@ use Modern::Perl; -use Test::More tests => 12; +use Test::More tests => 13; use C4::Biblio; use Koha::Database; @@ -551,3 +551,31 @@ subtest 'subscriptions() tests' => sub { $schema->storage->txn_rollback; }; + +subtest 'get_authors_from_MARC() tests' => sub { + + plan tests => 1; + + $schema->storage->txn_begin; + + my $biblio = $builder->build_sample_biblio; + my $record = $biblio->metadata->record; + + # add author information + my $field = MARC::Field->new('700','1','','a' => 'Jefferson, Thomas'); + $record->append_fields($field); + $field = MARC::Field->new('700','1','','d' => '1743-1826'); + $record->append_fields($field); + $field = MARC::Field->new('700','1','','e' => 'former owner.'); + $record->append_fields($field); + $field = MARC::Field->new('700','1','','5' => 'MH'); + $record->append_fields($field); + + # get record + C4::Biblio::ModBiblio( $record, $biblio->biblionumber ); + $biblio = Koha::Biblios->find( $biblio->biblionumber ); + + is( 4, @{$biblio->get_authors_from_MARC}, 'get_authors_from_MARC retrieves correct number of author subfields' ); + + $schema->storage->txn_rollback; +}; --- a/virtualshelves/sendshelf.pl +++ a/virtualshelves/sendshelf.pl @@ -67,11 +67,12 @@ if ($to_address) { while ( my $content = $contents->next ) { my $biblionumber = $content->biblionumber; + my $biblio = Koha::Biblios->find( $biblionumber ); my $dat = GetBiblioData($biblionumber); my $record = GetMarcBiblio({ biblionumber => $biblionumber, embed_items => 1 }); - my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour ); + my $marcauthorsarray = $biblio->get_authors_from_MARC; my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour ); my @items = GetItemsInfo($biblionumber); --