From 1fa8bc1a0341017f7d893c5cb5f613d309652429 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. Create a subgroup from the library group and add several library branches to the sub 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 of the sub group created in step 4 6. Perform an Advanced search in the staff client and write in the item barcode as the keyword and select the sub group in the 'Location and availability' section. 7. Submit the search query and notice the item with a homebranch existing in the selected sub 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: )' 8. Now edit the item making sure the homebranch branch is not in the sub group, and making sure the holdingbranch is in the sub group. This is to test that holdingbranch is indeed being checked when the AdvancedSearchBranchFieldToUse is set to 'homebranch and holdingbranch' 9. Repeat step 6 and notice the item with a holdingbranch existing in the selected library group is returned. 10. Change the value of the AdvancedSearchBranchFieldToUse syspref to 'holdingbranch' and repeat step 6 and again notice the item with a holdingbranch existing in the selected library group is returned. 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 11. Change the value of the AdvancedSearchBranchFieldToUse syspref to 'homebranch' 12. Change the item homebranch back to a branch that is in the sub group and change the holdingbranch value to a library branch that is not in the sub group. 13. Repeat step 6 and notice the item with the homebranch in the selected library group is returned, so we know the homebranch is being checked. 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 Signed-off-by: Amandine Zocca Signed-off-by: Jonathan Druart --- catalogue/search.pl | 15 +++++++++++++-- .../bug_21249-Branch_to_limit_advanced_search_results.sql | 1 + .../prog/en/modules/admin/preferences/searching.pref | 8 ++++++++ opac/opac-search.pl | 15 +++++++++++++-- 4 files changed, 35 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 89a5211b5c..4a6037de08 100755 --- a/catalogue/search.pl +++ b/catalogue/search.pl @@ -412,11 +412,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 $multibranch = '('.join( " or ", map { 'branch: ' . $_->branchcode } @libraries ) .')'; - push @limits, $multibranch if ($multibranch 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 0000000000..08e6e38e01 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_21249-Branch_to_limit_advanced_search_results.sql @@ -0,0 +1 @@ +INSERT INTO systempreferences (variable, value, options, explanation, type) VALUES ('AdvancedSearchBranchFieldToUse', '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 497447f5aa..e5b16eb945 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 @@ -159,6 +159,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 ea78ca0b23..f98cb51ffa 100755 --- a/opac/opac-search.pl +++ b/opac/opac-search.pl @@ -500,11 +500,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 $multibranch = '('.join( " or ", map { 'branch: ' . $_->branchcode } @libraries ) .')'; - push @limits, $multibranch if ($multibranch 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; -- 2.11.0