View | Details | Raw Unified | Return to bug 16735
Collapse All | Expand All

(-)a/Koha/Library/Group.pm (+31 lines)
Lines 117-122 sub libraries { Link Here
117
    );
117
    );
118
}
118
}
119
119
120
=head3 all_libraries
121
122
my @libraries = $group->libraries( { [invert => 1] } );
123
124
Returns the libraries set as children of this group or any subgroup.
125
126
=cut
127
128
sub all_libraries {
129
    my ( $self, $params ) = @_;
130
131
    my @libraries;
132
133
    my @children = $self->children;
134
    foreach my $c (@children) {
135
        if ( $c->branchcode ) {
136
            push( @libraries, $c );
137
        }
138
        else {
139
            push( @libraries, $c->all_libraries );
140
        }
141
    }
142
143
    my %seen;
144
    @libraries =
145
      grep { !$seen{ $_->id }++ } @libraries;
146
147
#    return wantarray ? @li : $children;
148
    return @libraries;
149
}
150
120
=head3 libraries_not_direct_children
151
=head3 libraries_not_direct_children
121
152
122
my @libraries = $group->libraries_not_direct_children();
153
my @libraries = $group->libraries_not_direct_children();
(-)a/catalogue/search.pl (-1 / +1 lines)
Lines 404-410 my %is_nolimit = map { $_ => 1 } @nolimits; Link Here
404
404
405
if($params->{'multibranchlimit'}) {
405
if($params->{'multibranchlimit'}) {
406
    my $search_group = Koha::Library::Groups->find( $params->{multibranchlimit} );
406
    my $search_group = Koha::Library::Groups->find( $params->{multibranchlimit} );
407
    my @libraries = $search_group->libraries;
407
    my @libraries = $search_group->all_libraries;
408
    my $multibranch = '('.join( " or ", map { 'branch: ' . $_->id } @libraries ) .')';
408
    my $multibranch = '('.join( " or ", map { 'branch: ' . $_->id } @libraries ) .')';
409
    push @limits, $multibranch if ($multibranch ne  '()');
409
    push @limits, $multibranch if ($multibranch ne  '()');
410
}
410
}
(-)a/opac/opac-search.pl (-1 / +1 lines)
Lines 492-498 if (@searchCategories > 0) { Link Here
492
492
493
if($params->{'multibranchlimit'}) {
493
if($params->{'multibranchlimit'}) {
494
    my $search_group = Koha::Library::Groups->find( $params->{multibranchlimit} );
494
    my $search_group = Koha::Library::Groups->find( $params->{multibranchlimit} );
495
    my @libraries = $search_group->libraries;
495
    my @libraries = $search_group->all_libraries;
496
    my $multibranch = '('.join( " or ", map { 'branch: ' . $_->id } @libraries ) .')';
496
    my $multibranch = '('.join( " or ", map { 'branch: ' . $_->id } @libraries ) .')';
497
    push @limits, $multibranch if ($multibranch ne  '()');
497
    push @limits, $multibranch if ($multibranch ne  '()');
498
}
498
}
(-)a/t/db_dependent/LibraryGroups.t (-19 / +27 lines)
Lines 4-10 use Modern::Perl; Link Here
4
4
5
use List::MoreUtils 'any';
5
use List::MoreUtils 'any';
6
6
7
use Test::More tests => 13;
7
use Test::More tests => 15;
8
8
9
use t::lib::TestBuilder;
9
use t::lib::TestBuilder;
10
10
Lines 20-45 $dbh->{AutoCommit} = 0; Link Here
20
$dbh->{RaiseError} = 1;
20
$dbh->{RaiseError} = 1;
21
21
22
$dbh->do(q|DELETE FROM issues|);
22
$dbh->do(q|DELETE FROM issues|);
23
$dbh->do(q|DELETE FROM library_groups|);
23
24
24
my $builder = t::lib::TestBuilder->new();
25
my $builder = t::lib::TestBuilder->new();
25
26
26
my $library1 = $builder->build(
27
my $library1 = $builder->build( { source => 'Branch' } );
27
    {
28
my $library2 = $builder->build( { source => 'Branch' } );
28
        source => 'Branch',
29
my $library3 = $builder->build( { source => 'Branch' } );
29
    }
30
my $library4 = $builder->build( { source => 'Branch' } );
30
);
31
my $library5 = $builder->build( { source => 'Branch' } );
31
32
my $library6 = $builder->build( { source => 'Branch' } );
32
my $library2 = $builder->build(
33
my $library7 = $builder->build( { source => 'Branch' } );
33
    {
34
        source => 'Branch',
35
    }
36
);
37
38
my $library3 = $builder->build(
39
    {
40
        source => 'Branch',
41
    }
42
);
43
34
44
my $root_group =
35
my $root_group =
45
  Koha::Library::Group->new( { title => "Test root group" } )->store();
36
  Koha::Library::Group->new( { title => "Test root group" } )->store();
Lines 77-79 $in_list = any { $_->id eq $groupA_library1->branchcode } @libraries_not_direct_ Link Here
77
ok( !$in_list, 'Method libraries_not_direct_children returns all libraries not direct descendants of group, library 1 is not in the list');
68
ok( !$in_list, 'Method libraries_not_direct_children returns all libraries not direct descendants of group, library 1 is not in the list');
78
$in_list = any { $_->id eq $groupA1_library2->branchcode } @libraries_not_direct_children;
69
$in_list = any { $_->id eq $groupA1_library2->branchcode } @libraries_not_direct_children;
79
ok( $in_list, 'Method libraries_not_direct_children returns all libraries not direct descendants of group, library 2 is in the list');
70
ok( $in_list, 'Method libraries_not_direct_children returns all libraries not direct descendants of group, library 2 is in the list');
80
- 
71
72
my $groupX = Koha::Library::Group->new( { title => "Group X" } )->store();
73
my $groupX_library1 = Koha::Library::Group->new({ parent_id => $groupX->id,  branchcode => $library1->{branchcode} })->store();
74
my $groupX_library2 = Koha::Library::Group->new({ parent_id => $groupX->id,  branchcode => $library2->{branchcode} })->store();
75
my $groupX1 = Koha::Library::Group->new({ parent_id => $groupX->id, title => 'Group X1' })->store();
76
my $groupX1_library3 = Koha::Library::Group->new({ parent_id => $groupX1->id,  branchcode => $library3->{branchcode} })->store();
77
my $groupX1_library4 = Koha::Library::Group->new({ parent_id => $groupX1->id,  branchcode => $library4->{branchcode} })->store();
78
my $groupX2 = Koha::Library::Group->new({ parent_id => $groupX->id, title => 'Group X2' })->store();
79
my $groupX2_library5 = Koha::Library::Group->new({ parent_id => $groupX2->id,  branchcode => $library5->{branchcode} })->store();
80
my $groupX2_library6 = Koha::Library::Group->new({ parent_id => $groupX2->id,  branchcode => $library6->{branchcode} })->store();
81
82
my @branchcodes = sort( $library1->{branchcode}, $library2->{branchcode} );
83
my @group_branchcodes = sort( map { $_->branchcode } $groupX->libraries->as_list );
84
is_deeply( \@branchcodes, \@group_branchcodes, "Group libraries are returned correctly" );
85
86
@branchcodes = sort( $library1->{branchcode}, $library2->{branchcode}, $library3->{branchcode}, $library4->{branchcode}, $library5->{branchcode}, $library6->{branchcode} );
87
@group_branchcodes = sort( map { $_->branchcode } $groupX->all_libraries );
88
is_deeply( \@branchcodes, \@group_branchcodes, "Group all_libraries are returned correctly" );

Return to bug 16735