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

(-)a/Koha/Item.pm (-4 / +4 lines)
Lines 938-944 sub last_returned_by_all { Link Here
938
938
939
    my $max_stored_borrowers = C4::Context->preference('StoreLastBorrower') || 0;
939
    my $max_stored_borrowers = C4::Context->preference('StoreLastBorrower') || 0;
940
940
941
    my @borrowers = $self->_result->last_returned_by(
941
    my $last_returned_rs = $self->_result->last_returned_by(
942
        {},
942
        {},
943
        {
943
        {
944
            order_by => [ { '-desc' => 'created_on' }, { '-desc' => 'id' } ],
944
            order_by => [ { '-desc' => 'created_on' }, { '-desc' => 'id' } ],
Lines 946-954 sub last_returned_by_all { Link Here
946
        }
946
        }
947
    );
947
    );
948
948
949
    my @stored_borrowers = map { Koha::Patron->_new_from_dbic( $_->borrowernumber ) } @borrowers;
949
    my $borrowers_rs = $last_returned_rs->search_related('borrowernumber');
950
950
951
    return \@stored_borrowers;
951
    return Koha::Patrons->_new_from_dbic($borrowers_rs);
952
}
952
}
953
953
954
=head3 last_returned_by
954
=head3 last_returned_by
Lines 977-983 sub last_returned_by { Link Here
977
977
978
                # If StoreLastBorrower is 0 or disabled, bail without storing anything. Also delete any remaining rows from the table.
978
                # If StoreLastBorrower is 0 or disabled, bail without storing anything. Also delete any remaining rows from the table.
979
                if ( $max_stored_borrowers == 0 ) {
979
                if ( $max_stored_borrowers == 0 ) {
980
                    $self->_result->last_returned_by->delete_all;
980
                    $self->last_returned_by_all->delete;
981
                    return $self;
981
                    return $self;
982
                }
982
                }
983
983
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/moredetail.tt (-1 / +1 lines)
Lines 496-502 Link Here
496
496
497
                                [% IF Koha.Preference('StoreLastBorrower') && Koha.Preference('StoreLastBorrower') > 0 %]
497
                                [% IF Koha.Preference('StoreLastBorrower') && Koha.Preference('StoreLastBorrower') > 0 %]
498
                                    [% SET all_borrowers = ITEM_DAT.object.last_returned_by_all %]
498
                                    [% SET all_borrowers = ITEM_DAT.object.last_returned_by_all %]
499
                                    [% IF all_borrowers.size > 0 %]
499
                                    [% IF all_borrowers.count > 0 %]
500
                                        <li>
500
                                        <li>
501
                                            <span class="label">Last returned by:</span>
501
                                            <span class="label">Last returned by:</span>
502
                                            [% FOREACH patron IN all_borrowers %]
502
                                            [% FOREACH patron IN all_borrowers %]
(-)a/t/db_dependent/Circulation/StoreLastBorrower.t (-12 / +14 lines)
Lines 153-159 subtest 'Test StoreLastBorrower with multiple borrowers' => sub { Link Here
153
    # Test last_returned_by_all with no borrowers
153
    # Test last_returned_by_all with no borrowers
154
    t::lib::Mocks::mock_preference( 'StoreLastBorrower', '3' );
154
    t::lib::Mocks::mock_preference( 'StoreLastBorrower', '3' );
155
    my $borrowers = $item->last_returned_by_all();
155
    my $borrowers = $item->last_returned_by_all();
156
    is( scalar(@$borrowers), 0, 'last_returned_by_all returns empty array when no borrowers stored' );
156
    is( $borrowers->count, 0, 'last_returned_by_all returns empty set when no borrowers stored' );
157
157
158
    # Add 3 borrowers for testing, checkout/check in
158
    # Add 3 borrowers for testing, checkout/check in
159
    my @patrons;
159
    my @patrons;
Lines 184-195 subtest 'Test StoreLastBorrower with multiple borrowers' => sub { Link Here
184
184
185
    # Test last_returned_by_all returns all borrowers
185
    # Test last_returned_by_all returns all borrowers
186
    $borrowers = $item->last_returned_by_all();
186
    $borrowers = $item->last_returned_by_all();
187
    is( scalar(@$borrowers), 3, 'Correctly returns 3 borrowers' );
187
    is( $borrowers->count, 3, 'Correctly returns 3 borrowers' );
188
188
189
    # Test ordering
189
    # Test ordering
190
    is( $borrowers->[0]->borrowernumber, $patrons[2]->{borrowernumber}, 'Most recent borrower first' );
190
    my @borrowers_array = $borrowers->as_list;
191
    is( $borrowers->[1]->borrowernumber, $patrons[1]->{borrowernumber}, 'Second most recent borrower second' );
191
    is( $borrowers_array[0]->borrowernumber, $patrons[2]->{borrowernumber}, 'Most recent borrower first' );
192
    is( $borrowers->[2]->borrowernumber, $patrons[0]->{borrowernumber}, 'Oldest borrower last' );
192
    is( $borrowers_array[1]->borrowernumber, $patrons[1]->{borrowernumber}, 'Second most recent borrower second' );
193
    is( $borrowers_array[2]->borrowernumber, $patrons[0]->{borrowernumber}, 'Oldest borrower last' );
193
194
194
    # Add 2 more borrowers/check out/check in
195
    # Add 2 more borrowers/check out/check in
195
    for my $i ( 4 .. 5 ) {
196
    for my $i ( 4 .. 5 ) {
Lines 218-227 subtest 'Test StoreLastBorrower with multiple borrowers' => sub { Link Here
218
    $item      = $item->get_from_storage;
219
    $item      = $item->get_from_storage;
219
    $borrowers = $item->last_returned_by_all();
220
    $borrowers = $item->last_returned_by_all();
220
    is(
221
    is(
221
        scalar(@$borrowers), 3,
222
        $borrowers->count, 3,
222
        'We only retain 3 borrowers when the sys pref is set to 3, even though there are 5 checkouts/checkins'
223
        'We only retain 3 borrowers when the sys pref is set to 3, even though there are 5 checkouts/checkins'
223
    );
224
    );
224
    is( $borrowers->[0]->borrowernumber, $patrons[4]->{borrowernumber}, 'Most recent borrower after cleanup' );
225
    @borrowers_array = $borrowers->as_list;
226
    is( $borrowers_array[0]->borrowernumber, $patrons[4]->{borrowernumber}, 'Most recent borrower after cleanup' );
225
227
226
    # Reduce StoreLastBorrower to 2
228
    # Reduce StoreLastBorrower to 2
227
    t::lib::Mocks::mock_preference( 'StoreLastBorrower', '2' );
229
    t::lib::Mocks::mock_preference( 'StoreLastBorrower', '2' );
Lines 250-258 subtest 'Test StoreLastBorrower with multiple borrowers' => sub { Link Here
250
252
251
    $item      = $item->get_from_storage;
253
    $item      = $item->get_from_storage;
252
    $borrowers = $item->last_returned_by_all();
254
    $borrowers = $item->last_returned_by_all();
253
    is( scalar(@$borrowers), 2, 'StoreLastBorrower was reduced to 2, we should now only keep 2 in the table' );
255
    is( $borrowers->count, 2, 'StoreLastBorrower was reduced to 2, we should now only keep 2 in the table' );
256
    @borrowers_array = $borrowers->as_list;
254
    is(
257
    is(
255
        $borrowers->[0]->borrowernumber, $yet_another_patron->{borrowernumber},
258
        $borrowers_array[0]->borrowernumber, $yet_another_patron->{borrowernumber},
256
        'Most recent borrower after limit reduction'
259
        'Most recent borrower after limit reduction'
257
    );
260
    );
258
261
Lines 284-290 subtest 'Test StoreLastBorrower with multiple borrowers' => sub { Link Here
284
287
285
    $item      = $item->get_from_storage;
288
    $item      = $item->get_from_storage;
286
    $borrowers = $item->last_returned_by_all();
289
    $borrowers = $item->last_returned_by_all();
287
    is( scalar(@$borrowers), 0, 'last_returned_by_all respects preference value 0' );
290
    is( $borrowers->count, 0, 'last_returned_by_all respects preference value 0' );
288
291
289
    my $cleanup_patron = $builder->build(
292
    my $cleanup_patron = $builder->build(
290
        {
293
        {
Lines 310-316 subtest 'Test StoreLastBorrower with multiple borrowers' => sub { Link Here
310
313
311
    $item      = $item->get_from_storage;
314
    $item      = $item->get_from_storage;
312
    $borrowers = $item->last_returned_by_all();
315
    $borrowers = $item->last_returned_by_all();
313
    is( scalar(@$borrowers),     0,     'All entries cleared when preference is 0' );
316
    is( $borrowers->count,       0,     'All entries cleared when preference is 0' );
314
    is( $item->last_returned_by, undef, 'last_returned_by returns undef when no records' );
317
    is( $item->last_returned_by, undef, 'last_returned_by returns undef when no records' );
315
318
316
};
319
};
317
- 

Return to bug 26993