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

(-)a/Koha/Clubs.pm (+26 lines)
Lines 85-90 sub get_enrollable { Link Here
85
    }
85
    }
86
}
86
}
87
87
88
=head3 filter_out_empty
89
90
    Remove clubs without current enrollments.
91
92
=cut
93
94
sub filter_out_empty {
95
    my ($self) = @_;
96
    return $self->search(
97
        {
98
            -and => [
99
                [
100
                    { name        => { like => '%x%' } },
101
                    { description => { like => '%x%' } },
102
                ],
103
                { 'club_enrollments.club_id'       => { '!=' => undef } },
104
                { 'club_enrollments.date_canceled' => undef },
105
            ]
106
        },
107
        {
108
            join     => 'club_enrollments',
109
            distinct => 1,
110
        }
111
    );
112
}
113
88
=head3 type
114
=head3 type
89
115
90
=cut
116
=cut
(-)a/reserve/request.pl (-4 / +2 lines)
Lines 165-174 if($findclub) { Link Here
165
    if( $club ) {
165
    if( $club ) {
166
        $club_hold = $club->id;
166
        $club_hold = $club->id;
167
    } else {
167
    } else {
168
        my @clubs = Koha::Clubs->search( [
168
        my @clubs = Koha::Clubs->search->filter_out_empty;
169
            { name => { like => '%'.$findclub.'%' } },
169
170
            { description => { like => '%'.$findclub.'%' } }
171
        ] );
172
        if( scalar @clubs == 1 ) {
170
        if( scalar @clubs == 1 ) {
173
            $club_hold = $clubs[0]->id;
171
            $club_hold = $clubs[0]->id;
174
        } elsif ( @clubs ) {
172
        } elsif ( @clubs ) {
(-)a/t/db_dependent/Clubs.t (-2 / +69 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 37;
20
use Test::More tests => 38;
21
use Test::Warn;
21
use Test::Warn;
22
22
23
use C4::Context;
23
use C4::Context;
Lines 231-233 is( $patron->get_enrollable_clubs->count, Link Here
231
is( $club->club_enrollments->count, 1, 'There is 1 enrollment for club' );
231
is( $club->club_enrollments->count, 1, 'There is 1 enrollment for club' );
232
232
233
$schema->storage->txn_rollback();
233
$schema->storage->txn_rollback();
234
- 
234
235
subtest 'filter_out_empty' => sub {
236
    plan tests => 2;
237
238
    $schema->storage->txn_begin();
239
240
    Koha::Clubs->delete;
241
242
    my $club_template = $builder->build_object({ class => 'Koha::Club::Templates' });
243
244
    # club_1 has 2 patrons
245
    my $club_1 = $builder->build_object(
246
        {
247
            class => 'Koha::Clubs',
248
            value => { club_template_id => $club_template->id }
249
        }
250
    );
251
252
    # club_2 has 1 patron but they canceled enrollment
253
    my $club_2 = $builder->build_object(
254
        {
255
            class => 'Koha::Clubs',
256
            value => { club_template_id => $club_template->id }
257
        }
258
    );
259
260
    # club_3 is empty
261
    my $club_3 = $builder->build_object(
262
        {
263
            class => 'Koha::Clubs',
264
            value => { club_template_id => $club_template->id }
265
        }
266
    );
267
268
    my $patron_1 = $builder->build_object({ class => 'Koha::Patrons' });
269
    my $patron_2 = $builder->build_object({ class => 'Koha::Patrons' });
270
271
    my $enrollment_1_1 = Koha::Club::Enrollment->new(
272
        {
273
            club_id        => $club_1->id,
274
            borrowernumber => $patron_1->borrowernumber,
275
            branchcode     => $patron_1->branchcode,
276
        }
277
    )->store();
278
    my $enrollment_2_1 = Koha::Club::Enrollment->new(
279
        {
280
            club_id        => $club_2->id,
281
            borrowernumber => $patron_1->borrowernumber,
282
            branchcode     => $patron_1->branchcode,
283
        }
284
    )->store();
285
    my $enrollment_1_2 = Koha::Club::Enrollment->new(
286
        {
287
            club_id        => $club_1->id,
288
            borrowernumber => $patron_2->borrowernumber,
289
            branchcode     => $patron_2->branchcode,
290
        }
291
    )->store();
292
293
294
    $enrollment_2_1->cancel;
295
296
    my $clubs = Koha::Clubs->search->filter_out_empty;
297
    is( $clubs->count, 1, 'Only one club has patron enrolled' );
298
    is( $clubs->next->id, $club_1->id, 'Correct club is considered non-empty');
299
300
    $schema->storage->txn_rollback();
301
}

Return to bug 29736