From 3755a5d01c03ebe043b267c0d239af7a60b67dab Mon Sep 17 00:00:00 2001 From: David Bourgault Date: Fri, 22 Sep 2017 11:29:14 -0400 Subject: [PATCH] Bug 12747 - Corrections on QA feedback C4/Breeding.pm + code in _add_rowdata moved to new subroutine (_add_custom_field_rowdata) - removed useless code Templates: * template use Koha.Preference instead of passed param. Syspref.sql * corrected order - removed unrelated modification to other system preferences --- C4/Breeding.pm | 78 ++++++++++++---------- installer/data/mysql/sysprefs.sql | 3 +- .../prog/en/modules/acqui/z3950_search.tt | 5 +- .../prog/en/modules/cataloguing/z3950_search.tt | 5 +- t/db_dependent/Breeding.t | 2 +- 5 files changed, 49 insertions(+), 44 deletions(-) diff --git a/C4/Breeding.pm b/C4/Breeding.pm index cfa5626..d4f56b2 100644 --- a/C4/Breeding.pm +++ b/C4/Breeding.pm @@ -221,19 +221,11 @@ sub Z3950Search { $oConnection[$_]->destroy(); } - @servers = (); - foreach my $id (@id) { - push @servers, {id => $id}; - } - $template->param( breeding_loop => \@breeding_loop, servers => \@servers, errconn => \@errconn ); - $template->param( - additionalFields => '1' - ) if C4::Context->preference('AdditionalFieldsInZ3950ResultSearch'); } sub _build_query { @@ -348,39 +340,51 @@ sub _add_rowdata { $row->{date}//= $row->{date2}; $row->{isbn}=_isbn_replace($row->{isbn}); - my $pref_addnumber = C4::Context->preference('AdditionalFieldsInZ3950ResultSearch'); + $row = _add_custom_field_rowdata($row, $record); + + return $row; +} + +sub _add_custom_field_rowdata +{ + my ( $row, $record ) = @_; + my $pref_newtags = C4::Context->preference('AdditionalFieldsInZ3950ResultSearch'); + + $pref_newtags =~ s/^\s+|\s+$//g; + $pref_newtags =~ s/\h+/ /g; - $pref_addnumber =~ s/^\s+|\s+$//g; - $pref_addnumber =~ s/\h+/ /g; - my @addnumber_array = split / /, $pref_addnumber; + my @addnumber_array = split / /, $pref_newtags; my @addnumberfields; + foreach (@addnumber_array) { my $length = length($_); - my $adTag = substr($_, 0, 3); - if ($record->field($adTag)) { - my $field = $record->field($adTag); - my $fieldContent=''; - if ($length > 3){ - my $adSubfield; - for (my $i=0; $i<$length-4; $i++){ # 4 because 3 digits, 1 dollar sign ($) - $adSubfield = substr($_, 4+$i, 1); - $fieldContent = $fieldContent.$field->subfield($adSubfield).' '; - } - push(@addnumberfields, $_); - $row->{$_} = $fieldContent; - } - else { - if($adTag <= 10){ - my $data = $field->data(); - push(@addnumberfields, $_); - $row->{$_} = $data; - } - else { - my $subfields_text = $field->as_string(); - push(@addnumberfields, $_); - $row->{$_} = $subfields_text; - } - } + my $adTag = substr( $_, 0, 3 ); + + if ( $record->field($adTag) ) { + my $field = $record->field($adTag); + my $fieldContent = ''; + + if ( $length > 3 ) { + my $adSubfield; + for ( my $i = 4; $i < $length; $i++ ) { # 4 because 3 digits, 1 dollar sign ($) + $adSubfield = substr( $_, $i, 1 ); + $fieldContent = $fieldContent . $field->subfield($adSubfield) . ' '; + } + push( @addnumberfields, $_ ); + $row->{$_} = $fieldContent; + } + else { + if ( $adTag <= 10 ) { + my $data = $field->data(); + push( @addnumberfields, $_ ); + $row->{$_} = $data; + } + else { + my $subfields_text = $field->as_string(); + push( @addnumberfields, $_ ); + $row->{$_} = $subfields_text; + } + } } } diff --git a/installer/data/mysql/sysprefs.sql b/installer/data/mysql/sysprefs.sql index 3f1f558..0e4651e 100644 --- a/installer/data/mysql/sysprefs.sql +++ b/installer/data/mysql/sysprefs.sql @@ -6,9 +6,8 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('AcquisitionDetails', '1', '', 'Hide/Show acquisition details on the biblio detail page.', 'YesNo'), ('AcqViewBaskets','user','user|branch|all','Define which baskets a user is allowed to view: his own only, any within his branch or all','Choice'), ('AcqWarnOnDuplicateInvoice','0','','Warn librarians when they try to create a duplicate invoice','YesNo'), -('AddressFormat','us','','Choose format to display postal addresses', 'Choice'), ('AdditionalFieldsInZ3950ResultSearch', '', NULL, 'Determines which MARC field/subfields are displayed in -Additional field- column in the result of a search Z3950', 'Free'), -('AddPatronLists','categorycode','categorycode|category_type','Allow user to choose what list to pick up from when adding patrons','Choice'), +('AddressFormat','us','us|de|fr','Choose format to display postal addresses', 'Choice'), ('advancedMARCeditor','0','','If ON, the MARC editor won\'t display field/subfield descriptions','YesNo'), ('AdvancedSearchLanguages','','','ISO 639-2 codes of languages you wish to see appear as an Advanced search option. Example: eng|fre|ita','Textarea'), ('AdvancedSearchTypes','itemtypes','itemtypes|ccode','Select which set of fields comprise the Type limit in the advanced search','Choice'), diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/z3950_search.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/z3950_search.tt index 3f8d3b0..b9edb72 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/z3950_search.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/z3950_search.tt @@ -1,3 +1,4 @@ +[% USE Koha %] [% INCLUDE 'doc-head-open.inc' %] Koha › Acquisitions › [% IF ( opsearch ) %]Order from external source[% ELSE %]Order from external source › Search results[% END %] @@ -132,7 +133,7 @@ tr.selected { background-color : #FFFFCC; } tr.selected td { background-color : Author ISBN LCCN - [% IF additionalFields %] + [% IF Koha.Preference('AdditionalFieldsInZ3950ResultSearch') != '' %] Additional fields [% END %] Preview @@ -147,7 +148,7 @@ tr.selected { background-color : #FFFFCC; } tr.selected td { background-color : [% breeding_loo.author %] [% breeding_loo.isbn %] [% breeding_loo.lccn %] - [% IF additionalFields %] + [% IF Koha.Preference('AdditionalFieldsInZ3950ResultSearch') != '' %]
[% FOREACH addnumberfield IN breeding_loo.addnumberfields %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/z3950_search.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/z3950_search.tt index 52c2873..d4813d4 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/z3950_search.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/z3950_search.tt @@ -1,3 +1,4 @@ +[% USE Koha %] [% INCLUDE 'doc-head-open.inc' %] Koha › Z39.50/SRU search results [% INCLUDE 'doc-head-close.inc' %] @@ -144,7 +145,7 @@ tr.selected { background-color : #FFFFCC; } tr.selected td { background-color : Edition ISBN LCCN - [% IF additionalFields %] + [% IF Koha.Preference('AdditionalFieldsInZ3950ResultSearch') != '' %] Additional fields [% END %] MARC @@ -162,7 +163,7 @@ tr.selected { background-color : #FFFFCC; } tr.selected td { background-color : [% breeding_loo.edition %] [% breeding_loo.isbn %] [% breeding_loo.lccn %] - [% IF additionalFields %] + [% IF Koha.Preference('AdditionalFieldsInZ3950ResultSearch') != '' %]
[% FOREACH addnumberfield IN breeding_loo.addnumberfields %] diff --git a/t/db_dependent/Breeding.t b/t/db_dependent/Breeding.t index 8bb4c2a..9856b9a 100755 --- a/t/db_dependent/Breeding.t +++ b/t/db_dependent/Breeding.t @@ -195,7 +195,7 @@ sub test_do_xslt { sub test_add_rowdata { - my $old_preference = C4::Context->preference("AdditionalFieldsInZ3950ResultSearch"); + my $old_preference = C4::Context->preference("AdditionalFieldsInZ3950ResultSearch"); C4::Context->set_preference("AdditionalFieldsInZ3950ResultSearch",""); my $row = { -- 2.7.4