From 2e2b88754462325f11393b019d8aa335f4be5e1e 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 --- C4/Languages.pm | 39 +++++++++++++++++++++- catalogue/search.pl | 4 +-- installer/data/mysql/sysprefs.sql | 3 +- installer/data/mysql/updatedatabase.pl | 16 +++++++++ .../en/modules/admin/preferences/searching.pref | 10 +++--- .../prog/en/modules/catalogue/advsearch.tt | 6 ++-- .../bootstrap/en/modules/opac-advsearch.tt | 6 ++-- .../opac-tmpl/prog/en/modules/opac-advsearch.tt | 4 +-- opac/opac-search.pl | 4 +-- 9 files changed, 73 insertions(+), 19 deletions(-) diff --git a/C4/Languages.pm b/C4/Languages.pm index f2e4b3b..71d3220 100644 --- a/C4/Languages.pm +++ b/C4/Languages.pm @@ -49,7 +49,7 @@ BEGIN { &getLanguages &getAllLanguages ); - @EXPORT_OK = qw(getLanguages_iso getFrameworkLanguages getTranslatedLanguages getAllLanguages getLanguages get_bidi regex_lang_subtags language_get_description accept_language getlanguage); + @EXPORT_OK = qw(getSearchLanguages getLanguages_iso 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 getLanguages_iso Get all languages codes and iso639_2 selected by iso639_2 diff --git a/catalogue/search.pl b/catalogue/search.pl index dbb75ca..59858ff 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; @@ -344,7 +344,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/sysprefs.sql b/installer/data/mysql/sysprefs.sql index ed427ea..1994ba8 100644 --- a/installer/data/mysql/sysprefs.sql +++ b/installer/data/mysql/sysprefs.sql @@ -7,7 +7,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('AcqWarnOnDuplicateInvoice','0','','Warn librarians when they try to create a duplicate invoice','YesNo'), ('AddPatronLists','categorycode','categorycode|category_type','Allow user to choose what list to pick up from when adding patrons','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'), @@ -175,6 +175,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/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index 1030454..84cc5aa 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -8570,6 +8570,22 @@ if ( CheckVersion($DBversion) ) { SetVersion($DBversion); } +$DBversion = "3.17.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); +} + =head1 FUNCTIONS =head2 TableExists($table) 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 eee5cc9..1f6012e 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 c982eb4..ecb9d9f 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/advsearch.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/advsearch.tt @@ -139,11 +139,11 @@

- [% FOREACH search_languages_loo IN search_languages_loop %] + [% 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/prog/en/modules/opac-advsearch.tt b/koha-tmpl/opac-tmpl/prog/en/modules/opac-advsearch.tt index 04ab78c..4185357 100644 --- a/koha-tmpl/opac-tmpl/prog/en/modules/opac-advsearch.tt +++ b/koha-tmpl/opac-tmpl/prog/en/modules/opac-advsearch.tt @@ -204,9 +204,9 @@ [% FOREACH search_languages_loo IN search_languages_loop %] [% IF ( search_languages_loo.selected ) %] - + [% ELSE %] - + [% END %] [% END %]

diff --git a/opac/opac-search.pl b/opac/opac-search.pl index 3b37b43..40957f7 100755 --- a/opac/opac-search.pl +++ b/opac/opac-search.pl @@ -40,7 +40,7 @@ if ( $searchengine =~ /^Solr$/ ) { 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 @@ -198,7 +198,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.9.1