From 77d46b7f1a48dda24e9f4f238fc6eda44311b92a 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 or library group search condition in the staff client and OPAC advanced searches. Test plan: 1. Apply patches, update database, restart services 2. Set up a record with one item. Edit the item so that: home branch = Branch A holding/current branch = Branch B. Note the barcode of your item. 3. Go to Administration -> Library Groups. Create a library group that only contains Branch A. = homebranch and holdingbranch = 4. Go to Administration -> System preferences and find the new SearchLimitLibrary syspref. Confirm it is set to 'homebranch and holdingbranch' by default. Keep this tab open. 5. Go to Advanced Search in the staff client in another tab. Under 'location and availability', select your library group from the dropdown. Under 'search for', select the barcode option and enter your item's barcode. 6. Submit the search and confirm you are taken to your item as expected. 7. Go back to Advanced Search. Under 'location and availability', select Branch A from the individual libraries dropdown. Under 'search for', select the barcode option and enter your item's barcode. 8. Submit the search and confirm you are taken to your item as expected. 9. Go back to Advanced Search. Under 'location and availability', select Branch B from the individual libraries dropdown. Under 'search for', select the barcode option and enter your item's barcode. 10. Submit the search and confirm you are taken to your item as expected. = homebranch only = 11. Go back to your System preferences tab. Set the SearchLimitLibrary syspref to 'homebranch'. keep this tab open. 12. Go to Advanced Search in the staff client in another tab. Under 'location and availability', select your library group from the dropdown. Under 'search for', select the barcode option and enter your item's barcode. 13. Submit the search and confirm you are taken to your item as expected, because the syspref is set to homebranch and the library group contains our item's homebranch. 14. Go back to Advanced Search. Under 'location and availability', select Branch A from the individual libraries dropdown. Under 'search for', select the barcode option and enter your item's barcode. 15. Submit the search and confirm you are taken to your item as expected. 16. Go back to Advanced Search. Under 'location and availability', select Branch B from the individual libraries dropdown. Under 'search for', select the barcode option and enter your item's barcode. 17. Submit the search and confirm you are NOT taken to your item and your item does not show in the search results. = holdingbranch only = 18. Go back to your System preferences tab. Set the SearchLimitLibrary syspref to 'holdingbranch'. keep this tab open. 19. Go to Advanced Search in the staff client in another tab. Under 'location and availability', select your library group from the dropdown. Under 'search for', select the barcode option and enter your item's barcode. 20. Submit the search and confirm you are NOT taken to your item and your item does not show in the search results, because the syspref is set to holdingbranch and the library group does not contain our item's holdingbranch. 21. Go back to Advanced Search. Under 'location and availability', select Branch B from the individual libraries dropdown. Under 'search for', select the barcode option and enter your item's barcode. 22. Submit the search and confirm you are taken to your item as expected. 23. Go back to Advanced Search. Under 'location and availability', select Branch A from the individual libraries dropdown. Under 'search for', select the barcode option and enter your item's barcode. 24. Submit the search and confirm you are NOT taken to your item and your item does not show in the search results. 25. Repeat the above test plan but do your searching with the OPAC advanced search. 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 1419759c85..806eb04143 100755 --- a/catalogue/search.pl +++ b/catalogue/search.pl @@ -375,11 +375,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 { '(homebranch: ' . $_->branchcode .')' } @libraries ) .')'; - push @limits, $multibranch if ($multibranch ne '()'); + + if ( $branchfield eq "homebranch") { + my $multihomebranch = '('.join( " OR ", map { 'homebranch: ' . $_->branchcode } @libraries ) .')'; + push @limits, $multihomebranch if ( $multihomebranch ne '()'); + } elsif ( $branchfield eq "holdingbranch") { + my $multiholdingbranch = '('.join( " OR ", map { 'holdingbranch: ' . $_->branchcode } @libraries ) .')'; + push @limits, $multiholdingbranch if ( $multiholdingbranch ne '()'); + } else { + my $multihomeandholdingbranch = '('.join( " OR ", map { 'homebranch: ' . $_->branchcode, 'holdingbranch: ' . $_->branchcode} @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 eaaf56344b..fa8252ddf9 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 @@ -168,6 +168,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 dd0d4884dc..8246c34493 100755 --- a/opac/opac-search.pl +++ b/opac/opac-search.pl @@ -495,11 +495,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 { 'homebranch: ' . $_->branchcode } @libraries ) .')'; - push @limits, $multibranch if ($multibranch ne '()'); + + if ( $branchfield eq "homebranch" ) { + my $multihomebranch = '('.join( " OR ", map { 'homebranch: ' . $_->branchcode } @libraries ) .')'; + push @limits, $multihomebranch if ( $multihomebranch ne '()'); + } elsif ( $branchfield eq "holdingbranch") { + my $multiholdingbranch = '('.join( " OR ", map { 'holdingbranch: ' . $_->branchcode } @libraries ) .')'; + push @limits, $multiholdingbranch if ( $multiholdingbranch ne '()'); + } else { + my $multihomeandholdingbranch = '('.join( " OR ", map { 'homebranch: ' . $_->branchcode, 'holdingbranch: ' . $_->branchcode} @libraries ) .')'; + push @limits, $multihomeandholdingbranch if ($multihomeandholdingbranch ne '()'); + } } my $available; -- 2.11.0