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

(-)a/Koha/Patron.pm (-1 / +72 lines)
Lines 46-51 use Koha::Encryption; Link Here
46
use Koha::Exceptions;
46
use Koha::Exceptions;
47
use Koha::Exceptions::Password;
47
use Koha::Exceptions::Password;
48
use Koha::Exceptions::HoldGroup;
48
use Koha::Exceptions::HoldGroup;
49
use Koha::Exceptions::PatronAccountLink;
49
use Koha::Holds;
50
use Koha::Holds;
50
use Koha::HoldGroups;
51
use Koha::HoldGroups;
51
use Koha::ILL::Requests;
52
use Koha::ILL::Requests;
Lines 704-709 sub linked_accounts_debt { Link Here
704
    return $total;
705
    return $total;
705
}
706
}
706
707
708
=head3 linked_account_links
709
710
    my $links = $patron->linked_account_links;
711
712
Returns all AccountLinks in this patron's link group as a Koha::Patron::AccountLinks
713
resultset, or undef if patron is not linked.
714
715
=cut
716
717
sub linked_account_links {
718
    my ($self) = @_;
719
720
    my $link = $self->account_link;
721
    return unless $link;
722
723
    return Koha::Patron::AccountLinks->search( { link_group_id => $link->link_group_id } );
724
}
725
726
=head3 link_to_patron
727
728
    my $link = $patron->link_to_patron( $other_patron );
729
730
Links this patron to another patron's account. Handles group creation/joining.
731
Returns the patron's AccountLink object.
732
733
Throws:
734
    Koha::Exceptions::PatronAccountLink::AlreadyLinked
735
    Koha::Exceptions::PatronAccountLink::DifferentGroups
736
737
=cut
738
739
sub link_to_patron {
740
    my ( $self, $other_patron ) = @_;
741
742
    my $own_link   = $self->account_link;
743
    my $other_link = $other_patron->account_link;
744
745
    # Both already linked to same group
746
    if ( $own_link && $other_link && $own_link->link_group_id == $other_link->link_group_id ) {
747
        Koha::Exceptions::PatronAccountLink::AlreadyLinked->throw();
748
    }
749
750
    # Both belong to different groups
751
    if ( $own_link && $other_link ) {
752
        Koha::Exceptions::PatronAccountLink::DifferentGroups->throw();
753
    }
754
755
    # Determine group ID
756
    my $link_group_id;
757
    if ($own_link) {
758
        $link_group_id = $own_link->link_group_id;
759
    } elsif ($other_link) {
760
        $link_group_id = $other_link->link_group_id;
761
    } else {
762
        $link_group_id = Koha::Patron::AccountLinks->get_next_group_id();
763
    }
764
765
    # Create missing links
766
    unless ($own_link) {
767
        Koha::Patron::AccountLink->new( { link_group_id => $link_group_id, borrowernumber => $self->borrowernumber } )
768
            ->store;
769
    }
770
771
    unless ($other_link) {
772
        Koha::Patron::AccountLink->new(
773
            { link_group_id => $link_group_id, borrowernumber => $other_patron->borrowernumber } )->store;
774
    }
775
776
    return $self->account_link;
777
}
778
707
=head3 housebound_profile
779
=head3 housebound_profile
708
780
709
Returns the HouseboundProfile associated with this patron.
781
Returns the HouseboundProfile associated with this patron.
710
- 

Return to bug 39658