Bugzilla – Attachment 138665 Details for
Bug 29897
Display author identifiers for researchers
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 29897: Move code to private method for reusability
Bug-29897-Move-code-to-private-method-for-reusabil.patch (text/plain), 5.96 KB, created by
Katrin Fischer
on 2022-08-05 10:55:17 UTC
(
hide
)
Description:
Bug 29897: Move code to private method for reusability
Filename:
MIME Type:
Creator:
Katrin Fischer
Created:
2022-08-05 10:55:17 UTC
Size:
5.96 KB
patch
obsolete
>From c5888fb73c70dac7d2c668d75800ed2f98b69d8f Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Mon, 17 Jan 2022 17:50:26 +0100 >Subject: [PATCH] Bug 29897: Move code to private method for reusability > >Sponsored-by: Orex Digital > >Signed-off-by: Orex Digital <info@orex.es> > >Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de> >--- > Koha/Biblio.pm | 111 +++++++++++++++++++++++++++-------- > t/db_dependent/Koha/Biblio.t | 13 ++-- > 2 files changed, 90 insertions(+), 34 deletions(-) > >diff --git a/Koha/Biblio.pm b/Koha/Biblio.pm >index 56edb03d8b..80aefa715f 100644 >--- a/Koha/Biblio.pm >+++ b/Koha/Biblio.pm >@@ -1001,39 +1001,28 @@ sub get_marc_notes { > return \@marcnotes; > } > >-=head3 get_marc_contributors >- >- my $contributors = $biblio->get_marc_contributors; >- >-Get all contributors (but first author) from the MARC record and returns them in an array. >-They are stored in different fields depending on MARC flavour >- >-=cut >- >-sub get_marc_contributors { >+sub _get_marc_authors { > my ( $self, $params ) = @_; > >- my ( $mintag, $maxtag, $fields_filter ); >- my $marcflavour = C4::Context->preference('marcflavour'); >+ my $fields_filter = $params->{fields_filter}; >+ my $mintag = $params->{mintag}; >+ my $maxtag = $params->{maxtag}; >+ >+ my $AuthoritySeparator = C4::Context->preference('AuthoritySeparator'); >+ my $marcflavour = C4::Context->preference('marcflavour'); > > # tagslib useful only for UNIMARC author responsibilities >- my $tagslib; >- if ( $marcflavour eq "UNIMARC" ) { >- $tagslib = C4::Biblio::GetMarcStructure( 1, $self->frameworkcode, { unsafe => 1 }); >- $mintag = "700"; >- $maxtag = "712"; >- $fields_filter = '7..'; >- } else { # marc21/normarc >- $mintag = "700"; >- $maxtag = "720"; >- $fields_filter = '7..'; >- } >+ my $tagslib = $marcflavour eq "UNIMARC" >+ ? C4::Biblio::GetMarcStructure( 1, $self->frameworkcode, { unsafe => 1 } ) >+ : undef; > > 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; >+ >+ next >+ if $mintag && $field->tag() < $mintag >+ || $maxtag && $field->tag() > $maxtag; >+ > my @subfields_loop; > my @link_loop; > my @subfields = $field->subfields(); >@@ -1097,6 +1086,76 @@ sub get_marc_contributors { > return \@marcauthors; > } > >+=head3 get_marc_contributors >+ >+ my $contributors = $biblio->get_marc_contributors; >+ >+Get all contributors (but first author) from the MARC record and returns them in an array. >+They are stored in different fields depending on MARC flavour (700..712 for MARC21) >+ >+=cut >+ >+sub get_marc_contributors { >+ my ( $self, $params ) = @_; >+ >+ my ( $mintag, $maxtag, $fields_filter ); >+ my $marcflavour = C4::Context->preference('marcflavour'); >+ >+ if ( $marcflavour eq "UNIMARC" ) { >+ $mintag = "700"; >+ $maxtag = "712"; >+ $fields_filter = '7..'; >+ } else { # marc21/normarc >+ $mintag = "700"; >+ $maxtag = "720"; >+ $fields_filter = '7..'; >+ } >+ >+ return $self->_get_marc_authors( >+ { >+ fields_filter => $fields_filter, >+ mintag => $mintag, >+ maxtag => $maxtag >+ } >+ ); >+} >+ >+=head3 get_marc_authors >+ >+ my $authors = $biblio->get_marc_authors; >+ >+Get all authors from the MARC record and returns them in an array. >+They are stored in different fields depending on MARC flavour >+(main author from 100 then secondary authors from 700..712). >+ >+=cut >+ >+sub get_marc_authors { >+ my ( $self, $params ) = @_; >+ >+ my ( $mintag, $maxtag, $fields_filter ); >+ my $marcflavour = C4::Context->preference('marcflavour'); >+ >+ if ( $marcflavour eq "UNIMARC" ) { >+ $fields_filter = '200'; >+ } else { # marc21/normarc >+ $fields_filter = '100'; >+ } >+ >+ my @first_authors = @{$self->_get_marc_authors( >+ { >+ fields_filter => $fields_filter, >+ mintag => $mintag, >+ maxtag => $maxtag >+ } >+ )}; >+ >+ my @other_authors = @{$self->get_marc_contributors}; >+ >+ return [@first_authors, @other_authors]; >+} >+ >+ > =head3 to_api > > my $json = $biblio->to_api; >diff --git a/t/db_dependent/Koha/Biblio.t b/t/db_dependent/Koha/Biblio.t >index f1633dedee..94deac1c28 100755 >--- a/t/db_dependent/Koha/Biblio.t >+++ b/t/db_dependent/Koha/Biblio.t >@@ -883,28 +883,25 @@ subtest 'current_checkouts() and old_checkouts() tests' => sub { > > subtest 'get_marc_contributors() tests' => sub { > >- plan tests => 1; >+ plan tests => 2; > > $schema->storage->txn_begin; > >- my $biblio = $builder->build_sample_biblio; >+ my $biblio = $builder->build_sample_biblio({ author => 'Main author' }); > 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'); >+ $field = MARC::Field->new('701','1','','d' => 'Secondary author 2'); > $record->append_fields($field); > > # get record > C4::Biblio::ModBiblio( $record, $biblio->biblionumber ); > $biblio = Koha::Biblios->find( $biblio->biblionumber ); > >- is( 4, @{$biblio->get_marc_contributors}, 'get_marc_contributors retrieves correct number of author subfields' ); >+ is( @{$biblio->get_marc_authors}, 3, 'get_marc_authors retrieves correct number of author subfields' ); >+ is( @{$biblio->get_marc_contributors}, 2, 'get_marc_contributors retrieves correct number of author subfields' ); > $schema->storage->txn_rollback; > }; > >-- >2.30.2
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 29897
:
129816
|
129817
|
129818
|
129819
|
132961
|
132962
|
132963
|
132964
|
133081
|
133113
|
133114
|
133115
|
133116
|
133117
|
134459
|
134460
|
134461
|
134462
|
134463
|
134464
|
135983
|
135984
|
135985
|
135986
|
135987
|
135988
|
135989
|
135990
|
135991
|
135992
|
135993
|
138249
|
138250
|
138251
|
138252
|
138253
|
138254
|
138255
|
138256
|
138257
|
138258
|
138259
|
138260
|
138371
|
138372
|
138425
|
138426
|
138427
|
138428
|
138429
|
138430
|
138431
|
138432
|
138433
|
138434
|
138435
|
138486
|
138487
|
138490
|
138501
|
138664
| 138665 |
138666
|
138667
|
138668
|
138669
|
138670
|
138671
|
138672
|
138673
|
138674
|
138675
|
138676
|
138677
|
138678
|
138679