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

(-)a/C4/ILSDI/Services.pm (-1 / +16 lines)
Lines 478-484 sub GetPatronInfo { Link Here
478
478
479
    # Issues management
479
    # Issues management
480
    if ( $cgi->param('show_loans') && $cgi->param('show_loans') eq "1" ) {
480
    if ( $cgi->param('show_loans') && $cgi->param('show_loans') eq "1" ) {
481
        my $per_page = $cgi->param('loans_per_page');
482
        my $page = $cgi->param('loans_page');
483
481
        my $pending_checkouts = $patron->pending_checkouts;
484
        my $pending_checkouts = $patron->pending_checkouts;
485
486
        if ($page || $per_page) {
487
            $page ||= 1;
488
            $per_page ||= 10;
489
            $borrower->{total_loans} = $pending_checkouts->count();
490
            $pending_checkouts = $pending_checkouts->search(undef, {
491
                rows => $per_page,
492
                page => $page,
493
            });
494
        }
495
482
        my @checkouts;
496
        my @checkouts;
483
        while ( my $c = $pending_checkouts->next ) {
497
        while ( my $c = $pending_checkouts->next ) {
484
            # FIXME We should only retrieve what is needed in the template
498
            # FIXME We should only retrieve what is needed in the template
Lines 489-495 sub GetPatronInfo { Link Here
489
        $borrower->{'loans'}->{'loan'} = \@checkouts;
503
        $borrower->{'loans'}->{'loan'} = \@checkouts;
490
    }
504
    }
491
505
492
    if ( $cgi->param('show_attributes') eq "1" ) {
506
    my $show_attributes = $cgi->param('show_attributes');
507
    if ( $show_attributes && $show_attributes eq "1" ) {
493
        my $attrs = GetBorrowerAttributes( $borrowernumber, 1 );
508
        my $attrs = GetBorrowerAttributes( $borrowernumber, 1 );
494
        $borrower->{'attributes'} = $attrs;
509
        $borrower->{'attributes'} = $attrs;
495
    }
510
    }
(-)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 (-2 / +54 lines)
Lines 19-30 use Modern::Perl; Link Here
19
19
20
use CGI qw ( -utf8 );
20
use CGI qw ( -utf8 );
21
21
22
use Test::More tests => 8;
22
use Test::More tests => 9;
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;
26
26
27
use C4::Items qw( ModItemTransfer );
27
use C4::Items qw( ModItemTransfer );
28
use C4::Circulation;
28
29
29
use Koha::AuthUtils;
30
use Koha::AuthUtils;
30
31
Lines 631-633 subtest 'RenewHold' => sub { Link Here
631
632
632
    $schema->storage->txn_rollback;
633
    $schema->storage->txn_rollback;
633
};
634
};
634
- 
635
636
subtest 'GetPatronInfo paginated loans' => sub {
637
    plan tests => 7;
638
639
    $schema->storage->txn_begin;
640
641
    my $library = $builder->build_object({
642
        class => 'Koha::Libraries',
643
    });
644
645
    my $item1 = $builder->build_sample_item({ library => $library->branchcode });
646
    my $item2 = $builder->build_sample_item({ library => $library->branchcode });
647
    my $item3 = $builder->build_sample_item({ library => $library->branchcode });
648
    my $patron = $builder->build_object({
649
        class => 'Koha::Patrons',
650
        value => {
651
            branchcode => $library->branchcode,
652
        },
653
    });
654
    my $module = new Test::MockModule('C4::Context');
655
    $module->mock('userenv', sub { { branch => $library->branchcode } });
656
    my $date_due = DateTime->now->add(weeks => 2);
657
    my $issue1 = C4::Circulation::AddIssue($patron->unblessed, $item1->barcode, $date_due);
658
    my $date_due1 = Koha::DateUtils::dt_from_string( $issue1->date_due );
659
    my $issue2 = C4::Circulation::AddIssue($patron->unblessed, $item2->barcode, $date_due);
660
    my $date_due2 = Koha::DateUtils::dt_from_string( $issue2->date_due );
661
    my $issue3 = C4::Circulation::AddIssue($patron->unblessed, $item3->barcode, $date_due);
662
    my $date_due3 = Koha::DateUtils::dt_from_string( $issue3->date_due );
663
664
    my $cgi = new CGI;
665
666
    $cgi->param( 'service', 'GetPatronInfo' );
667
    $cgi->param( 'patron_id', $patron->borrowernumber );
668
    $cgi->param( 'show_loans', '1' );
669
    $cgi->param( 'loans_per_page', '2' );
670
    $cgi->param( 'loans_page', '1' );
671
    my $reply = C4::ILSDI::Services::GetPatronInfo($cgi);
672
673
    is($reply->{total_loans}, 3, 'total_loans == 3');
674
    is(scalar @{ $reply->{loans}->{loan} }, 2, 'GetPatronInfo returned only 2 loans');
675
    is($reply->{loans}->{loan}->[0]->{itemnumber}, $item3->itemnumber);
676
    is($reply->{loans}->{loan}->[1]->{itemnumber}, $item2->itemnumber);
677
678
    $cgi->param( 'loans_page', '2' );
679
    $reply = C4::ILSDI::Services::GetPatronInfo($cgi);
680
681
    is($reply->{total_loans}, 3, 'total_loans == 3');
682
    is(scalar @{ $reply->{loans}->{loan} }, 1, 'GetPatronInfo returned only 1 loan');
683
    is($reply->{loans}->{loan}->[0]->{itemnumber}, $item1->itemnumber);
684
685
    $schema->storage->txn_rollback;
686
};

Return to bug 23156