-if ( my $guarantor = $patron->guarantor ) {
- $template->param( guarantor => $guarantor );
- push @relatives, $guarantor->borrowernumber;
- push @relatives, $_->borrowernumber for $patron->siblings;
-} elsif ( $patron->contactname || $patron->contactfirstname ) {
- $template->param(
- guarantor => {
- firstname => $patron->contactfirstname,
- surname => $patron->contactname,
- }
- );
-} else {
- my @guarantees = $patron->guarantees;
- $template->param( guarantees => \@guarantees );
- push @relatives, $_->borrowernumber for @guarantees;
-}
-
-my $relatives_issues_count =
- Koha::Database->new()->schema()->resultset('Issue')
- ->count( { borrowernumber => \@relatives } );
-
-my %bor;
-$bor{'borrowernumber'} = $borrowernumber;
-
-# Converts the branchcode to the branch name
-my $samebranch;
-if ( C4::Context->preference("IndependentBranches") ) {
- if ( C4::Context->IsSuperLibrarian() ) {
- $samebranch = 1;
- }
- else {
- my $userenv = C4::Context->userenv;
- $samebranch = ( $data->{'branchcode'} eq $userenv->{branch} );
- }
+my $guarantor_relationships = $patron->guarantor_relationships;
+my @guarantees = $patron->guarantee_relationships->guarantees;
+my @guarantors = $guarantor_relationships->guarantors;
+if (@guarantors) {
+ push( @relatives, $_->id ) for @guarantors;
+ push( @relatives, $_->id ) for $patron->siblings();