Bugzilla – Attachment 69692 Details for
Bug 16735
Replace existing library search groups functionality with the new hierarchical groups system
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 16735: Use libraries in all subgroups, not just immediate children
Bug-16735-Use-libraries-in-all-subgroups-not-just-.patch (text/plain), 5.95 KB, created by
Tomás Cohen Arazi (tcohen)
on 2017-12-11 16:12:32 UTC
(
hide
)
Description:
Bug 16735: Use libraries in all subgroups, not just immediate children
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2017-12-11 16:12:32 UTC
Size:
5.95 KB
patch
obsolete
>From 78b575aba652c0829c2c4f542125a1e0fb236677 Mon Sep 17 00:00:00 2001 >From: Kyle M Hall <kyle@bywatersolutions.com> >Date: Tue, 8 Aug 2017 12:40:45 -0400 >Subject: [PATCH] Bug 16735: Use libraries in all subgroups, not just immediate > children > >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> >--- > Koha/Library/Group.pm | 31 +++++++++++++++++++++++++++++ > catalogue/search.pl | 2 +- > opac/opac-search.pl | 2 +- > t/db_dependent/LibraryGroups.t | 45 +++++++++++++++++++++++++----------------- > 4 files changed, 60 insertions(+), 20 deletions(-) > >diff --git a/Koha/Library/Group.pm b/Koha/Library/Group.pm >index cc4bd6d831..5ac1360fb9 100644 >--- a/Koha/Library/Group.pm >+++ b/Koha/Library/Group.pm >@@ -117,6 +117,37 @@ sub libraries { > ); > } > >+=head3 all_libraries >+ >+my @libraries = $group->libraries( { [invert => 1] } ); >+ >+Returns the libraries set as children of this group or any subgroup. >+ >+=cut >+ >+sub all_libraries { >+ my ( $self, $params ) = @_; >+ >+ my @libraries; >+ >+ my @children = $self->children; >+ foreach my $c (@children) { >+ if ( $c->branchcode ) { >+ push( @libraries, $c ); >+ } >+ else { >+ push( @libraries, $c->all_libraries ); >+ } >+ } >+ >+ my %seen; >+ @libraries = >+ grep { !$seen{ $_->id }++ } @libraries; >+ >+# return wantarray ? @li : $children; >+ return @libraries; >+} >+ > =head3 libraries_not_direct_children > > my @libraries = $group->libraries_not_direct_children(); >diff --git a/catalogue/search.pl b/catalogue/search.pl >index 6bbfb98c5a..9aba50302f 100755 >--- a/catalogue/search.pl >+++ b/catalogue/search.pl >@@ -404,7 +404,7 @@ my %is_nolimit = map { $_ => 1 } @nolimits; > > if($params->{'multibranchlimit'}) { > my $search_group = Koha::Library::Groups->find( $params->{multibranchlimit} ); >- my @libraries = $search_group->libraries; >+ my @libraries = $search_group->all_libraries; > my $multibranch = '('.join( " or ", map { 'branch: ' . $_->id } @libraries ) .')'; > push @limits, $multibranch if ($multibranch ne '()'); > } >diff --git a/opac/opac-search.pl b/opac/opac-search.pl >index e28a877ef8..2e30efc2ea 100755 >--- a/opac/opac-search.pl >+++ b/opac/opac-search.pl >@@ -492,7 +492,7 @@ if (@searchCategories > 0) { > > if($params->{'multibranchlimit'}) { > my $search_group = Koha::Library::Groups->find( $params->{multibranchlimit} ); >- my @libraries = $search_group->libraries; >+ my @libraries = $search_group->all_libraries; > my $multibranch = '('.join( " or ", map { 'branch: ' . $_->id } @libraries ) .')'; > push @limits, $multibranch if ($multibranch ne '()'); > } >diff --git a/t/db_dependent/LibraryGroups.t b/t/db_dependent/LibraryGroups.t >index c3aef9ff97..52bde2050b 100644 >--- a/t/db_dependent/LibraryGroups.t >+++ b/t/db_dependent/LibraryGroups.t >@@ -4,7 +4,7 @@ use Modern::Perl; > > use List::MoreUtils 'any'; > >-use Test::More tests => 13; >+use Test::More tests => 15; > > use t::lib::TestBuilder; > >@@ -20,26 +20,17 @@ $dbh->{AutoCommit} = 0; > $dbh->{RaiseError} = 1; > > $dbh->do(q|DELETE FROM issues|); >+$dbh->do(q|DELETE FROM library_groups|); > > my $builder = t::lib::TestBuilder->new(); > >-my $library1 = $builder->build( >- { >- source => 'Branch', >- } >-); >- >-my $library2 = $builder->build( >- { >- source => 'Branch', >- } >-); >- >-my $library3 = $builder->build( >- { >- source => 'Branch', >- } >-); >+my $library1 = $builder->build( { source => 'Branch' } ); >+my $library2 = $builder->build( { source => 'Branch' } ); >+my $library3 = $builder->build( { source => 'Branch' } ); >+my $library4 = $builder->build( { source => 'Branch' } ); >+my $library5 = $builder->build( { source => 'Branch' } ); >+my $library6 = $builder->build( { source => 'Branch' } ); >+my $library7 = $builder->build( { source => 'Branch' } ); > > my $root_group = > Koha::Library::Group->new( { title => "Test root group" } )->store(); >@@ -77,3 +68,21 @@ $in_list = any { $_->id eq $groupA_library1->branchcode } @libraries_not_direct_ > ok( !$in_list, 'Method libraries_not_direct_children returns all libraries not direct descendants of group, library 1 is not in the list'); > $in_list = any { $_->id eq $groupA1_library2->branchcode } @libraries_not_direct_children; > ok( $in_list, 'Method libraries_not_direct_children returns all libraries not direct descendants of group, library 2 is in the list'); >+ >+my $groupX = Koha::Library::Group->new( { title => "Group X" } )->store(); >+my $groupX_library1 = Koha::Library::Group->new({ parent_id => $groupX->id, branchcode => $library1->{branchcode} })->store(); >+my $groupX_library2 = Koha::Library::Group->new({ parent_id => $groupX->id, branchcode => $library2->{branchcode} })->store(); >+my $groupX1 = Koha::Library::Group->new({ parent_id => $groupX->id, title => 'Group X1' })->store(); >+my $groupX1_library3 = Koha::Library::Group->new({ parent_id => $groupX1->id, branchcode => $library3->{branchcode} })->store(); >+my $groupX1_library4 = Koha::Library::Group->new({ parent_id => $groupX1->id, branchcode => $library4->{branchcode} })->store(); >+my $groupX2 = Koha::Library::Group->new({ parent_id => $groupX->id, title => 'Group X2' })->store(); >+my $groupX2_library5 = Koha::Library::Group->new({ parent_id => $groupX2->id, branchcode => $library5->{branchcode} })->store(); >+my $groupX2_library6 = Koha::Library::Group->new({ parent_id => $groupX2->id, branchcode => $library6->{branchcode} })->store(); >+ >+my @branchcodes = sort( $library1->{branchcode}, $library2->{branchcode} ); >+my @group_branchcodes = sort( map { $_->branchcode } $groupX->libraries->as_list ); >+is_deeply( \@branchcodes, \@group_branchcodes, "Group libraries are returned correctly" ); >+ >+@branchcodes = sort( $library1->{branchcode}, $library2->{branchcode}, $library3->{branchcode}, $library4->{branchcode}, $library5->{branchcode}, $library6->{branchcode} ); >+@group_branchcodes = sort( map { $_->branchcode } $groupX->all_libraries ); >+is_deeply( \@branchcodes, \@group_branchcodes, "Group all_libraries are returned correctly" ); >-- >2.14.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 16735
:
52732
|
52733
|
52734
|
52735
|
57098
|
57099
|
57100
|
57101
|
58087
|
58088
|
58089
|
58090
|
60497
|
60498
|
60499
|
60500
|
60501
|
60502
|
60503
|
60772
|
60773
|
60774
|
60775
|
60776
|
60777
|
60778
|
60779
|
65658
|
65659
|
65660
|
65661
|
65662
|
65663
|
65664
|
65665
|
69533
|
69534
|
69535
|
69536
|
69537
|
69538
|
69539
|
69540
|
69541
|
69684
|
69685
|
69686
|
69687
|
69688
|
69689
|
69690
|
69691
| 69692 |
69693
|
69694
|
71386
|
71393