Commit 2b90ea2c authored by joubu's avatar joubu

Bug 17829: Move GetMember to Koha::Patron

GetMember returned a patron given a borrowernumber, cardnumber or
userid.
All of these 3 attributes are defined as a unique key at the DB level
and so we can use Koha::Patrons->find to replace this subroutine.
Additionaly GetMember set category_type and description.
Signed-off-by: Martin Renvoize's avatarMartin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: default avatarTomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: joubu's avatarJonathan Druart <jonathan.druart@bugs.koha-community.org>
parent 06c53f21
......@@ -35,6 +35,7 @@ use Koha::Items;
use Koha::Number::Price;
use Koha::Libraries;
use Koha::CsvProfiles;
use Koha::Patrons;
use C4::Koha;
......@@ -805,7 +806,7 @@ AcqViewBaskets, user permissions and basket properties (creator, users list,
branch).
First parameter can be either a borrowernumber or a hashref as returned by
C4::Members::GetMember.
Koha::Patron->unblessed
Second parameter can be either a basketno or a hashref as returned by
C4::Acquisition::GetBasket.
......@@ -822,7 +823,7 @@ sub CanUserManageBasket {
my ($borrower, $basket, $userflags) = @_;
if (!ref $borrower) {
$borrower = C4::Members::GetMember(borrowernumber => $borrower);
$borrower = Koha::Patrons->find( $borrower );
}
if (!ref $basket) {
$basket = GetBasket($basket);
......@@ -830,7 +831,7 @@ sub CanUserManageBasket {
return 0 unless ($basket and $borrower);
my $borrowernumber = $borrower->{borrowernumber};
my $borrowernumber = $borrower->borrowernumber;
my $basketno = $basket->{basketno};
my $AcqViewBaskets = C4::Context->preference('AcqViewBaskets');
......@@ -842,7 +843,7 @@ sub CanUserManageBasket {
my ($flags) = $sth->fetchrow_array;
$sth->finish;
$userflags = C4::Auth::getuserflags($flags, $borrower->{userid}, $dbh);
$userflags = C4::Auth::getuserflags($flags, $borrower->userid, $dbh);
}
unless ($userflags->{superlibrarian}
......@@ -865,7 +866,7 @@ sub CanUserManageBasket {
}
if ($AcqViewBaskets eq 'branch' && defined $basket->{branch}
&& $basket->{branch} ne $borrower->{branchcode}) {
&& $basket->{branch} ne $borrower->branchcode) {
return 0;
}
}
......@@ -3082,17 +3083,17 @@ sub NotifyOrderUsers {
my $order = GetOrder( $ordernumber );
for my $borrowernumber (@borrowernumbers) {
my $borrower = C4::Members::GetMember( borrowernumber => $borrowernumber );
my $library = Koha::Libraries->find( $borrower->{branchcode} )->unblessed;
my $patron = Koha::Patrons->find( $borrowernumber );
my $library = $patron->library->unblessed;
my $biblio = Koha::Biblios->find( $order->{biblionumber} )->unblessed;
my $letter = C4::Letters::GetPreparedLetter(
module => 'acquisition',
letter_code => 'ACQ_NOTIF_ON_RECEIV',
branchcode => $library->{branchcode},
lang => $borrower->{lang},
lang => $patron->lang,
tables => {
'branches' => $library,
'borrowers' => $borrower,
'borrowers' => $patron->unblessed,
'biblio' => $biblio,
'aqorders' => $order,
},
......
......@@ -211,7 +211,6 @@ sub get_template_and_user {
my $borrowernumber;
if ($user) {
require C4::Members;
# It's possible for $user to be the borrowernumber if they don't have a
# userid defined (and are logging in through some other method, such
......@@ -219,8 +218,9 @@ sub get_template_and_user {
my $borrower;
$borrowernumber = getborrowernumber($user) if defined($user);
if ( !defined($borrowernumber) && defined($user) ) {
$borrower = C4::Members::GetMember( borrowernumber => $user );
$borrower = Koha::Patrons->find( $user );
if ($borrower) {
$borrower = $borrower->unblessed;
$borrowernumber = $user;
# A bit of a hack, but I don't know there's a nicer way
......@@ -228,7 +228,8 @@ sub get_template_and_user {
$user = $borrower->{firstname} . ' ' . $borrower->{surname};
}
} else {
$borrower = C4::Members::GetMember( borrowernumber => $borrowernumber );
$borrower = Koha::Patrons->find( $borrowernumber );
$borrower->unblessed if $borrower; # FIXME Otherwise, what to do?
}
# user info
......
......@@ -21,6 +21,7 @@ use strict;
#use warnings; FIXME - Bug 2505
use C4::Context;
use Koha::Database;
use Koha::Patrons;
use C4::Debug;
use vars qw(@ISA @EXPORT);
......@@ -915,7 +916,7 @@ sub CanUserUseBudget {
my ($borrower, $budget, $userflags) = @_;
if (not ref $borrower) {
$borrower = C4::Members::GetMember(borrowernumber => $borrower);
$borrower = Koha::Patrons->find( $borrower )->unblessed;
}
if (not ref $budget) {
$budget = GetBudget($budget);
......@@ -998,7 +999,7 @@ sub CanUserModifyBudget {
my ($borrower, $budget, $userflags) = @_;
if (not ref $borrower) {
$borrower = C4::Members::GetMember(borrowernumber => $borrower);
$borrower = Koha::Patrons->find( $borrower )->unblessed;
}
if (not ref $budget) {
$budget = GetBudget($budget);
......
This diff is collapsed.
......@@ -29,6 +29,7 @@ use C4::Circulation;
use C4::Members;
use C4::Biblio;
use Koha::DateUtils;
use Koha::Patrons;
use List::Util qw(shuffle);
use List::MoreUtils qw(any);
......@@ -677,11 +678,11 @@ sub CreatePicklistFromItemMap {
my $barcode = $item->{barcode};
my $itemcallnumber = $item->{itemcallnumber};
my $borrower = GetMember('borrowernumber'=>$borrowernumber);
my $cardnumber = $borrower->{'cardnumber'};
my $surname = $borrower->{'surname'};
my $firstname = $borrower->{'firstname'};
my $phone = $borrower->{'phone'};
my $patron = Koha::Patrons->find( $borrowernumber );
my $cardnumber = $patron->cardnumber;
my $surname = $patron->surname;
my $firstname = $patron->firstname;
my $phone = $patron->phone;
my $bib = GetBiblioData($biblionumber);
my $title = $bib->{title};
......
......@@ -306,18 +306,12 @@ Parameters:
sub LookupPatron {
my ($cgi) = @_;
# Get the borrower...
my $borrower = GetMember($cgi->param('id_type') => $cgi->param('id'));
if ( not $borrower->{'borrowernumber'} ) {
my $patrons = Koha::Patrons->search( { $cgi->param('id_type') => $cgi->param('id') } );
unless ( $patrons->count ) {
return { message => 'PatronNotFound' };
}
# Build the hashref
my $patron->{'id'} = $borrower->{'borrowernumber'};
return { code => 'PatronNotFound' } unless $$borrower{borrowernumber};
# ...and return his ID
return $patron;
return { id => $patrons->next->borrowernumber };
}
=head2 AuthenticatePatron
......@@ -341,9 +335,8 @@ sub AuthenticatePatron {
my ($status, $cardnumber, $userid) = C4::Auth::checkpw( C4::Context->dbh, $username, $password );
if ( $status ) {
# Get the borrower
my $borrower = GetMember( cardnumber => $cardnumber );
my $patron->{'id'} = $borrower->{'borrowernumber'};
return $patron;
my $patron = Koha::Patrons->find( { cardnumber => $cardnumber } );
return { id => $patron->borrowernumber };
}
else {
return { code => 'PatronNotFound' };
......@@ -376,11 +369,11 @@ sub GetPatronInfo {
# Get Member details
my $borrowernumber = $cgi->param('patron_id');
my $borrower = GetMember( borrowernumber => $borrowernumber );
return { code => 'PatronNotFound' } unless $$borrower{borrowernumber};
my $patron = Koha::Patrons->find( $borrowernumber );
return { code => 'PatronNotFound' } unless $patron;
# Cleaning the borrower hashref
my $borrower = $patron->unblessed;
my $flags = C4::Members::patronflags( $borrower );
$borrower->{'charges'} = $flags->{'CHARGES'}->{'amount'};
my $library = Koha::Libraries->find( $borrower->{branchcode} );
......@@ -483,14 +476,14 @@ sub GetPatronStatus {
# Get Member details
my $borrowernumber = $cgi->param('patron_id');
my $borrower = GetMember( borrowernumber => $borrowernumber );
return { code => 'PatronNotFound' } unless $$borrower{borrowernumber};
my $patron = Koha::Patrons->find( $borrowernumber );
return { code => 'PatronNotFound' } unless $patron;
# Return the results
return {
type => $$borrower{categorycode},
type => $patron->categorycode,
status => 0, # TODO
expiry => $$borrower{dateexpiry},
expiry => $patron->dateexpiry,
};
}
......@@ -513,11 +506,10 @@ sub GetServices {
# Get the member, or return an error code if not found
my $borrowernumber = $cgi->param('patron_id');
my $borrower = GetMember( borrowernumber => $borrowernumber );
return { code => 'PatronNotFound' } unless $$borrower{borrowernumber};
my $patron = Koha::Patrons->find( $borrowernumber );
return { code => 'PatronNotFound' } unless $patron;
my $borrower = $patron->unblessed;
# Get the item, or return an error code if not found
my $itemnumber = $cgi->param('item_id');
my $item = GetItem( $itemnumber );
......@@ -587,8 +579,8 @@ sub RenewLoan {
# Get borrower infos or return an error code
my $borrowernumber = $cgi->param('patron_id');
my $borrower = GetMember( borrowernumber => $borrowernumber );
return { code => 'PatronNotFound' } unless $$borrower{borrowernumber};
my $patron = Koha::Patrons->find( $borrowernumber );
return { code => 'PatronNotFound' } unless $patron;
# Get the item, or return an error code
my $itemnumber = $cgi->param('item_id');
......@@ -637,8 +629,8 @@ sub HoldTitle {
# Get the borrower or return an error code
my $borrowernumber = $cgi->param('patron_id');
my $borrower = GetMember( borrowernumber => $borrowernumber );
return { code => 'PatronNotFound' } unless $$borrower{borrowernumber};
my $patron = Koha::Patrons->find( $borrowernumber );
return { code => 'PatronNotFound' } unless $patron;
# Get the biblio record, or return an error code
my $biblionumber = $cgi->param('bib_id');
......@@ -657,7 +649,7 @@ sub HoldTitle {
$branch = $cgi->param('pickup_location');
return { code => 'LocationNotFound' } unless Koha::Libraries->find($branch);
} else { # if the request provide no branch, use the borrower's branch
$branch = $$borrower{branchcode};
$branch = $patron->branchcode;
}
# Add the reserve
......@@ -705,8 +697,8 @@ sub HoldItem {
# Get the borrower or return an error code
my $borrowernumber = $cgi->param('patron_id');
my $borrower = GetMember( borrowernumber => $borrowernumber );
return { code => 'PatronNotFound' } unless $$borrower{borrowernumber};
my $patron = Koha::Patrons->find( $borrowernumber );
return { code => 'PatronNotFound' } unless $patron;
# Get the biblio or return an error code
my $biblionumber = $cgi->param('bib_id');
......@@ -734,7 +726,7 @@ sub HoldItem {
$branch = $cgi->param('pickup_location');
return { code => 'LocationNotFound' } unless Koha::Libraries->find($branch);
} else { # if the request provide no branch, use the borrower's branch
$branch = $$borrower{branchcode};
$branch = $patron->branchcode;
}
# Add the reserve
......@@ -772,8 +764,8 @@ sub CancelHold {
# Get the borrower or return an error code
my $borrowernumber = $cgi->param('patron_id');
my $borrower = GetMember( borrowernumber => $borrowernumber );
return { code => 'PatronNotFound' } unless $$borrower{borrowernumber};
my $patron = Koha::Patrons->find( $borrowernumber );
return { code => 'PatronNotFound' } unless $patron;
# Get the reserve or return an error code
my $reserve_id = $cgi->param('item_id');
......
......@@ -37,6 +37,7 @@ use Koha::SMS::Providers;
use Koha::Email;
use Koha::DateUtils qw( format_sqldatetime dt_from_string );
use Koha::Patrons;
use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
......@@ -416,8 +417,9 @@ sub SendAlerts {
# find the list of borrowers to alert
my $alerts = getalert( '', 'issue', $subscriptionid );
foreach (@$alerts) {
my $borinfo = C4::Members::GetMember('borrowernumber' => $_->{'borrowernumber'});
my $email = $borinfo->{email} or next;
my $patron = Koha::Patrons->find( $_->{borrowernumber} );
next unless $patron; # Just in case
my $email = $patron->email or next;
# warn "sending issues...";
my $userenv = C4::Context->userenv;
......@@ -430,7 +432,7 @@ sub SendAlerts {
'branches' => $_->{branchcode},
'biblio' => $biblionumber,
'biblioitems' => $biblionumber,
'borrowers' => $borinfo,
'borrowers' => $patron->unblessed,
'subscription' => $subscriptionid,
'serial' => $externalid,
},
......@@ -1048,15 +1050,15 @@ sub SendQueuedMessages {
}
elsif ( lc( $message->{'message_transport_type'} ) eq 'sms' ) {
if ( C4::Context->preference('SMSSendDriver') eq 'Email' ) {
my $member = C4::Members::GetMember( 'borrowernumber' => $message->{'borrowernumber'} );
my $sms_provider = Koha::SMS::Providers->find( $member->{'sms_provider_id'} );
my $patron = Koha::Patrons->find( $message->{borrowernumber} );
my $sms_provider = Koha::SMS::Providers->find( $patron->sms_provider_id );
unless ( $sms_provider ) {
warn sprintf( "Patron %s has no sms provider id set!", $message->{'borrowernumber'} ) if $params->{'verbose'} or $debug;
_set_message_status( { message_id => $message->{'message_id'}, status => 'failed' } );
next MESSAGE;
}
$message->{to_address} ||= $member->{'smsalertnumber'};
unless ( $message->{to_address} && $member->{'smsalertnumber'} ) {
$message->{to_address} ||= $patron->smsalertnumber;
unless ( $message->{to_address} && $patron->smsalertnumber ) {
_set_message_status( { message_id => $message->{'message_id'}, status => 'failed' } );
warn sprintf( "No smsalertnumber found for patron %s!", $message->{'borrowernumber'} ) if $params->{'verbose'} or $debug;
next MESSAGE;
......@@ -1302,10 +1304,10 @@ sub _send_message_by_email {
my $message = shift or return;
my ($username, $password, $method) = @_;
my $member = C4::Members::GetMember( 'borrowernumber' => $message->{'borrowernumber'} );
my $patron = Koha::Patrons->find( $message->{borrowernumber} );
my $to_address = $message->{'to_address'};
unless ($to_address) {
unless ($member) {
unless ($patron) {
warn "FAIL: No 'to_address' and INVALID borrowernumber ($message->{borrowernumber})";
_set_message_status( { message_id => $message->{'message_id'},
status => 'failed' } );
......@@ -1330,8 +1332,8 @@ sub _send_message_by_email {
my $branch_email = undef;
my $branch_replyto = undef;
my $branch_returnpath = undef;
if ($member) {
my $library = Koha::Libraries->find( $member->{branchcode} );
if ($patron) {
my $library = $patron->library;
$branch_email = $library->branchemail;
$branch_replyto = $library->branchreplyto;
$branch_returnpath = $library->branchreturnpath;
......@@ -1407,9 +1409,9 @@ sub _is_duplicate {
sub _send_message_by_sms {
my $message = shift or return;
my $member = C4::Members::GetMember( 'borrowernumber' => $message->{'borrowernumber'} );
my $patron = Koha::Patrons->find( $message->{borrowernumber} );
unless ( $member->{smsalertnumber} ) {
unless ( $patron and $patron->smsalertnumber ) {
_set_message_status( { message_id => $message->{'message_id'},
status => 'failed' } );
return;
......@@ -1421,7 +1423,7 @@ sub _send_message_by_sms {
return;
}
my $success = C4::SMS->send_sms( { destination => $member->{'smsalertnumber'},
my $success = C4::SMS->send_sms( { destination => $patron->smsalertnumber,
message => $message->{'content'},
} );
_set_message_status( { message_id => $message->{'message_id'},
......
......@@ -60,7 +60,6 @@ BEGIN {
@ISA = qw(Exporter);
#Get data
push @EXPORT, qw(
&GetMember
&GetPendingIssues
&GetAllIssues
......@@ -280,68 +279,6 @@ sub patronflags {
}
=head2 GetMember
$borrower = &GetMember(%information);
Retrieve the first patron record meeting on criteria listed in the
C<%information> hash, which should contain one or more
pairs of borrowers column names and values, e.g.,
$borrower = GetMember(borrowernumber => id);
C<&GetBorrower> returns a reference-to-hash whose keys are the fields of
the C<borrowers> table in the Koha database.
FIXME: GetMember() is used throughout the code as a lookup
on a unique key such as the borrowernumber, but this meaning is not
enforced in the routine itself.
=cut
#'
sub GetMember {
my ( %information ) = @_;
if (exists $information{borrowernumber} && !defined $information{borrowernumber}) {
#passing mysql's kohaadmin?? Makes no sense as a query
return;
}
my $dbh = C4::Context->dbh;
my $select =
q{SELECT borrowers.*, categories.category_type, categories.description
FROM borrowers
LEFT JOIN categories on borrowers.categorycode=categories.categorycode WHERE };
my $more_p = 0;
my @values = ();
for (keys %information ) {
if ($more_p) {
$select .= ' AND ';
}
else {
$more_p++;
}
if (defined $information{$_}) {
$select .= "$_ = ?";
push @values, $information{$_};
}
else {
$select .= "$_ IS NULL";
}
}
$debug && warn $select, " ",values %information;
my $sth = $dbh->prepare("$select");
$sth->execute(@values);
my $data = $sth->fetchall_arrayref({});
#FIXME interface to this routine now allows generation of a result set
#so whole array should be returned but bowhere in the current code expects this
if (@{$data} ) {
return $data->[0];
}
return;
}
=head2 ModMember
my $success = ModMember(borrowernumber => $borrowernumber,
......
......@@ -226,16 +226,16 @@ sub AddReserve {
# Send e-mail to librarian if syspref is active
if(C4::Context->preference("emailLibrarianWhenHoldIsPlaced")){
my $borrower = C4::Members::GetMember(borrowernumber => $borrowernumber);
my $library = Koha::Libraries->find($borrower->{branchcode})->unblessed;
my $patron = Koha::Patrons->find( $borrowernumber );
my $library = $patron->library;
if ( my $letter = C4::Letters::GetPreparedLetter (
module => 'reserves',
letter_code => 'HOLDPLACED',
branchcode => $branch,
lang => $borrower->{lang},
lang => $patron->lang,
tables => {
'branches' => $library,
'borrowers' => $borrower,
'branches' => $library->unblessed,
'borrowers' => $patron->unblessed,
'biblio' => $biblionumber,
'biblioitems' => $biblionumber,
'items' => $checkitem,
......@@ -243,7 +243,7 @@ sub AddReserve {
},
) ) {
my $admin_email_address = $library->{'branchemail'} || C4::Context->preference('KohaAdminEmailAddress');
my $admin_email_address = $library->branchemail || C4::Context->preference('KohaAdminEmailAddress');
C4::Letters::EnqueueLetter(
{ letter => $letter,
......@@ -331,7 +331,8 @@ sub CanItemBeReserved {
# item->{itype} will come for biblioitems if necessery
my $item = GetItem($itemnumber);
my $biblioData = C4::Biblio::GetBiblioData( $item->{biblionumber} );
my $borrower = C4::Members::GetMember( 'borrowernumber' => $borrowernumber );
my $patron = Koha::Patrons->find( $borrowernumber );
my $borrower = $patron->unblessed;
# If an item is damaged and we don't allow holds on damaged items, we can stop right here
return 'damaged'
......@@ -807,12 +808,12 @@ sub CheckReserves {
if ( $res->{'itemnumber'} == $itemnumber && $res->{'priority'} == 0) {
return ( "Waiting", $res, \@reserves ); # Found it
} else {
my $borrowerinfo;
my $patron;
my $iteminfo;
my $local_hold_match;
if ($LocalHoldsPriority) {
$borrowerinfo = C4::Members::GetMember( borrowernumber => $res->{'borrowernumber'} );
$patron = Koha::Patrons->find( $res->{borrowernumber} );
$iteminfo = C4::Items::GetItem($itemnumber);
my $local_holds_priority_item_branchcode =
......@@ -821,7 +822,7 @@ sub CheckReserves {
( $LocalHoldsPriorityPatronControl eq 'PickupLibrary' )
? $res->{branchcode}
: ( $LocalHoldsPriorityPatronControl eq 'HomeLibrary' )
? $borrowerinfo->{branchcode}
? $patron->branchcode
: undef;
$local_hold_match =
$local_holds_priority_item_branchcode eq
......@@ -832,11 +833,11 @@ sub CheckReserves {
if ( ( $res->{'priority'} && $res->{'priority'} < $priority ) || $local_hold_match ) {
$iteminfo ||= C4::Items::GetItem($itemnumber);
next if $res->{itemtype} && $res->{itemtype} ne _get_itype( $iteminfo );
$borrowerinfo ||= C4::Members::GetMember( borrowernumber => $res->{'borrowernumber'} );
my $branch = GetReservesControlBranch( $iteminfo, $borrowerinfo );
$patron ||= Koha::Patrons->find( $res->{borrowernumber} );
my $branch = GetReservesControlBranch( $iteminfo, $patron->unblessed );
my $branchitemrule = C4::Circulation::GetBranchItemRule($branch,$iteminfo->{'itype'});
next if ($branchitemrule->{'holdallowed'} == 0);
next if (($branchitemrule->{'holdallowed'} == 1) && ($branch ne $borrowerinfo->{'branchcode'}));
next if (($branchitemrule->{'holdallowed'} == 1) && ($branch ne $patron->branchcode));
next if ( ($branchitemrule->{hold_fulfillment_policy} ne 'any') && ($res->{branchcode} ne $iteminfo->{ $branchitemrule->{hold_fulfillment_policy} }) );
$priority = $res->{'priority'};
$highest = $res;
......@@ -1808,7 +1809,7 @@ sub _koha_notify_reserve {
my $hold = Koha::Holds->find($reserve_id);
my $borrowernumber = $hold->borrowernumber;
my $borrower = C4::Members::GetMember(borrowernumber => $borrowernumber);
my $patron = Koha::Patrons->find( $borrowernumber );
# Try to get the borrower's email address
my $to_address = C4::Members::GetNoticeEmailAddress($borrowernumber);
......@@ -1825,10 +1826,10 @@ sub _koha_notify_reserve {
my %letter_params = (
module => 'reserves',
branchcode => $hold->branchcode,
lang => $borrower->{lang},
lang => $patron->lang,
tables => {
'branches' => $library,
'borrowers' => $borrower,
'borrowers' => $patron->unblessed,
'biblio' => $hold->biblionumber,
'biblioitems' => $hold->biblionumber,
'reserves' => $hold->unblessed,
......@@ -1859,7 +1860,7 @@ sub _koha_notify_reserve {
while ( my ( $mtt, $letter_code ) = each %{ $messagingprefs->{transports} } ) {
next if (
( $mtt eq 'email' and not $to_address ) # No email address
or ( $mtt eq 'sms' and not $borrower->{smsalertnumber} ) # No SMS number
or ( $mtt eq 'sms' and not $patron->smsalertnumber ) # No SMS number
or ( $mtt eq 'phone' and C4::Context->preference('TalkingTechItivaPhoneNotification') ) # Notice is handled by TalkingTech_itiva_outbound.pl
);
......
......@@ -93,9 +93,9 @@ sub new {
my $issue = Koha::Checkouts->find( { itemnumber => $item->itemnumber } );
if ($issue) {
$self->{due_date} = dt_from_string( $issue->date_due, 'sql' )->truncate( to => 'minute' );
my $patron = Koha::Patrons->find( $issue->borrowernumber );
$self->{patron} = $patron->cardnumber;
}
my $borrower = $issue ? GetMember( borrowernumber => $issue->borrowernumber ) : {};
$self->{patron} = $borrower->{'cardnumber'};
my $biblio = Koha::Biblios->find( $self->{biblionumber} );
my $holds = $biblio->current_holds->unblessed;
$self->{hold_queue} = $holds;
......@@ -175,29 +175,27 @@ sub hold_patron_name {
return $output;
}
my $holder = GetMember(borrowernumber=>$borrowernumber);
my $holder = Koha::Patrons->find( $borrowernumber );
unless ($holder) {
syslog("LOG_ERR", "While checking hold, GetMember failed for borrowernumber '$borrowernumber'");
syslog("LOG_ERR", "While checking hold, failed to retrieve the patron with borrowernumber '$borrowernumber'");
return;
}
my $email = $holder->{email} || '';
my $phone = $holder->{phone} || '';
my $email = $holder->email || '';
my $phone = $holder->phone || '';
my $extra = ($email and $phone) ? " ($email, $phone)" : # both populated, employ comma
($email or $phone) ? " ($email$phone)" : # only 1 populated, we don't care which: no comma
"" ; # neither populated, empty string
my $name = $holder->{firstname} ? $holder->{firstname} . ' ' : '';
$name .= $holder->{surname} . $extra;
my $name = $holder->firstname ? $holder->firstname . ' ' : '';
$name .= $holder->surname . $extra;
return $name;
}
sub hold_patron_bcode {
my $self = shift;
my $borrowernumber = (@_ ? shift: $self->hold_patron_id()) or return;
my $holder = GetMember(borrowernumber => $borrowernumber);
if ($holder) {
if ($holder->{cardnumber}) {
return $holder->{cardnumber};
}
my $holder = Koha::Patrons->find( $borrowernumber );
if ($holder and $holder->cardnumber ) {
return $holder->cardnumber;
}
return;
}
......@@ -359,8 +357,8 @@ sub available {
sub _barcode_to_borrowernumber {
my $known = shift;
return unless defined $known;
my $member = GetMember(cardnumber=>$known) or return;
return $member->{borrowernumber};
my $patron = Koha::Patrons->find( { cardnumber => $known } ) or return;
return $patron->borrowernumber
}
sub barcode_is_borrowernumber { # because hold_queue only has borrowernumber...
my $self = shift;
......
......@@ -32,14 +32,14 @@ sub new {
my ($class, $patron_id) = @_;
my $type = ref($class) || $class;
my $self;
$kp = GetMember(cardnumber=>$patron_id) || GetMember(userid=>$patron_id);
$debug and warn "new Patron (GetMember): " . Dumper($kp);
unless (defined $kp) {
$kp = Koha::Patrons->find( { cardnumber => $patron_id } )
or Koha::Patrons->find( { userid => $patron_id } );
$debug and warn "new Patron: " . Dumper($kp->unblessed) if $kp;
unless ($kp) {
syslog("LOG_DEBUG", "new ILS::Patron(%s): no such patron", $patron_id);
return;
}
$kp = GetMember( borrowernumber => $kp->{borrowernumber});
$debug and warn "new Patron (GetMember): " . Dumper($kp);
$kp = $kp->unblessed;
my $pw = $kp->{password};
my $flags = C4::Members::patronflags( $kp );
my $debarred = defined($flags->{DBARRED});
......
......@@ -8,7 +8,7 @@ use Modern::Perl;
use C4::SIP::ILS::Transaction;