From 8606b25eb477e0fb1ee40a16126358b251610161 Mon Sep 17 00:00:00 2001 From: charles Date: Thu, 23 Apr 2015 11:25:56 -0400 Subject: [PATCH] Bug 12747 - Add extra column in Z3950 search This is a complete squash of previous patches, with additional code quality improvments following M. Tompsett's feedback. Squashing was done (as suggested) because many lines add be added and subsequently deleted, which made for confusing patches. New changes: * Major enhancement to _add_custom_rowdata(), as suggested by QA. The $_ variable is no longer used (at all), and the split() routine is used. * t/db_dependent/Breeding.t now uses the mocked preference logic to avoid sysprefs being affected. Functionality and test plan have not changed. -- This patch makes it possible to add an extra column to Z3950 search results. The system preference AdditionalFieldsInZ3950ResultSearch maps which MARC field/subfields are displayed in the column. Testing: I Apply the patch II Run updatedatabase.pl ACQUISITIONS 0) Enter a field/subfield in the AdditionalFieldsInZ3950ResultSearch 1) Create a new basket or use an existing one 2) In -Add order to basket-, click "From an external source" 3) Select some search targets and enter a subject heading ex. house 4) Click Search bouton 5) Validate "Additional fields" column with the field/subfield value. CATALOGUING 0) Shares same syspref as above 1) Go to cataloguing, click New from z3950 2) Fill to result in a successful search 3) Validate column Addition Fields Sponsored-by: CCSR (https://ccsr.qc.ca) --- C4/Breeding.pm | 41 ++++++++++++++++++++ ...47-additional_fields_in_Z3950_search_result.sql | 1 + installer/data/mysql/sysprefs.sql | 1 + .../prog/en/modules/acqui/z3950_search.tt | 20 +++++++++- .../en/modules/admin/preferences/cataloguing.pref | 4 ++ .../prog/en/modules/cataloguing/z3950_search.tt | 23 ++++++++++- t/db_dependent/Breeding.t | 44 +++++++++++++++++++++- 7 files changed, 129 insertions(+), 5 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/bug_12747-additional_fields_in_Z3950_search_result.sql mode change 100644 => 100755 t/db_dependent/Breeding.t diff --git a/C4/Breeding.pm b/C4/Breeding.pm index 060d3f4..a7b5f99 100644 --- a/C4/Breeding.pm +++ b/C4/Breeding.pm @@ -25,6 +25,7 @@ use C4::Biblio; use C4::Koha; use C4::Charset; use MARC::File::USMARC; +use MARC::Field; use C4::ImportBatch; use C4::AuthoritiesMarc; #GuessAuthTypeCode, FindDuplicateAuthority use C4::Languages; @@ -336,6 +337,46 @@ sub _add_rowdata { } $row->{date}//= $row->{date2}; $row->{isbn}=_isbn_replace($row->{isbn}); + + $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; + + my @addnumberfields; + + foreach my $field (split / /, $pref_newtags) { + my ($tag, $subtags) = split(/\$/, $field); + + if ( $record->field($tag) ) { + my $marcfield = $record->field($tag); + + if ( $subtags ) { + my $content = ''; + for my $code (split //, $subtags) { + $content .= $marcfield->subfield($code) . ' '; + } + + $row->{$field} = $content; + } elsif ( $tag <= 10 ) { + $row->{$field} = $marcfield->data(); + } else { + $row->{$field} = $marcfield->as_string(); + } + push( @addnumberfields, $field ); + } + } + + $row->{'addnumberfields'} = \@addnumberfields; + return $row; } diff --git a/installer/data/mysql/atomicupdate/bug_12747-additional_fields_in_Z3950_search_result.sql b/installer/data/mysql/atomicupdate/bug_12747-additional_fields_in_Z3950_search_result.sql new file mode 100644 index 0000000..d60bed3 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_12747-additional_fields_in_Z3950_search_result.sql @@ -0,0 +1 @@ +INSERT IGNORE INTO systempreferences (variable,value,options,explanation,type) VALUES ('AdditionalFieldsInZ3950ResultSearch', '', 'NULL', 'Determines which MARC field/subfields are displayed in -Additional field- column in the result of a search Z3950', 'Free'); diff --git a/installer/data/mysql/sysprefs.sql b/installer/data/mysql/sysprefs.sql index 76bb2cc..79f5893 100644 --- a/installer/data/mysql/sysprefs.sql +++ b/installer/data/mysql/sysprefs.sql @@ -6,6 +6,7 @@ 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'), +('AdditionalFieldsInZ3950ResultSearch', '', NULL, 'Determines which MARC field/subfields are displayed in -Additional field- column in the result of a search Z3950', 'Free'), ('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'), 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 7c33a1a..9bf0bb4 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 @@ -3,6 +3,9 @@ Koha › Acquisitions › [% IF ( opsearch ) %]Order from external source[% ELSE %]Order from external source › Search results[% END %] [% INCLUDE 'doc-head-close.inc' %] +[% INCLUDE 'datatables.inc' %] +[% USE Koha %] +