From 40ca270825734e9716871401cabd86414ff4c470 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 14 Mar 2024 09:58:05 +0100 Subject: [PATCH] Bug 29948: OPACAuthorIdentifiersAndInformation This patch merge the previous patch attempt with the existing OPACAuthorIdentifiers syspref. It creates a new syspref OPACAuthorIdentifiersAndInformation and remove OPACAuthorIdentifiers. "identifiers" become an entry of the new syspref. Test plan: Select some entries in OPACAuthorIdentifiersAndInformation Edit an authority record and enter data in the corresponding subfield (the list is on the syspref entry) Go to the biblio detail page or the authority detail page at the OPAC and notice that the info you selected are correctly displayed. Sponsored-by: Orex Digital Signed-off-by: Signed-off-by: Hugo Agud Signed-off-by: David Nind Signed-off-by: Nick Clemens Signed-off-by: Katrin Fischer --- Koha/Authority.pm | 45 +++++++------------ .../data/mysql/atomicupdate/bug_29948.pl | 22 ++++++--- .../en/modules/admin/preferences/opac.pref | 15 +++---- .../en/includes/authority-identifiers.inc | 27 ----------- .../en/includes/authority-information.inc | 20 +++++++++ .../bootstrap/en/modules/opac-auth-detail.tt | 14 +++--- .../bootstrap/en/modules/opac-detail.tt | 21 ++------- opac/opac-authoritiesdetail.pl | 6 +-- opac/opac-detail.pl | 24 ++-------- t/db_dependent/Koha/Authorities.t | 27 ++++++----- 10 files changed, 86 insertions(+), 135 deletions(-) delete mode 100644 koha-tmpl/opac-tmpl/bootstrap/en/includes/authority-identifiers.inc diff --git a/Koha/Authority.pm b/Koha/Authority.pm index 0bee57b135..5cfc806b09 100644 --- a/Koha/Authority.pm +++ b/Koha/Authority.pm @@ -141,39 +141,15 @@ sub controlled_indicators { }); } -=head3 get_identifiers +=head3 get_identifiers_and_information - my $identifiers = $author->get_identifiers; + my $information = $author->get_identifiers_and_information; -Return a list of identifiers of the authors which are in 024$2$a +Return a list of information of the authors (syspref OPACAuthorIdentifiersAndInformation) =cut -sub get_identifiers { - my ( $self ) = @_; - - my $record = $self->record; - - my @identifiers; - for my $field ( $record->field('024') ) { - my $sf_2 = $field->subfield('2'); - my $sf_a = $field->subfield('a'); - next unless $sf_2 && $sf_a; - push @identifiers, {source => $sf_2, number => $sf_a, }; - } - - return \@identifiers; -} - -=head3 get_information - - my $information = $author->get_information; - -Return a list of information of the authors (syspref OPACAuthorInformation) - -=cut - -sub get_information { +sub get_identifiers_and_information { my ($self) = @_; my $record = $self->record; @@ -182,8 +158,17 @@ sub get_information { return if C4::Context->preference('marcflavour') eq 'UNIMARC'; my $information; - for my $info ( split ',', C4::Context->preference('OPACAuthorInformation') ) { - if ( $info eq 'activity' ) { + for my $info ( split ',', C4::Context->preference('OPACAuthorIdentifiersAndInformation') ) { + if ( $info eq 'identifiers' ) { + + # identifiers (024$2$a) + for my $field ( $record->field('024') ) { + my $sf_2 = $field->subfield('2'); + my $sf_a = $field->subfield('a'); + next unless $sf_2 && $sf_a; + push @{ $information->{identifiers} }, { source => $sf_2, number => $sf_a, }; + } + } elsif ( $info eq 'activity' ) { # activity: Activity (372$a$s$t) for my $field ( $record->field('372') ) { diff --git a/installer/data/mysql/atomicupdate/bug_29948.pl b/installer/data/mysql/atomicupdate/bug_29948.pl index 3b8f0a682b..1dc6362e60 100755 --- a/installer/data/mysql/atomicupdate/bug_29948.pl +++ b/installer/data/mysql/atomicupdate/bug_29948.pl @@ -1,16 +1,24 @@ use Modern::Perl; return { - bug_number => "29948", + bug_number => "29948", description => "Display author information for researchers", - up => sub { + up => sub { my ($args) = @_; - my ($dbh, $out) = @$args{qw(dbh out)}; - $dbh->do(q{ + my ( $dbh, $out ) = @$args{qw(dbh out)}; + my ($OPACAuthorIdentifiers) = + $dbh->selectrow_array(q{SELECT value FROM systempreferences WHERE variable="OPACAuthorIdentifiers"}); + my $value = $OPACAuthorIdentifiers ? 'identifiers' : ''; + + $dbh->do( + q{ INSERT IGNORE INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `type` ) VALUES - ('OPACAuthorInformation','0','','Display author information on the OPAC detail page','multiple_sortable') - }); + ('OPACAuthorIdentifiersAndInformation', ?, '', 'Display author information on the OPAC detail page','multiple_sortable') + }, undef, $value + ); + say $out "Added new system preference 'OPACAuthorIdentifiersAndInformation'"; - say $out "Added new system preference 'OPACAuthorInformation'"; + $dbh->do(q{DELETE FROM systempreferences WHERE variable="OPACAuthorIdentifiers"}); + say $out " Removed system preference 'OPACAuthorIdentifiers'"; }, }; 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 613c1b110b..3212c3456f 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 @@ -524,27 +524,22 @@ OPAC: 1: Enable 0: Disable - "interface for browsing all holdings (Elasticsearch only)." - - - - pref: OPACAuthorIdentifiers - default: 0 - choices: - 1: Display - 0: "Don't display" - - "identifiers for authors and contributors to the detail pages in the OPAC." - - "This feature requires authorities with 024$2 and 024$a." - - "Valid source codes in $2 are currently: orcid, scopus, loop, rid and viaf." - - "Display the following information for authors and contributors to the detail pages in the OPAC." - - pref: OPACAuthorInformation + - pref: OPACAuthorIdentifiersAndInformation multiple: activity: Activity (372$a$s$t) address: Address (371$a$b$d$e) associated_group: Associated group (373$a$s$t$u$v$0) email_address: Electronic mail address (371$m) + identifiers: Identifiers (024$2$a) occupation: Occupation (374$a$s$t$u$v$0) place_of_birth: Place of birth (370$a) place_of_death: Place of death (370$b) uri: URI (371$u) + - "

Indentifiers: identifiers for authors and contributors to the detail pages in the OPAC." + - "This feature requires authorities with 024$2 and 024$a." + - "Valid source codes in $2 are currently: orcid, scopus, loop, rid and viaf.

" - - "Calculate the amount a patron has 'saved' by using the library based on replacement prices, and display:" - pref: OPACShowSavings diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/includes/authority-identifiers.inc b/koha-tmpl/opac-tmpl/bootstrap/en/includes/authority-identifiers.inc deleted file mode 100644 index 85d68c09be..0000000000 --- a/koha-tmpl/opac-tmpl/bootstrap/en/includes/authority-identifiers.inc +++ /dev/null @@ -1,27 +0,0 @@ -[% SWITCH identifier.source.lower %] -[% CASE 'orcid' %] -
  • - ORCID: - [% identifier.number | html %] -
  • -[% CASE 'scopus' %] -
  • - ScopusID: - [% identifier.number | html %] -
  • -[% CASE 'loop' %] -
  • - loop: - [% identifier.number | html %] -
  • -[% CASE 'rid' %] -
  • - Publons: - [% identifier.number | html %] -
  • -[% CASE 'viaf' %] -
  • - VIAF: - [% identifier.number | html %] -
  • -[% END %] diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/includes/authority-information.inc b/koha-tmpl/opac-tmpl/bootstrap/en/includes/authority-information.inc index 9f1f5c6d71..5e1b748da6 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/includes/authority-information.inc +++ b/koha-tmpl/opac-tmpl/bootstrap/en/includes/authority-information.inc @@ -1,5 +1,25 @@ [% FOREACH info IN information %] [% SWITCH info_type %] + [% CASE 'identifiers' %] +
  • + [% SWITCH info.source.lower %] + [% CASE 'orcid' %] + ORCID: + [% info.number | html %] + [% CASE 'scopus' %] + ScopusID: + [% info.number | html %] + [% CASE 'loop' %] + loop: + [% info.number | html %] + [% CASE 'rid' %] + Publons: + [% info.number | html %] + [% CASE 'viaf' %] + VIAF: + [% info.number | html %] + [% END %] +
  • [% CASE 'activity' %]
  • diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-auth-detail.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-auth-detail.tt index 661a9bc2b2..e5babfd0d6 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-auth-detail.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-auth-detail.tt @@ -38,12 +38,12 @@ [% INCLUDE 'navigation.inc' %] - [% IF Koha.Preference( 'OPACAuthorIdentifiers' ) && author_identifiers.size %] + [% IF Koha.Preference( 'OPACAuthorIdentifiersAndInformation' ) && author_information.size %]
    [% ELSE %]
    [% END %] - [% ELSIF Koha.Preference( 'OPACAuthorIdentifiers' ) && author_identifiers.size %] + [% ELSIF Koha.Preference( 'OPACAuthorIdentifiersAndInformation' ) && author_information.size %]
    [% ELSE %]
    @@ -176,17 +176,17 @@
    - [% IF Koha.Preference( 'OPACAuthorIdentifiers' ) && author_identifiers.size %] + [% IF Koha.Preference( 'OPACAuthorIdentifiersAndInformation' ) && author_information.size %] [% IF ( OpacNav || OpacNavBottom ) %]
    [% ELSE %]
    [% END %] -
    - Identifiers +
    + Identifiers/information
      - [% FOR identifier IN author_identifiers %] - [% PROCESS "authority-identifiers.inc" identifier => identifier %] + [% FOR info IN author_information.keys %] + [% PROCESS "authority-information.inc" information => author_information.$info, info_type => info %] [% END %]
    diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt index 449e4b19f2..3f91b3f2e9 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt @@ -494,14 +494,10 @@ [% END %] [% END %] - [% IF Koha.Preference( 'OPACAuthorIdentifiers' ) && author_identifiers.size || Koha.Preference( 'OPACAuthorInformation' ) && author_information.size %] + [% IF Koha.Preference( 'OPACAuthorIdentifiersAndInformation' ) && author_information.size %] [% WRAPPER tab_item tabname= "author_identifiers_info" %] - [% IF Koha.Preference( 'OPACAuthorIdentifiers' ) && author_identifiers.size && Koha.Preference( 'OPACAuthorInformation' ) && author_information.size %] + [% IF Koha.Preference( 'OPACAuthorIdentifiersAndInformation' ) && author_information.size %] Author identifiers/information - [% ELSIF Koha.Preference( 'OPACAuthorIdentifiers' ) && author_identifiers.size %] - Author identifiers - [% ELSIF Koha.Preference( 'OPACAuthorInformation' ) && author_information.size %] - Author information [% END %] [% END %] [% END %] @@ -948,7 +944,7 @@ [% END # /tab_panel#images %] [% END # / IF OPACLocalCoverImages && localimages.size %] - [% IF Koha.Preference( 'OPACAuthorIdentifiers' ) && author_identifiers.size || Koha.Preference( 'OPACAuthorInformation' ) && author_information.size %] + [% IF Koha.Preference( 'OPACAuthorIdentifiersAndInformation' ) && author_information.size %] [% WRAPPER tab_panel tabname="author_identifiers_info" %] [% FOR author IN author_information %]
    @@ -960,17 +956,6 @@
    [% END %] - - [% FOR author IN author_identifiers %] -
    - [% author.name | html %] -
      - [% FOR identifier IN author.identifiers %] - [% PROCESS "authority-identifiers.inc" identifier => identifier %] - [% END %] -
    -
    - [% END %] [% END # /tab_panel#author_identifiers_info %] [% END %] diff --git a/opac/opac-authoritiesdetail.pl b/opac/opac-authoritiesdetail.pl index 26d22f3a43..c8993d1f01 100755 --- a/opac/opac-authoritiesdetail.pl +++ b/opac/opac-authoritiesdetail.pl @@ -188,10 +188,10 @@ if ($show_marc) { $template->param(summary => $summary); } - if ( C4::Context->preference('OPACAuthorIdentifiers') ) { + if ( C4::Context->preference('OPACAuthorIdentifiersAndInformation') ) { my $authority = Koha::Authorities->find($authid); - my $identifiers = $authority->get_identifiers; - $template->param( author_identifiers => $identifiers ); + my $information = $authority->get_identifiers_and_information; + $template->param( author_information => $information ); } } diff --git a/opac/opac-detail.pl b/opac/opac-detail.pl index 89108c1a93..96c73dd1fc 100755 --- a/opac/opac-detail.pl +++ b/opac/opac-detail.pl @@ -1233,38 +1233,20 @@ $template->param( 'OpacLocationBranchToDisplay' => C4::Context->preference('OpacLocationBranchToDisplay'), ); -if ( C4::Context->preference('OPACAuthorIdentifiers') ) { - my @author_identifiers; - for my $author ( @{ $biblio->get_marc_authors } ) { - my $authid = $author->{authoritylink}; - my $authority = Koha::Authorities->find($authid); - next unless $authority; - my $identifiers = $authority->get_identifiers; - next unless $identifiers && @$identifiers; - my ($name) = - map { $_->{value} } - grep { $_->{code} eq 'a' ? $_ : () } - @{ $author->{MARCAUTHOR_SUBFIELDS_LOOP} }; - push @author_identifiers, - { authid => $authid, name => $name, identifiers => $identifiers }; - } - $template->param( author_identifiers => \@author_identifiers ); -} - -if ( C4::Context->preference('OPACAuthorInformation') ) { +if ( C4::Context->preference('OPACAuthorIdentifiersAndInformation') ) { my @author_information; for my $author ( @{ $biblio->get_marc_authors } ) { my $authid = $author->{authoritylink}; my $authority = Koha::Authorities->find($authid); next unless $authority; - my $information = $authority->get_information; + my $information = $authority->get_identifiers_and_information; next unless $information; my ($name) = map { $_->{value} } grep { $_->{code} eq 'a' ? $_ : () } @{ $author->{MARCAUTHOR_SUBFIELDS_LOOP} }; push @author_information, - { authid => $authid, name => $name, information => $information }; + { authid => $authid, name => $name, information => $information}; } $template->param( author_information => \@author_information ); } diff --git a/t/db_dependent/Koha/Authorities.t b/t/db_dependent/Koha/Authorities.t index 422307c7b9..111a68dbd2 100755 --- a/t/db_dependent/Koha/Authorities.t +++ b/t/db_dependent/Koha/Authorities.t @@ -242,10 +242,11 @@ sub few_marc_records { return [ $marc ]; } -subtest 'get_identifiers' => sub { +subtest 'get_identifiers_and_information' => sub { plan tests => 1; t::lib::Mocks::mock_preference( 'marcflavour', 'MARC21' ); + t::lib::Mocks::mock_preference( 'OPACAuthorIdentifiersAndInformation', 'identifiers' ); my $record = MARC::Record->new(); $record->add_fields( [ @@ -271,17 +272,19 @@ subtest 'get_identifiers' => sub { my $authid = C4::AuthoritiesMarc::AddAuthority($record, undef, 'PERSO_NAME'); my $authority = Koha::Authorities->find($authid); is_deeply( - $authority->get_identifiers, - [ - { - source => 'orcid', - number => '0000-0002-1234-5678', - }, - { - source => 'scopus', - number => '01234567890', - } - ] + $authority->get_identifiers_and_information, + { + identifiers => [ + { + source => 'orcid', + number => '0000-0002-1234-5678', + }, + { + source => 'scopus', + number => '01234567890', + } + ] + } ); }; -- 2.39.5