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

(-)a/C4/Members.pm (-42 lines)
Lines 444-491 sub GetMember { Link Here
444
    return;
444
    return;
445
}
445
}
446
446
447
=head2 GetMemberRelatives
448
449
 @borrowernumbers = GetMemberRelatives($borrowernumber);
450
451
 C<GetMemberRelatives> returns a borrowersnumber's list of guarantor/guarantees of the member given in parameter
452
453
=cut
454
455
sub GetMemberRelatives {
456
    my $borrowernumber = shift;
457
    my $dbh = C4::Context->dbh;
458
    my @glist;
459
460
    # Getting guarantor
461
    my $query = "SELECT guarantorid FROM borrowers WHERE borrowernumber=?";
462
    my $sth = $dbh->prepare($query);
463
    $sth->execute($borrowernumber);
464
    my $data = $sth->fetchrow_arrayref();
465
    push @glist, $data->[0] if $data->[0];
466
    my $guarantor = $data->[0] ? $data->[0] : undef;
467
468
    # Getting guarantees
469
    $query = "SELECT borrowernumber FROM borrowers WHERE guarantorid=?";
470
    $sth = $dbh->prepare($query);
471
    $sth->execute($borrowernumber);
472
    while ($data = $sth->fetchrow_arrayref()) {
473
       push @glist, $data->[0];
474
    }
475
476
    # Getting sibling guarantees
477
    if ($guarantor) {
478
        $query = "SELECT borrowernumber FROM borrowers WHERE guarantorid=?";
479
        $sth = $dbh->prepare($query);
480
        $sth->execute($guarantor);
481
        while ($data = $sth->fetchrow_arrayref()) {
482
           push @glist, $data->[0] if ($data->[0] != $borrowernumber);
483
        }
484
    }
485
486
    return @glist;
487
}
488
489
=head2 IsMemberBlocked
447
=head2 IsMemberBlocked
490
448
491
  my ($block_status, $count) = IsMemberBlocked( $borrowernumber );
449
  my ($block_status, $count) = IsMemberBlocked( $borrowernumber );
(-)a/Koha/Patron.pm (+25 lines)
Lines 66-71 sub guarantees { Link Here
66
    return Koha::Patrons->search({ guarantorid => $self->borrowernumber });
66
    return Koha::Patrons->search({ guarantorid => $self->borrowernumber });
67
}
67
}
68
68
69
=head3 siblings
70
71
Returns the siblings of this patron.
72
73
=cut
74
75
sub siblings {
76
    my ( $self ) = @_;
77
78
    my $guarantor = $self->guarantor;
79
    my $guarantorid = $guarantor ? $guarantor->borrowernumber : undef;
80
81
    return Koha::Patrons->search(
82
        {
83
            guarantorid => {
84
                '!=' => undef,
85
                '=' => $guarantorid,
86
            },
87
            borrowernumber => {
88
                '!=' => $self->borrowernumber,
89
            }
90
        }
91
    );
92
}
93
69
=head3 type
94
=head3 type
70
95
71
=cut
96
=cut
(-)a/circ/circulation.pl (-1 / +9 lines)
Lines 43-48 use Koha::Holds; Link Here
43
use C4::Context;
43
use C4::Context;
44
use CGI::Session;
44
use CGI::Session;
45
use C4::Members::Attributes qw(GetBorrowerAttributes);
45
use C4::Members::Attributes qw(GetBorrowerAttributes);
46
use Koha::Patron;
46
use Koha::Patron::Debarments qw(GetDebarments IsDebarred);
47
use Koha::Patron::Debarments qw(GetDebarments IsDebarred);
47
use Koha::DateUtils;
48
use Koha::DateUtils;
48
use Koha::Database;
49
use Koha::Database;
Lines 582-588 my $view = $batch Link Here
582
    ?'batch_checkout_view'
583
    ?'batch_checkout_view'
583
    : 'circview';
584
    : 'circview';
584
585
585
my @relatives = GetMemberRelatives( $borrower->{'borrowernumber'} );
586
my $patron = Koha::Patrons->find( $borrower->{borrowernumber} );
587
my @relatives;
588
if ( my $guarantor = $patron->guarantor ) {
589
    push @relatives, $guarantor->borrowernumber;
590
    push @relatives, $_->borrowernumber for $patron->siblings;
591
} else {
592
    push @relatives, $_->borrowernumber for $patron->guarantees;
593
}
586
my $relatives_issues_count =
594
my $relatives_issues_count =
587
  Koha::Database->new()->schema()->resultset('Issue')
595
  Koha::Database->new()->schema()->resultset('Issue')
588
  ->count( { borrowernumber => \@relatives } );
596
  ->count( { borrowernumber => \@relatives } );
(-)a/members/moremember.pl (-10 / +12 lines)
Lines 164-176 if ( $category_type eq 'C') { Link Here
164
}
164
}
165
165
166
my $patron = Koha::Patrons->find($data->{borrowernumber});
166
my $patron = Koha::Patrons->find($data->{borrowernumber});
167
my @guarantees = $patron->guarantees;
167
my @relatives;
168
if ( @guarantees ) {
168
if ( my $guarantor = $patron->guarantor ) {
169
    $template->param( guarantor => $guarantor );
170
    push @relatives, $guarantor->borrowernumber;
171
    push @relatives, $_->borrowernumber for $patron->siblings;
172
} else {
173
    my @guarantees = $patron->guarantees;
169
    $template->param( guarantees => \@guarantees );
174
    $template->param( guarantees => \@guarantees );
175
    push @relatives, $_->borrowernumber for @guarantees;
170
}
176
}
171
elsif ( $patron->guarantorid ) {
177
172
    $template->param( guarantor => $patron->guarantor );
178
my $relatives_issues_count =
173
}
179
  Koha::Database->new()->schema()->resultset('Issue')
180
  ->count( { borrowernumber => \@relatives } );
174
181
175
$template->param( adultborrower => 1 ) if ( $category_type eq 'A' || $category_type eq 'I' );
182
$template->param( adultborrower => 1 ) if ( $category_type eq 'A' || $category_type eq 'I' );
176
183
Lines 219-229 if ( C4::Context->preference('OPACPrivacy') ) { Link Here
219
    $template->param( "privacy".$data->{'privacy'} => 1);
226
    $template->param( "privacy".$data->{'privacy'} => 1);
220
}
227
}
221
228
222
my @relatives = GetMemberRelatives($borrowernumber);
223
my $relatives_issues_count =
224
  Koha::Database->new()->schema()->resultset('Issue')
225
  ->count( { borrowernumber => \@relatives } );
226
227
my $today       = DateTime->now( time_zone => C4::Context->tz);
229
my $today       = DateTime->now( time_zone => C4::Context->tz);
228
$today->truncate(to => 'day');
230
$today->truncate(to => 'day');
229
my $overdues_exist = 0;
231
my $overdues_exist = 0;
(-)a/t/db_dependent/Koha/Patrons.t (-2 / +21 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 4;
22
use Test::More tests => 5;
23
23
24
use Koha::Patron;
24
use Koha::Patron;
25
use Koha::Patrons;
25
use Koha::Patrons;
Lines 77-82 subtest 'guarantees' => sub { Link Here
77
    $_->delete for @guarantees;
77
    $_->delete for @guarantees;
78
};
78
};
79
79
80
subtest 'siblings' => sub {
81
    plan tests => 7;
82
    my $siblings = $new_patron_1->siblings;
83
    is( ref($siblings), 'Koha::Patrons', 'Koha::Patron->siblings should not crashed if the patron has not guarantor' );
84
    my $guarantee_1 = $builder->build( { source => 'Borrower', value => { guarantorid => $new_patron_1->borrowernumber } } );
85
    my $retrieved_guarantee_1 = Koha::Patrons->find($guarantee_1);
86
    $siblings = $retrieved_guarantee_1->siblings;
87
    is( ref($siblings), 'Koha::Patrons', 'Koha::Patron->siblings should return a Koha::Patrons result set in a scalar context' );
88
    my @siblings = $retrieved_guarantee_1->siblings;
89
    is( ref( \@siblings ), 'ARRAY', 'Koha::Patron->siblings should return an array in a list context' );
90
    is( $siblings->count,  0,       'guarantee_1 should not have siblings yet' );
91
    my $guarantee_2 = $builder->build( { source => 'Borrower', value => { guarantorid => $new_patron_1->borrowernumber } } );
92
    my $guarantee_3 = $builder->build( { source => 'Borrower', value => { guarantorid => $new_patron_1->borrowernumber } } );
93
    $siblings = $retrieved_guarantee_1->siblings;
94
    is( $siblings->count,               2,                               'guarantee_1 should have 2 siblings' );
95
    is( $guarantee_2->{borrowernumber}, $siblings->next->borrowernumber, 'guarantee_2 should exist in the guarantees' );
96
    is( $guarantee_3->{borrowernumber}, $siblings->next->borrowernumber, 'guarantee_3 should exist in the guarantees' );
97
    $_->delete for $retrieved_guarantee_1->siblings;
98
    $retrieved_guarantee_1->delete;
99
};
80
100
81
$retrieved_patron_1->delete;
101
$retrieved_patron_1->delete;
82
is( Koha::Patrons->search->count, $nb_of_patrons + 1, 'Delete should have deleted the patron' );
102
is( Koha::Patrons->search->count, $nb_of_patrons + 1, 'Delete should have deleted the patron' );
83
- 

Return to bug 15656