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

(-)a/C4/ILSDI/Services.pm (-1 / +16 lines)
Lines 465-471 sub GetPatronInfo { Link Here
465
465
466
    # Issues management
466
    # Issues management
467
    if ( $cgi->param('show_loans') && $cgi->param('show_loans') eq "1" ) {
467
    if ( $cgi->param('show_loans') && $cgi->param('show_loans') eq "1" ) {
468
        my $per_page = $cgi->param('loans_per_page');
469
        my $page = $cgi->param('loans_page');
470
468
        my $pending_checkouts = $patron->pending_checkouts;
471
        my $pending_checkouts = $patron->pending_checkouts;
472
473
        if ($page || $per_page) {
474
            $page ||= 1;
475
            $per_page ||= 10;
476
            $borrower->{total_loans} = $pending_checkouts->count();
477
            $pending_checkouts = $pending_checkouts->search(undef, {
478
                rows => $per_page,
479
                page => $page,
480
            });
481
        }
482
469
        my @checkouts;
483
        my @checkouts;
470
        while ( my $c = $pending_checkouts->next ) {
484
        while ( my $c = $pending_checkouts->next ) {
471
            # FIXME We should only retrieve what is needed in the template
485
            # FIXME We should only retrieve what is needed in the template
Lines 476-482 sub GetPatronInfo { Link Here
476
        $borrower->{'loans'}->{'loan'} = \@checkouts;
490
        $borrower->{'loans'}->{'loan'} = \@checkouts;
477
    }
491
    }
478
492
479
    if ( $cgi->param('show_attributes') eq "1" ) {
493
    my $show_attributes = $cgi->param('show_attributes');
494
    if ( $show_attributes && $show_attributes eq "1" ) {
480
        my $attrs = GetBorrowerAttributes( $borrowernumber, 1 );
495
        my $attrs = GetBorrowerAttributes( $borrowernumber, 1 );
481
        $borrower->{'attributes'} = $attrs;
496
        $borrower->{'attributes'} = $attrs;
482
    }
497
    }
(-)a/opac/ilsdi.pl (-1 / +1 lines)
Lines 104-110 my %optional = ( Link Here
104
    'GetAuthorityRecords' => ['schema'],
104
    'GetAuthorityRecords' => ['schema'],
105
    'LookupPatron'        => ['id_type'],
105
    'LookupPatron'        => ['id_type'],
106
    'AuthenticatePatron'  => [],
106
    'AuthenticatePatron'  => [],
107
    'GetPatronInfo'       => [ 'show_contact', 'show_fines', 'show_holds', 'show_loans', 'show_attributes' ],
107
    'GetPatronInfo'       => [ 'show_contact', 'show_fines', 'show_holds', 'show_loans', 'loans_per_page', 'loans_page', 'show_attributes' ],
108
    'GetPatronStatus'     => [],
108
    'GetPatronStatus'     => [],
109
    'GetServices'         => [],
109
    'GetServices'         => [],
110
    'RenewLoan'           => ['desired_due_date'],
110
    'RenewLoan'           => ['desired_due_date'],
(-)a/t/db_dependent/ILSDI_Services.t (-3 / +54 lines)
Lines 19-25 use Modern::Perl; Link Here
19
19
20
use CGI qw ( -utf8 );
20
use CGI qw ( -utf8 );
21
21
22
use Test::More tests => 5;
22
use Test::More tests => 6;
23
use Test::MockModule;
23
use Test::MockModule;
24
use t::lib::Mocks;
24
use t::lib::Mocks;
25
use t::lib::TestBuilder;
25
use t::lib::TestBuilder;
Lines 336-339 subtest 'GetRecords' => sub { Link Here
336
    ok($result,'There is a result');
336
    ok($result,'There is a result');
337
337
338
    $schema->storage->txn_rollback;
338
    $schema->storage->txn_rollback;
339
}
339
};
340
341
subtest 'GetPatronInfo paginated loans' => sub {
342
    plan tests => 7;
343
344
    $schema->storage->txn_begin;
345
346
    my $library = $builder->build_object({
347
        class => 'Koha::Libraries',
348
    });
349
350
    my $item1 = $builder->build_sample_item({ library => $library->branchcode });
351
    my $item2 = $builder->build_sample_item({ library => $library->branchcode });
352
    my $item3 = $builder->build_sample_item({ library => $library->branchcode });
353
    my $patron = $builder->build_object({
354
        class => 'Koha::Patrons',
355
        value => {
356
            branchcode => $library->branchcode,
357
        },
358
    });
359
    my $module = new Test::MockModule('C4::Context');
360
    $module->mock('userenv', sub { { branch => $library->branchcode } });
361
    my $date_due = DateTime->now->add(weeks => 2);
362
    my $issue1 = C4::Circulation::AddIssue($patron->unblessed, $item1->barcode, $date_due);
363
    my $date_due1 = Koha::DateUtils::dt_from_string( $issue1->date_due );
364
    my $issue2 = C4::Circulation::AddIssue($patron->unblessed, $item2->barcode, $date_due);
365
    my $date_due2 = Koha::DateUtils::dt_from_string( $issue2->date_due );
366
    my $issue3 = C4::Circulation::AddIssue($patron->unblessed, $item3->barcode, $date_due);
367
    my $date_due3 = Koha::DateUtils::dt_from_string( $issue3->date_due );
368
369
    my $cgi = new CGI;
370
371
    $cgi->param( 'service', 'GetPatronInfo' );
372
    $cgi->param( 'patron_id', $patron->borrowernumber );
373
    $cgi->param( 'show_loans', '1' );
374
    $cgi->param( 'loans_per_page', '2' );
375
    $cgi->param( 'loans_page', '1' );
376
    my $reply = C4::ILSDI::Services::GetPatronInfo($cgi);
377
378
    is($reply->{total_loans}, 3, 'total_loans == 3');
379
    is(scalar @{ $reply->{loans}->{loan} }, 2, 'GetPatronInfo returned only 2 loans');
380
    is($reply->{loans}->{loan}->[0]->{itemnumber}, $item3->itemnumber);
381
    is($reply->{loans}->{loan}->[1]->{itemnumber}, $item2->itemnumber);
382
383
    $cgi->param( 'loans_page', '2' );
384
    $reply = C4::ILSDI::Services::GetPatronInfo($cgi);
385
386
    is($reply->{total_loans}, 3, 'total_loans == 3');
387
    is(scalar @{ $reply->{loans}->{loan} }, 1, 'GetPatronInfo returned only 1 loan');
388
    is($reply->{loans}->{loan}->[0]->{itemnumber}, $item1->itemnumber);
389
390
    $schema->storage->txn_rollback;
391
};
340
- 

Return to bug 23156