From d9d9b7f265eba631829c9970d5de5e01ef9abcba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20V=C3=A9ron?= Date: Sun, 26 Apr 2015 07:04:03 +0200 Subject: [PATCH] Bug 14063 - Implement language overlay for authorised values MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This patch implements a language overlay for authorised values. To prepare tests - Have an installation with e.g. English, French and German languages - Set syspref 'suggestion' to: [Allow] patrons to make purchase suggestions on the OPAC. - Verify that you have a authorised values for OPAC_SUG (bestseller, damaged) - Open OPAC, log in, go to Purchase suggestions > Create a new suggesion - The dropdown "Reason for suggestion:" shows the authorised values from OPAC_SUG, e.g. "The copy on the shelf is damaged" and "Upcoming title by popular author" - Select German - The dropdown "Begründung" shows the same (English) values. - Same with French - Open Intranet (Staff client) - Go to Home > Acquisitions > Suggestions management > New purchase suggestion - Switch between languages, the dropdown "Reason for suggestion" changes the label, but the values are not ranslated. - Same with the detail view of a suggestion To test: - In Staff client, go to Home > Administration > Authorized values - Add a new category OPAC_SUG-de-DE (add language code) - Create new translated values 'bestseller' and 'damaged' for this category. - Do the same for French (OPAC_SUG-fr-FR) or other installed languages - Go to OPAC > Purchase suggestions > Create a new suggesion - Switch between languages, the values in the dropdown 'Reason' should display in selected language - Got to Staff client > Home > Acquisitions > Suggestions management > New purchase suggestion - Switch between languages and verify that the values in the dropdown 'Reason' display in selected language - Display a suggestion's detail view, switch languages. Text for 'Reason' should change as appropriate. Bonus test: - Create language overlays e.g. for category 'DAMAGED' (DAMAGED-de-DE and DAMAGED-fr-FR), authorised values 0 -> 'No' and 1 -> 'Damaged' --- C4/Koha.pm | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/C4/Koha.pm b/C4/Koha.pm index 23fbfee..7979b89 100644 --- a/C4/Koha.pm +++ b/C4/Koha.pm @@ -1151,6 +1151,8 @@ sub GetAuthorisedValues { return $result if $result; my @results; + my $lang_results_hash; + my $language = C4::Languages::getlanguage(); my $dbh = C4::Context->dbh; my $query = qq{ SELECT * @@ -1161,13 +1163,17 @@ sub GetAuthorisedValues { } if $branch_limit; my @where_strings; my @where_args; + my @where_args_lang; if($category) { push @where_strings, "category = ?"; push @where_args, $category; + push @where_args_lang, $category.'-'.$language; } + if($branch_limit) { push @where_strings, "( branchcode = ? OR branchcode IS NULL )"; push @where_args, $branch_limit; + push @where_args_lang, $branch_limit; } if(@where_strings > 0) { $query .= " WHERE " . join(" AND ", @where_strings); @@ -1178,10 +1184,23 @@ sub GetAuthorisedValues { : 'lib, lib_opac' ); - my $sth = $dbh->prepare($query); + # Prepare language overlay + my $sth_lang = $dbh->prepare($query); + $sth_lang->execute( @where_args_lang ); + while (my $data_lang=$sth_lang->fetchrow_hashref) { + $lang_results_hash->{$data_lang->{authorised_value}}= $data_lang; + } + $sth_lang->finish; + # Get original values and overlay them if appropriate + my $sth = $dbh->prepare($query); $sth->execute( @where_args ); while (my $data=$sth->fetchrow_hashref) { + #Do language overlay + if (defined $lang_results_hash->{$data->{authorised_value}} ){ + $data = $lang_results_hash->{$data->{authorised_value}}; + } + if ( defined $selected and $selected eq $data->{authorised_value} ) { $data->{selected} = 1; } -- 1.7.10.4