From 2476d120004923014c6ba77202eb3fa2a422e3f7 Mon Sep 17 00:00:00 2001 From: Bernardo Gonzalez Kriegel Date: Sat, 26 Apr 2014 08:12:00 -0300 Subject: [PATCH] Bug 12017: 6 - Change syspref AdvancedSearchLanguages Bug 10986 introduces a way of limiting advanced search languages list. It's a good feature, but to fill the preference you need to list iso639_2 codes. And there is no way to get the list of all codes again as before, and language descriptions are taken from database. This patch changes that preference so it's now a Local syspref, to present an interface to set it's value. Also adds another syspref to control if language chooser is limited at all, recovering previous behavior. As per comments on Bug 10986 language list shows translated and native names and is ordered by iso639_2 code To test: 1. Apply the patch 2. Run updatedatabase.pl 3. Go to system preferences, Searching, new syspref LimitAdvancedSearchLanguages, on by default 4. Go to Local use sysprefs, AdvancedSearchLanguages is now here with interface to set it's values 5. Check language limit on advanced search on staff and opac (any theme) 6. Disable limit and chech language list 7. Enable limit and set different languages on syspref, check language list Signed-off-by: Julian FIOL --- C4/Languages.pm | 39 +++++++++++++++++++- catalogue/search.pl | 4 +- ...017-add-syspres-LimitAdvancedSearchLanguage.sql | 24 ++++++++++++ installer/data/mysql/sysprefs.sql | 3 +- .../en/modules/admin/preferences/searching.pref | 10 ++--- .../prog/en/modules/catalogue/advsearch.tt | 4 +- .../bootstrap/en/modules/opac-advsearch.tt | 6 +-- opac/opac-search.pl | 4 +- 8 files changed, 78 insertions(+), 16 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/bug-12017-add-syspres-LimitAdvancedSearchLanguage.sql diff --git a/C4/Languages.pm b/C4/Languages.pm index 9d6529b..e335296 100644 --- a/C4/Languages.pm +++ b/C4/Languages.pm @@ -49,7 +49,7 @@ BEGIN { &getLanguages &getAllLanguages ); - @EXPORT_OK = qw(getLanguagesIso getFrameworkLanguages getTranslatedLanguages getAllLanguages getLanguages get_bidi regex_lang_subtags language_get_description accept_language getlanguage); + @EXPORT_OK = qw(getSearchLanguages getLanguagesIso getFrameworkLanguages getTranslatedLanguages getAllLanguages getLanguages get_bidi regex_lang_subtags language_get_description accept_language getlanguage); $DEBUG = 0; } @@ -106,6 +106,43 @@ sub getFrameworkLanguages { return \@languages; } +=head2 getSearchLanguages + +Get selection of languages codes and iso639_2. +Use sysprefs LimitAdvancedSearchLanguages and AdvancedSearchLanguages, +default to english. + +Returns a reference to an array of hashes: + + my $languages = getSearchLanguages(); + for my $language( @$languages ) { + print "$language->{rfc4646_subtag}\n"; # language code in rfc4646 + print "$language->{iso638_2_code}\n"; # language code in iso 639-2 + } + +=cut + +sub getSearchLanguages { + my $isFiltered = C4::Context->preference("LimitAdvancedSearchLanguages");; + my $language_list = C4::Context->preference("AdvancedSearchLanguages"); + $language_list = 'eng' unless $language_list; + my @languages = split ( /\,/, $language_list ); + my $langs = getLangCodes(); + my @result; + my %enabled; + $enabled{$_}++ for ( @languages ); + + for my $code ( keys %$langs ) { + if (( $isFiltered and $enabled{ $langs->{ $code } } ) or ( not $isFiltered )) { + push @result, { + rfc4646_subtag => $code, + iso639_2_code => $langs->{$code}, + } + } + } + return \@result; +} + =head2 getLanguagesIso Get all languages codes and iso639_2 selected by iso639_2 diff --git a/catalogue/search.pl b/catalogue/search.pl index 4d165ac..03c285d 100755 --- a/catalogue/search.pl +++ b/catalogue/search.pl @@ -144,7 +144,7 @@ use C4::Context; use C4::Output; use C4::Auth qw(:DEFAULT get_session); use C4::Search; -use C4::Languages qw(getLanguages); +use C4::Languages qw(getSearchLanguages); use C4::Koha; use C4::Members qw(GetMember); use C4::VirtualShelves; @@ -346,7 +346,7 @@ if ( $template_type eq 'advsearch' ) { search_boxes_loop => \@search_boxes_array); # load the language limits (for search) - my $languages_limit_loop = getLanguages($lang, 1); + my $languages_limit_loop = getSearchLanguages(); $template->param(search_languages_loop => $languages_limit_loop,); # Expanded search options in advanced search: diff --git a/installer/data/mysql/atomicupdate/bug-12017-add-syspres-LimitAdvancedSearchLanguage.sql b/installer/data/mysql/atomicupdate/bug-12017-add-syspres-LimitAdvancedSearchLanguage.sql new file mode 100644 index 0000000..15981d0 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug-12017-add-syspres-LimitAdvancedSearchLanguage.sql @@ -0,0 +1,24 @@ + +INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type) +VALUES('LimitAdvancedSearchLanguages',1,'If ON, limit language list on advanced search languages.','','YesNo'); + +UPDATE systempreferences SET +type = 'Languages', +explanation = 'ISO 639-2 codes of languages you wish to see appear as an advanced search option' +WHERE variable = 'AdvancedSearchLanguages'; + +-- $DBversion = "3.21.00.XXX"; +-- if ( CheckVersion($DBversion) ) { +-- $dbh->do(q{ +-- INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type) +-- VALUES('LimitAdvancedSearchLanguages',1,'If ON, limit language list on advanced search languages.','','YesNo') +-- }); +-- $dbh->do(q{ +-- UPDATE systempreferences SET type = 'Languages', +-- explanation = 'ISO 639-2 codes of languages you wish to see appear as an advanced search option' +-- WHERE variable = 'AdvancedSearchLanguages' +-- }); +-- +-- print "Upgrade to $DBversion done (Bug 12017 - Add system preferecence LimitAdvancedSearchLanguages)\n"; +-- SetVersion($DBversion); +-- } diff --git a/installer/data/mysql/sysprefs.sql b/installer/data/mysql/sysprefs.sql index 84ba363..954a9d9 100644 --- a/installer/data/mysql/sysprefs.sql +++ b/installer/data/mysql/sysprefs.sql @@ -8,7 +8,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('AcqWarnOnDuplicateInvoice','0','','Warn librarians when they try to create a duplicate invoice','YesNo'), ('AddressFormat','us','','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'), +('AdvancedSearchLanguages','','','ISO 639-2 codes of languages you wish to see appear as an advanced search option','Language'), ('AdvancedSearchTypes','itemtypes','itemtypes|ccode','Select which set of fields comprise the Type limit in the advanced search','Choice'), ('AgeRestrictionMarker','',NULL,'Markers for age restriction indication, e.g. FSK|PEGI|Age|','free'), ('AgeRestrictionOverride','0',NULL,'Allow staff to check out an item with age restriction.','YesNo'), @@ -189,6 +189,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('LibraryThingForLibrariesEnabled','0','','Enable or Disable Library Thing for Libraries Features','YesNo'), ('LibraryThingForLibrariesID','','','See:http://librarything.com/forlibraries/','free'), ('LibraryThingForLibrariesTabbedView','0','','Put LibraryThingForLibraries Content in Tabs.','YesNo'), +('LimitAdvancedSearchLanguages','1','','If ON, limit language list on advanced search languages. To set language list configure AdvancedSearchLanguages local system preference.','YesNo'), ('LinkerKeepStale','0',NULL,'If ON the authority linker will keep existing authority links for headings where it is unable to find a match.','YesNo'), ('LinkerModule','Default','Default|FirstMatch|LastMatch','Chooses which linker module to use (see documentation).','Choice'), ('LinkerOptions','','','A pipe-separated list of options for the linker.','free'), diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/searching.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/searching.pref index 8b04d39..4e11d91 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/searching.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/searching.pref @@ -86,11 +86,11 @@ Searching: - "fields (separate values with |). Tabs appear in the order listed.
" - "Currently supported values: Item types (itemtypes), Collection Codes (ccode) and Shelving Location (loc)." - - - Limit the languages listed in the advanced search drop-down to the - - pref: AdvancedSearchLanguages - class: long - - "ISO 639-2 language codes (separate values with | or ,)." - - "For example, to limit listing to French and Italian, enter ita|fre." + - pref: LimitAdvancedSearchLanguages + choices: + yes: Limit + no: "Don't limit" + - the languages listed in the advanced search drop-down to the ISO 639-2 language codes managed on Local use system preference AdvancedSearchLanguages. - - By default, - pref: expandedSearchOption diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/advsearch.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/advsearch.tt index ff4712b..7867350 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/advsearch.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/advsearch.tt @@ -142,9 +142,9 @@ [% FOREACH search_languages_loo IN search_languages_loop.sort('iso639_2_code') %] [% IF ( search_languages_loo.selected ) %] - + [% ELSE %] - + [% END %] [% END %] diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-advsearch.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-advsearch.tt index 9f856c4..5544491 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-advsearch.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-advsearch.tt @@ -173,11 +173,11 @@ diff --git a/opac/opac-search.pl b/opac/opac-search.pl index 2c4e34e..fec86fb 100755 --- a/opac/opac-search.pl +++ b/opac/opac-search.pl @@ -32,7 +32,7 @@ use List::MoreUtils q/any/; use C4::Output; use C4::Auth qw(:DEFAULT get_session); -use C4::Languages qw(getLanguages); +use C4::Languages qw(getSearchLanguages); use C4::Search; use C4::Search::History; use C4::Biblio; # GetBiblioData @@ -206,7 +206,7 @@ $template->param( ); # load the language limits (for search) -my $languages_limit_loop = getLanguages($lang, 1); +my $languages_limit_loop = getSearchLanguages(); $template->param(search_languages_loop => $languages_limit_loop,); # load the Type stuff -- 1.7.9.5