From f6e86dc0cab2bcd4e8477f639fd600d27d387180 Mon Sep 17 00:00:00 2001 From: David Bourgault Date: Fri, 4 May 2018 15:38:11 -0400 Subject: [PATCH] Bug 12747: Add extra column in Z3950 search MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This patch makes it possible to add an extra column to Z3950 search results. The system preference AdditionalFieldsInZ3950ResultSearch decides 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 prove t/db_dependent/Breeding.t Sponsored-by: CCSR (https://ccsr.qc.ca) Signed-off-by: Katrin Fischer Signed-off-by: Séverine QUEUNE Signed-off-by: Katrin Fischer Signed-off-by: Nick Clemens --- C4/Breeding.pm | 57 ++++++++++++++++++- ...ditional_fields_in_Z3950_search_result.sql | 1 + installer/data/mysql/sysprefs.sql | 1 + .../prog/en/modules/acqui/z3950_search.tt | 18 ++++++ .../admin/preferences/cataloguing.pref | 4 ++ .../en/modules/cataloguing/z3950_search.tt | 17 +++++- t/db_dependent/Breeding.t | 50 +++++++++++++++- 7 files changed, 143 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 fc539d0044..3899b38436 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; @@ -355,15 +356,65 @@ sub _add_rowdata { author => 'biblio.author', isbn =>'biblioitems.isbn', lccn =>'biblioitems.lccn', #LC control number (not call number) - edition =>'biblioitems.editionstatement', - date => 'biblio.copyrightdate', #MARC21 - date2 => 'biblioitems.publicationyear', #UNIMARC + edition =>'biblioitems.editionstatement' ); + $fetch{date} = C4::Context->preference('marcflavour') eq "MARC21" ? 'biblio.copyrightdate' : 'biblioitems.publicationyear'; + foreach my $k (keys %fetch) { $row->{$k} = C4::Biblio::TransformMarcToKohaOneField( $fetch{$k}, $record ); } $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) { + $field =~ s/^\s+|\s+$//g ; # trim whitespace + my ($tag, $subtags) = split(/\$/, $field); + + if ( $record->field($tag) ) { + my @content = (); + + for my $marcfield ($record->field($tag)) { + if ( $subtags ) { + my $str = ''; + for my $code (split //, $subtags) { + if ( $marcfield->subfield($code) ) { + $str .= $marcfield->subfield($code) . ' '; + } + } + if ( not $str eq '') { + push @content, $str; + } + } elsif ( $tag <= 10 ) { + push @content, $marcfield->data(); + } else { + push @content, $marcfield->as_string(); + } + } + + if ( @content ) { + $row->{$field} = \@content; + 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 0000000000..d60bed3f9d --- /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 a08ff3e5c8..e51ba36f0f 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 6ceb352665..fabc4921cc 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 @@ -5,6 +5,9 @@ Koha › Acquisitions › [% IF ( opsearch ) %]Order from external source[% ELSE %]Order from external source › Search results[% END %] [% Asset.css("css/datatables.css") | $raw %] [% INCLUDE 'doc-head-close.inc' %] +[% INCLUDE 'datatables.inc' %] +[% USE Koha %] +