Browse Source

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 <f.demians@tamil.fr>

It works as described, both in authority search result page, and in authority
data entry plugin.

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>
3.20.x
Jonathan Druart 9 years ago
committed by Tomas Cohen Arazi
parent
commit
927aedafa1
  1. 56
      C4/AuthoritiesMarc.pm
  2. 13
      koha-tmpl/intranet-tmpl/prog/en/includes/authorities-search-results.inc
  3. 6
      koha-tmpl/intranet-tmpl/prog/en/modules/authorities/searchresultlist-auth.tt
  4. 13
      koha-tmpl/opac-tmpl/bootstrap/en/includes/authorities-search-results.inc
  5. 8
      t/db_dependent/AuthoritiesMarc.t

56
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/<br>/g;
push @repets, $localsummary;
}
$summary{summary} =~ s/\[\Q$textbefore$tag$subtag$textafter\E\]/$value/;
}
$summary{repets} = \@repets;
$summary{summary} =~ s/\\n/<br \/>/g;
}
my @authorized;
my @notes;

13
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 %]
<div class="authres_repet">
[% FOREACH repet IN summary.repets %]
<span>[% repet | html %]</span>
[% UNLESS loop.last %] | [% END %]
[% END %]
</div>
[% IF ( summary.label ) %][% summary.label | html %]:[% END %]
[% IF summary.summary %]
<div class="authority-summary">
[% summary.summary %]
</div>
[% END %]
[% UNLESS ( summary.summaryonly ) %]
<div class="authorizedheading">
[% FOREACH authorize IN summary.authorized %]

6
koha-tmpl/intranet-tmpl/prog/en/modules/authorities/searchresultlist-auth.tt

@ -73,9 +73,9 @@ function doauth(authid, index, repet)
<td>[% PROCESS authresult summary=resul.summary %]</td>
<td>[% resul.used %] times</td>
<td>
[% IF resul.summary && resul.summary.repets && resul.summary.repets.size > 1 %]
[% FOREACH repet IN resul.summary.repets %]
<a href="javascript:doauth('[% resul.authid %]', '[% index %]', '[% loop.count %]')" title="[% repet | html %]">[% loop.count %]</a>
[% IF resul.summary && resul.summary.authorized && resul.summary.authorized.size > 1 %]
[% FOREACH authorized IN resul.summary.authorized %]
<a href="javascript:doauth('[% resul.authid %]', '[% index %]', '[% loop.count %]')" title="[% authorized.heading | html %]">[% loop.count %]</a>
[% END %]
[% ELSE %]
<a href="javascript:doauth('[% resul.authid %]', '[% index %]', '')">choose</a>

13
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 %]
<div class="authres_repet">
[% FOREACH repet IN summary.repets %]
<span>[% repet | html %]</span>
[% UNLESS loop.last %] | [% END %]
[% END %]
</div>
[% IF ( summary.label ) %][% summary.label | html %]:[% END %]
[% IF summary.summary %]
<div class="authority-summary">
[% summary.summary %]
</div>
[% END %]
[% UNLESS ( summary.summaryonly ) %]
<div class="authorizedheading">
[% FOREACH authorize IN summary.authorized %]

8
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'
};

Loading…
Cancel
Save