From fc9beb952417fd1a9d3682255849b91c55b49ca7 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 2 Oct 2013 14:16:09 +0200 Subject: [PATCH] [PASSED QA] Bug 10985: [UNIMARC] Fix authority summary The problem is the template in authority type summary is not respected at all. It is only read to see which fields and subfields should appear in the summary. This patch fixes that. It also fixes a bug in auth_finder.pl plugin when summary contains fields other than 2XX. Test plan: 0/ You must use a UNIMARC setup for those tests 1/ edit an authority type summary with: NP : [200a][, 200b][ 200d][-- 152b --][ ; 200c][ (200f)] [001*] [ppn: 009*] 2/ create a new authority with previous fields (it is possible some fields don't exist). 3/ search this authority and verify the summary is someting like: NP : Name, D.-- NP -- 23849 ppn: my_ppn 4/ Verify some summary for existing authorities and check they are correct. 5/ Edit a biblio record and use the plugin auth_finder.pl (for example in a 7XX field) 6/ Do a search and verify the summary is correct 7/ Click on 'choose' or one of the numbered links ('1', '2', ... ; you should have multiple 2XX fields for the numbered links to show up) 8/ Verify that the biblio field is correctly filled. /!\ For the ppn, it should be defined in the zebra indexes. In MARC21 and NORMARC setups, this patch should change nothing, please verify that too (you can check that the auth_finder.pl plugin is still working and the auth type summary is correctly displayed in authorities search and auth_finder.pl plugin). Signed-off-by: Frederic Demians It works as described, both in authority search result page, and in authority data entry plugin. Signed-off-by: Katrin Fischer --- C4/AuthoritiesMarc.pm | 56 ++++++++++++---------- .../en/includes/authorities-search-results.inc | 13 +++-- .../modules/authorities/searchresultlist-auth.tt | 6 +-- .../en/includes/authorities-search-results.inc | 13 +++-- t/db_dependent/AuthoritiesMarc.t | 8 ++-- 5 files changed, 49 insertions(+), 47 deletions(-) diff --git a/C4/AuthoritiesMarc.pm b/C4/AuthoritiesMarc.pm index 4860eba..03b0b51 100644 --- a/C4/AuthoritiesMarc.pm +++ b/C4/AuthoritiesMarc.pm @@ -908,6 +908,8 @@ sub BuildSummary { # for MARC21, the authority type summary displays a label meant for # display if (C4::Context->preference('marcflavour') ne 'UNIMARC') { + $summary{label} = $authref->{summary}; + } else { $summary{summary} = $authref->{summary}; } } @@ -942,35 +944,37 @@ sub BuildSummary { # suit the MARC21 version, so for now the "templating" # feature will be enabled only for UNIMARC for backwards # compatibility. - if ($summary_template and C4::Context->preference('marcflavour') eq 'UNIMARC') { - my @fields = $record->fields(); -# $reported_tag = '$9'.$result[$counter]; - my @repets; - foreach my $field (@fields) { - my $tag = $field->tag(); - my $tagvalue = $field->as_string(); - my $localsummary= $summary_template; - $localsummary =~ s/\[(.?.?.?.?)$tag\*(.*?)\]/$1$tagvalue$2\[$1$tag$2\]/g; - if ($tag<10) { - if ($tag eq '001') { - $reported_tag.='$3'.$field->data(); - } - } else { - my @subf = $field->subfields; - for my $i (0..$#subf) { - my $subfieldcode = $subf[$i][0]; - my $subfieldvalue = $subf[$i][1]; - my $tagsubf = $tag.$subfieldcode; - $localsummary =~ s/\[(.?.?.?.?)$tagsubf(.*?)\]/$1$subfieldvalue$2\[$1$tagsubf$2\]/g; + if ($summary{summary} and C4::Context->preference('marcflavour') eq 'UNIMARC') { + my @matches = ($summary{summary} =~ m/\[(.*?)(\d{3})([\*a-z0-9])(.*?)\]/g); + my (@textbefore, @tag, @subtag, @textafter); + for(my $i = 0; $i < scalar @matches; $i++){ + push @textbefore, $matches[$i] if($i%4 == 0); + push @tag, $matches[$i] if($i%4 == 1); + push @subtag, $matches[$i] if($i%4 == 2); + push @textafter, $matches[$i] if($i%4 == 3); + } + for(my $i = scalar @tag; $i >= 0; $i--){ + my $textbefore = $textbefore[$i] || ''; + my $tag = $tag[$i] || ''; + my $subtag = $subtag[$i] || ''; + my $textafter = $textafter[$i] || ''; + my $value = ''; + my $field = $record->field($tag); + if ( $field ) { + if($subtag eq '*') { + if($tag < 10) { + $value = $textbefore . $field->data() . $textafter; + } + } else { + my @subfields = $field->subfield($subtag); + if(@subfields > 0) { + $value = $textbefore . join (" - ", @subfields) . $textafter; + } } } - if ($localsummary ne $summary_template) { - $localsummary =~ s/\[(.*?)\]//g; - $localsummary =~ s/\n/
/g; - push @repets, $localsummary; - } + $summary{summary} =~ s/\[\Q$textbefore$tag$subtag$textafter\E\]/$value/; } - $summary{repets} = \@repets; + $summary{summary} =~ s/\\n/
/g; } my @authorized; my @notes; diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/authorities-search-results.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/authorities-search-results.inc index ceff1a4..a009c7d 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/authorities-search-results.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/authorities-search-results.inc @@ -50,13 +50,12 @@ [% END %] [% END %] [% BLOCK authresult %] - [% IF ( summary.summary ) %][% summary.summary | html %]:[% END %] -
- [% FOREACH repet IN summary.repets %] - [% repet | html %] - [% UNLESS loop.last %] | [% END %] - [% END %] -
+ [% IF ( summary.label ) %][% summary.label | html %]:[% END %] + [% IF summary.summary %] +
+ [% summary.summary %] +
+ [% END %] [% UNLESS ( summary.summaryonly ) %]
[% FOREACH authorize IN summary.authorized %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/searchresultlist-auth.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/searchresultlist-auth.tt index 898de87..fd2e92b 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/searchresultlist-auth.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/searchresultlist-auth.tt @@ -73,9 +73,9 @@ function doauth(authid, index, repet) [% PROCESS authresult summary=resul.summary %] [% resul.used %] times - [% IF resul.summary && resul.summary.repets && resul.summary.repets.size > 1 %] - [% FOREACH repet IN resul.summary.repets %] - [% loop.count %] + [% IF resul.summary && resul.summary.authorized && resul.summary.authorized.size > 1 %] + [% FOREACH authorized IN resul.summary.authorized %] + [% loop.count %] [% END %] [% ELSE %] choose diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/includes/authorities-search-results.inc b/koha-tmpl/opac-tmpl/bootstrap/en/includes/authorities-search-results.inc index c378817..043556d 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/includes/authorities-search-results.inc +++ b/koha-tmpl/opac-tmpl/bootstrap/en/includes/authorities-search-results.inc @@ -50,13 +50,12 @@ [% END # / BLOCK showreference %] [% BLOCK authresult %] - [% IF ( summary.summary ) %][% summary.summary | html %]:[% END %] -
- [% FOREACH repet IN summary.repets %] - [% repet | html %] - [% UNLESS loop.last %] | [% END %] - [% END %] -
+ [% IF ( summary.label ) %][% summary.label | html %]:[% END %] + [% IF summary.summary %] +
+ [% summary.summary %] +
+ [% END %] [% UNLESS ( summary.summaryonly ) %]
[% FOREACH authorize IN summary.authorized %] diff --git a/t/db_dependent/AuthoritiesMarc.t b/t/db_dependent/AuthoritiesMarc.t index bc4adeb..f432a5d 100755 --- a/t/db_dependent/AuthoritiesMarc.t +++ b/t/db_dependent/AuthoritiesMarc.t @@ -61,6 +61,8 @@ my $dbh = C4::Context->dbh; $dbh->{AutoCommit} = 0; $dbh->{RaiseError} = 1; +t::lib::Mocks::mock_preference('marcflavour', 'MARC21'); + is(BuildAuthHierarchies(3, 1), '1,2,3', "Built linked authtrees hierarchy string"); my $expectedhierarchy = [ [ { @@ -135,7 +137,7 @@ my $expected_marc21_summary = { } ], 'seefrom' => [], - 'summary' => 'Geographic Name', + 'label' => 'Geographic Name', 'type' => 'Geographic Name' }; is_deeply( @@ -178,9 +180,7 @@ my $expected_unimarc_name_summary = { 'otherscript' => [], 'seealso' => [], 'seefrom' => [], - 'repets' => [ - 'Fossey, Brigitte' - ], + 'summary' => 'Fossey, Brigitte', 'type' => 'Auteur' }; -- 1.9.1