Bug 14570: Make it possible to add multiple guarantors to a record
[koha.git] / members / moremember.pl
index 33f833e..593b0d1 100755 (executable)
@@ -99,22 +99,20 @@ if ( $patron->is_debarred ) {
 $template->param( flagged => 1 ) if $patron->account_locked;
 
 my @relatives;
-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 $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();
 }
+else {
+    push( @relatives, $_->id ) for @guarantees;
+}
+$template->param(
+    guarantor_relationships => $guarantor_relationships,
+    guarantees              => \@guarantees,
+);
 
 my $relatives_issues_count =
     Koha::Checkouts->count({ borrowernumber => \@relatives });