From a8cf3843f52a69fa0fc68582a73cd27f8cfe07b8 Mon Sep 17 00:00:00 2001 From: Alex Buckley Date: Mon, 20 Aug 2018 21:49:43 +1200 Subject: [PATCH] Bug 21249 - New syspref controlling branch fields queried against selected library group value in advanced search This commit allows librarians to choose whether they want to query the homebranch, holdingbranch or homebranch AND holdingbranch when they set a library group search condition in the staff client and OPAC advanced searches. Test plan: 1. Apply patch and run ./updatedatabase.pl in the koha shell 2. Restart memcached and plack 3. In the staff client go to Administration->Global system preferences and search for the systempreference: AdvancedSearchBranchFieldToUse and notice by default it is set to 'homebranch and holdingbranch' 4. Create a library group (if you do not already have one) and add several library branches to the group. 5. Note down the barcode of an item to use for testing searching. Make sure the items homebranch and holdingbranch are different and the items homebranch is a child branch of the library group created in step 4 5. Perform an Advanced search in the staff client and write in the keyword as the barcode of the item and select the library group in the 'Location and availability' section. 6. Submit the search query and notice the item with a homebranch existing in the selected library group is returned. This proves that when the AdvancedSearchBranchFieldToUse syspref is set to 'homebranch and holdingbranch' the homebranch value is checked. Also note at the top of the search result page the search query is listed: Results of search with limit(s): '(homebranch: or holdingbranch: or homebranch: or holdingbranch: )' 7. Now edit the item making sure the homebranch branch is not in the library group, and making sure the holdingbranch is in the library group. This is to test that holdingbranch is indeed being checked when the AdvancedSearchBranchFieldToUse is set to 'AdvancedSearchBranchFieldToUse'. 8. Repeat step 5 and 6 and notice the item with a holdingbranch existing in the selected library group is returned. This proves that when the AdvancedSearchBranchFieldToUse syspref is set to 'homebranch and holdingbranch' the holdingbranch is checked. 9. Change the value of the AdvancedSearchBranchFieldToUse syspref to 'holdingbranch' and repeat step 8 and again notice the item with a holdingbranch existing in the selected library group is returned so we know the holdingbranch is being chcked when the 'holdingbranch' value for the syspref is set. Also note the search query at the top of the page is: "Results of search with limit(s): '(holdingbranch: or holdingbranch: )'" this shows holdingbranch not homebranch is a condition in the query 10. Change the homebranch back to a branch that is in the library group and change the holdingbranch value to a library branch that is not in the library group. 11. Repeat step 5 and 6 and notice the item with the homebranch in the selected library group is returned, so we know the homebranch is being checked when the 'homebranch' value for the syspref is set. Also note the search query at the top of the page is: " Results of search with limit(s): '(homebranch: or homebranch: )'" this shows homebranch not holdingbranch is a condition in the query. Sponsored-By: Brimbank Library --- catalogue/search.pl | 16 +++++++++++++--- ...bug_21249-Branch_to_limit_advanced_search_results.sql | 2 ++ .../prog/en/modules/admin/preferences/searching.pref | 8 ++++++++ opac/opac-search.pl | 12 +++++++++++- 4 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/bug_21249-Branch_to_limit_advanced_search_results.sql diff --git a/catalogue/search.pl b/catalogue/search.pl index e776c7e..e1f6aba 100755 --- a/catalogue/search.pl +++ b/catalogue/search.pl @@ -397,12 +397,22 @@ my @nolimits = map uri_unescape($_), $cgi->multi_param('nolimit'); my %is_nolimit = map { $_ => 1 } @nolimits; @limits = grep { not $is_nolimit{$_} } @limits; +my $branchfield = C4::Context->preference('AdvancedSearchBranchFieldToUse'); + if($params->{'multibranchlimit'}) { my $search_group = Koha::Library::Groups->find( $params->{multibranchlimit} ); my @libraries = $search_group->all_libraries; - my $multihomebranch = '('.join( " or ", map { 'homebranch: ' . $_->id } @libraries ) .')'; - my $multiholdingbranch = '('.join( " or ", map { 'holdingbranch: ' . $_->id } @libraries ) .')'; - push @limits, $multihomebranch . " or " . $multiholdingbranch if ($multihomebranch && $multiholdingbranch ne '()'); + my $multihomebranch = '('.join( " or ", map { 'homebranch: ' . $_->id } @libraries ) .')'; + my $multiholdingbranch = '('.join( " or ", map { 'holdingbranch: ' . $_->id } @libraries ) .')'; + + if ( $branchfield eq "homebranch") { + push @limits, $multihomebranch if ( $multihomebranch ne '()'); + } elsif ( $branchfield eq "holdingbranch") { + push @limits, $multiholdingbranch if ( $multiholdingbranch ne '()'); + } else { + my $multihomeandholdingbranch = '('.join( " or ", map { 'homebranch: ' . $_->id, 'holdingbranch: ' . $_->id} @libraries ) .')'; + push @limits, $multihomeandholdingbranch if ($multihomeandholdingbranch ne '()'); + } } my $available; diff --git a/installer/data/mysql/atomicupdate/bug_21249-Branch_to_limit_advanced_search_results.sql b/installer/data/mysql/atomicupdate/bug_21249-Branch_to_limit_advanced_search_results.sql new file mode 100644 index 0000000..248c469 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_21249-Branch_to_limit_advanced_search_results.sql @@ -0,0 +1,2 @@ +INSERT INTO systempreferences (variable, value, options, explanation, type) VALUES ('AdvancedSearchBranchToLimit', 'homebranch and holdingbranch', 'homebranch|holdingbranch|homebranch and holdingbranch', 'When a library or group of libraries is selected from the advanced search compare the selected branch value against this branch field(s) selected', 'choice'); + 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 ad28e82..ac591a4 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 @@ -151,6 +151,14 @@ Searching: az: from A to Z. za: from Z to A. - + - pref: AdvancedSearchBranchFieldToUse + default: homebranch and holdingbranch + choices: + homebranch: homebranch + holdingbranch: holdingbranch + homebranch and holdingbranch: homebranch and holdingbranch + - When a library or group of libraries is selected from the advanced search compare the selected branch value against this branch field(s) selected + - - pref: displayFacetCount type: boolean default: no diff --git a/opac/opac-search.pl b/opac/opac-search.pl index 04d3c02..71488c2 100755 --- a/opac/opac-search.pl +++ b/opac/opac-search.pl @@ -490,12 +490,22 @@ if (@searchCategories > 0) { @limits = map { uri_unescape($_) } @limits; +my $branchfield = C4::Context->preference('AdvancedSearchBranchFieldToUse'); + if($params->{'multibranchlimit'}) { my $search_group = Koha::Library::Groups->find( $params->{multibranchlimit} ); my @libraries = $search_group->all_libraries; my $multihomebranch = '('.join( " or ", map { 'homebranch: ' . $_->id } @libraries ) .')'; my $multiholdingbranch = '('.join( " or ", map { 'holdingbranch: ' . $_->id } @libraries ) .')'; - push @limits, $multihomebranch . " or " . $multiholdingbranch if ($multihomebranch && $multiholdingbranch ne '()'); + + if ( $branchfield eq "homebranch" ) { + push @limits, $multihomebranch if ( $multihomebranch ne '()'); + } elsif ( $branchfield eq "holdingbranch") { + push @limits, $multiholdingbranch if ( $multiholdingbranch ne '()'); + } else { + my $multihomeandholdingbranch = '('.join( " or ", map { 'homebranch: ' . $_->id, 'holdingbranch: ' . $_->id} @libraries ) .')'; + push @limits, $multihomeandholdingbranch if ($multihomeandholdingbranch ne '()'); + } } my $available; -- 2.1.4