From 2b90ea2cb0e5e976de7ddef0151ae83d8ac578e6 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 29 Dec 2016 14:24:03 +0100 Subject: [PATCH] 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 Signed-off-by: Tomas Cohen Arazi Signed-off-by: Jonathan Druart --- C4/Acquisition.pm | 19 +- C4/Auth.pm | 7 +- C4/Budgets.pm | 5 +- C4/Circulation.pm | 188 +++++++++--------- C4/HoldsQueue.pm | 11 +- C4/ILSDI/Services.pm | 54 +++-- C4/Letters.pm | 30 +-- C4/Members.pm | 63 ------ C4/Reserves.pm | 35 ++-- C4/SIP/ILS/Item.pm | 28 ++- C4/SIP/ILS/Patron.pm | 10 +- C4/SIP/ILS/Transaction/Hold.pm | 20 +- C4/SIP/ILS/Transaction/Renew.pm | 6 +- C4/SIP/ILS/Transaction/RenewAll.pm | 4 +- acqui/acqui-home.pl | 12 +- acqui/addorderiso2709.pl | 10 +- acqui/basket.pl | 12 +- acqui/basketgroup.pl | 8 +- acqui/booksellers.pl | 14 +- acqui/neworderbiblio.pl | 6 +- acqui/neworderempty.pl | 11 +- acqui/orderreceive.pl | 11 +- acqui/transferorder.pl | 5 +- admin/aqbudgets.pl | 15 +- catalogue/ISBDdetail.pl | 10 +- catalogue/MARCdetail.pl | 10 +- catalogue/detail.pl | 18 +- catalogue/imageviewer.pl | 10 +- catalogue/labeledMARCdetail.pl | 10 +- catalogue/moredetail.pl | 15 +- catalogue/search.pl | 12 +- cataloguing/additem.pl | 3 +- circ/branchtransfers.pl | 13 +- circ/circulation.pl | 70 ++++--- circ/returns.pl | 112 ++++++----- circ/transferstoreceive.pl | 14 +- circ/waitingreserves.pl | 15 +- members/boraccount.pl | 18 +- members/deletemem.pl | 54 ++--- members/discharge.pl | 49 ++--- members/files.pl | 11 +- members/housebound.pl | 2 +- members/mancredit.pl | 18 +- members/maninvoice.pl | 20 +- members/member-flags.pl | 18 +- members/member-password.pl | 19 +- members/member.pl | 11 +- members/memberentry.pl | 14 +- members/moremember.pl | 21 +- members/notices.pl | 11 +- members/pay.pl | 7 +- members/paycollect.pl | 7 +- members/printfeercpt.pl | 12 +- members/printinvoice.pl | 12 +- members/purchase-suggestions.pl | 17 +- members/readingrec.pl | 15 +- members/routing-lists.pl | 29 ++- members/statistics.pl | 14 +- members/summary-print.pl | 7 +- members/update-child.pl | 4 +- misc/cronjobs/advance_notices.pl | 5 +- .../notice_unprocessed_suggestions.pl | 20 +- misc/export_borrowers.pl | 17 +- misc/load_testing/benchmark_staff.pl | 4 +- offline_circ/list.pl | 9 +- offline_circ/process_koc.pl | 30 +-- opac/opac-ISBDdetail.pl | 6 +- opac/opac-MARCdetail.pl | 5 +- opac/opac-account-pay-paypal-return.pl | 5 +- opac/opac-account.pl | 10 +- opac/opac-detail.pl | 23 ++- opac/opac-discharge.pl | 6 +- opac/opac-memberentry.pl | 23 ++- opac/opac-messaging.pl | 5 +- opac/opac-passwd.pl | 7 +- opac/opac-readingrecord.pl | 4 +- opac/opac-registration-verify.pl | 5 +- opac/opac-renew.pl | 3 +- opac/opac-reserve.pl | 30 +-- opac/opac-sendbasket.pl | 9 +- opac/opac-sendshelf.pl | 7 +- opac/opac-shelves.pl | 7 +- opac/opac-showreviews.pl | 4 +- opac/opac-suggestions.pl | 8 +- opac/opac-user.pl | 2 +- opac/sco/sco-main.pl | 8 +- patroncards/create-pdf.pl | 4 +- patroncards/edit-batch.pl | 5 +- reserve/placerequest.pl | 6 +- reserve/request.pl | 76 +++---- reviews/reviewswaiting.pl | 8 +- serials/routing-preview.pl | 3 +- serials/routing.pl | 3 +- suggestion/suggestion.pl | 22 +- svc/members/search | 5 +- t/db_dependent/Acquisition/OrderUsers.t | 2 - t/db_dependent/Circulation.t | 23 ++- t/db_dependent/Circulation/Branch.t | 1 - .../Circulation/CheckIfIssuedToPatron.t | 5 +- .../Circulation/GetPendingOnSiteCheckouts.t | 4 +- t/db_dependent/Circulation/GetTopIssues.t | 3 +- t/db_dependent/Circulation/IsItemIssued.t | 3 +- .../IssuingRules/maxsuspensiondays.t | 4 +- t/db_dependent/Circulation/Returns.t | 5 +- t/db_dependent/Circulation/issue.t | 25 +-- t/db_dependent/Holds/RevertWaitingStatus.t | 4 +- t/db_dependent/Koha/Patrons.t | 2 +- t/db_dependent/Members.t | 37 ++-- t/db_dependent/Members/GetAllIssues.t | 5 +- t/db_dependent/Members/GetOverdues.t | 3 +- t/db_dependent/Members/GetPendingIssues.t | 5 +- t/db_dependent/Members/IssueSlip.t | 3 +- t/db_dependent/Patron/Borrower_Debarments.t | 3 +- t/db_dependent/Patron/Borrower_Discharge.t | 2 +- t/db_dependent/Patron/Borrower_PrevCheckout.t | 13 +- t/db_dependent/Reserves.t | 3 +- t/db_dependent/Utils/Datatables_Members.t | 15 ++ t/db_dependent/rollingloans.t | 7 +- tools/batchMod.pl | 3 +- tools/import_borrowers.pl | 4 +- tools/modborrowers.pl | 3 +- tools/picture-upload.pl | 1 - tools/viewlog.pl | 26 +-- virtualshelves/shelves.pl | 5 +- 124 files changed, 953 insertions(+), 946 deletions(-) diff --git a/C4/Acquisition.pm b/C4/Acquisition.pm index 2e36ac15b8..ee382853aa 100644 --- a/C4/Acquisition.pm +++ b/C4/Acquisition.pm @@ -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, }, diff --git a/C4/Auth.pm b/C4/Auth.pm index e7b0895160..b1e7824d4f 100644 --- a/C4/Auth.pm +++ b/C4/Auth.pm @@ -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 diff --git a/C4/Budgets.pm b/C4/Budgets.pm index c68fbecd3e..f05d234781 100644 --- a/C4/Budgets.pm +++ b/C4/Budgets.pm @@ -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); diff --git a/C4/Circulation.pm b/C4/Circulation.pm index 069bb80274..0c5585aa2a 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -573,7 +573,7 @@ C<$issuingimpossible> and C<$needsconfirmation> are some hashref. =over 4 -=item C<$borrower> hash with borrower informations (from GetMember) +=item C<$borrower> hash with borrower informations (from Koha::Patron->unblessed) =item C<$barcode> is the bar code of the book being issued. @@ -971,8 +971,8 @@ sub CanBookBeIssued { elsif ( $issue ) { # issued to someone else - my $currborinfo = C4::Members::GetMember( borrowernumber => $issue->borrowernumber ); + my $patron = Koha::Patrons->find( $issue->borrowernumber ); my ( $can_be_returned, $message ) = CanBookBeReturned( $item, C4::Context->userenv->{branch} ); @@ -981,10 +981,10 @@ sub CanBookBeIssued { $issuingimpossible{branch_to_return} = $message; } else { $needsconfirmation{ISSUED_TO_ANOTHER} = 1; - $needsconfirmation{issued_firstname} = $currborinfo->{'firstname'}; - $needsconfirmation{issued_surname} = $currborinfo->{'surname'}; - $needsconfirmation{issued_cardnumber} = $currborinfo->{'cardnumber'}; - $needsconfirmation{issued_borrowernumber} = $currborinfo->{'borrowernumber'}; + $needsconfirmation{issued_firstname} = $patron->firstname; + $needsconfirmation{issued_surname} = $patron->surname; + $needsconfirmation{issued_cardnumber} = $patron->cardnumber; + $needsconfirmation{issued_borrowernumber} = $patron->borrowernumber; } } @@ -994,28 +994,28 @@ sub CanBookBeIssued { if ($restype) { my $resbor = $res->{'borrowernumber'}; if ( $resbor ne $borrower->{'borrowernumber'} ) { - my ( $resborrower ) = C4::Members::GetMember( borrowernumber => $resbor ); + my $patron = Koha::Patrons->find( $resbor ); if ( $restype eq "Waiting" ) { # The item is on reserve and waiting, but has been # reserved by some other patron. $needsconfirmation{RESERVE_WAITING} = 1; - $needsconfirmation{'resfirstname'} = $resborrower->{'firstname'}; - $needsconfirmation{'ressurname'} = $resborrower->{'surname'}; - $needsconfirmation{'rescardnumber'} = $resborrower->{'cardnumber'}; - $needsconfirmation{'resborrowernumber'} = $resborrower->{'borrowernumber'}; + $needsconfirmation{'resfirstname'} = $patron->firstname; + $needsconfirmation{'ressurname'} = $patron->surname; + $needsconfirmation{'rescardnumber'} = $patron->cardnumber; + $needsconfirmation{'resborrowernumber'} = $patron->borrowernumber; $needsconfirmation{'resbranchcode'} = $res->{branchcode}; $needsconfirmation{'reswaitingdate'} = $res->{'waitingdate'}; } elsif ( $restype eq "Reserved" ) { # The item is on reserve for someone else. $needsconfirmation{RESERVED} = 1; - $needsconfirmation{'resfirstname'} = $resborrower->{'firstname'}; - $needsconfirmation{'ressurname'} = $resborrower->{'surname'}; - $needsconfirmation{'rescardnumber'} = $resborrower->{'cardnumber'}; - $needsconfirmation{'resborrowernumber'} = $resborrower->{'borrowernumber'}; - $needsconfirmation{'resbranchcode'} = $res->{branchcode}; - $needsconfirmation{'resreservedate'} = $res->{'reservedate'}; + $needsconfirmation{'resfirstname'} = $patron->firstname; + $needsconfirmation{'ressurname'} = $patron->surname; + $needsconfirmation{'rescardnumber'} = $patron->cardnumber; + $needsconfirmation{'resborrowernumber'} = $patron->borrowernumber; + $needsconfirmation{'resbranchcode'} = $patron->branchcode; + $needsconfirmation{'resreservedate'} = $res->{reservedate}; } } } @@ -1235,7 +1235,7 @@ Issue a book. Does no check, they are done in CanBookBeIssued. If we reach this =over 4 -=item C<$borrower> is a hash with borrower informations (from GetMember). +=item C<$borrower> is a hash with borrower informations (from Koha::Patron->unblessed). =item C<$barcode> is the barcode of the item being issued. @@ -1808,7 +1808,7 @@ sub AddReturn { } $branch = C4::Context->userenv->{'branch'} unless $branch; # we trust userenv to be a safe fallback/default my $messages; - my $borrower; + my $patron; my $doreturn = 1; my $validTransfert = 0; my $stat_type = 'return'; @@ -1827,7 +1827,7 @@ sub AddReturn { my $issue = Koha::Checkouts->find( { itemnumber => $itemnumber } ); if ( $issue ) { - $borrower = C4::Members::GetMember( borrowernumber => $issue->borrowernumber ) + $patron = Koha::Patrons->find( $issue->borrowernumber ) or die "Data inconsistency: barcode $barcode (itemnumber:$itemnumber) claims to be issued to non-existent borrowernumber '" . $issue->borrowernumber . "'\n" . Dumper($issue->unblessed) . "\n"; } else { @@ -1859,7 +1859,8 @@ sub AddReturn { my $returnbranch = $item->{$hbr} || $branch ; # if $hbr was "noreturn" or any other non-item table value, then it should 'float' (i.e. stay at this branch) - my $borrowernumber = $borrower->{'borrowernumber'} || undef; # we don't know if we had a borrower or not + my $borrowernumber = $patron ? $patron->borrowernumber : undef; # we don't know if we had a borrower or not + my $patron_unblessed = $patron ? $patron->unblessed : {}; my $yaml = C4::Context->preference('UpdateNotForLoanStatusOnCheckin'); if ($yaml) { @@ -1898,7 +1899,7 @@ sub AddReturn { Rightbranch => $message }; $doreturn = 0; - return ( $doreturn, $messages, $issue, $borrower ); + return ( $doreturn, $messages, $issue, $patron_unblessed); } if ( $item->{'withdrawn'} ) { # book has been cancelled @@ -1912,28 +1913,28 @@ sub AddReturn { if ($doreturn) { my $is_overdue; die "The item is not issed and cannot be returned" unless $issue; # Just in case... - $borrower or warn "AddReturn without current borrower"; + $patron or warn "AddReturn without current borrower"; my $circControlBranch; if ($dropbox) { # define circControlBranch only if dropbox mode is set # don't allow dropbox mode to create an invalid entry in issues (issuedate > today) # FIXME: check issuedate > returndate, factoring in holidays - $circControlBranch = _GetCircControlBranch($item,$borrower); + $circControlBranch = _GetCircControlBranch($item,$patron_unblessed); $is_overdue = $issue->is_overdue( $dropboxdate ); } else { $is_overdue = $issue->is_overdue; } - if ($borrowernumber) { + if ($patron) { eval { my $issue_id = MarkIssueReturned( $borrowernumber, $item->{'itemnumber'}, - $circControlBranch, $return_date, $borrower->{'privacy'} ); + $circControlBranch, $return_date, $patron->privacy ); $issue->issue_id($issue_id); }; unless ( $@ ) { if ( ( C4::Context->preference('CalculateFinesOnReturn') && $is_overdue ) || $return_date ) { - _CalculateAndUpdateFine( { issue => $issue, item => $item, borrower => $borrower, return_date => $return_date } ); + _CalculateAndUpdateFine( { issue => $issue, item => $item, borrower => $patron_unblessed, return_date => $return_date } ); } } else { $messages->{'Wrongbranch'} = { @@ -1941,7 +1942,7 @@ sub AddReturn { Rightbranch => $message }; carp $@; - return ( 0, { WasReturned => 0 }, $issue, $borrower ); + return ( 0, { WasReturned => 0 }, $issue, $patron_unblessed ); } # FIXME is the "= 1" right? This could be the borrower hash. @@ -2013,22 +2014,22 @@ sub AddReturn { if ( $issue and $issue->is_overdue ) { # fix fine days $today = $dropboxdate if $dropbox; - my ($debardate,$reminder) = _debar_user_on_return( $borrower, $item, dt_from_string($issue->date_due), $today ); + my ($debardate,$reminder) = _debar_user_on_return( $patron_unblessed, $item, dt_from_string($issue->date_due), $today ); if ($reminder){ $messages->{'PrevDebarred'} = $debardate; } else { $messages->{'Debarred'} = $debardate if $debardate; } # there's no overdue on the item but borrower had been previously debarred - } elsif ( $issue->date_due and $borrower->{'debarred'} ) { - if ( $borrower->{debarred} eq "9999-12-31") { - $messages->{'ForeverDebarred'} = $borrower->{'debarred'}; + } elsif ( $issue->date_due and $patron->debarred ) { + if ( $patron->debarred eq "9999-12-31") { + $messages->{'ForeverDebarred'} = $patron->debarred; } else { - my $borrower_debar_dt = dt_from_string( $borrower->{debarred} ); + my $borrower_debar_dt = dt_from_string( $patron->debarred ); $borrower_debar_dt->truncate(to => 'day'); my $today_dt = $today->clone()->truncate(to => 'day'); if ( DateTime->compare( $borrower_debar_dt, $today_dt ) != -1 ) { - $messages->{'PrevDebarred'} = $borrower->{'debarred'}; + $messages->{'PrevDebarred'} = $patron->debarred; } } } @@ -2054,29 +2055,31 @@ sub AddReturn { ccode => $item->{ ccode } }); - # Send a check-in slip. # NOTE: borrower may be undef. probably shouldn't try to send messages then. - my $circulation_alert = 'C4::ItemCirculationAlertPreference'; - my %conditions = ( - branchcode => $branch, - categorycode => $borrower->{categorycode}, - item_type => $item->{itype}, - notification => 'CHECKIN', - ); - if ($doreturn && $circulation_alert->is_enabled_for(\%conditions)) { - SendCirculationAlert({ - type => 'CHECKIN', - item => $item, - borrower => $borrower, - branch => $branch, - }); - } - - logaction("CIRCULATION", "RETURN", $borrowernumber, $item->{'itemnumber'}) - if C4::Context->preference("ReturnLog"); - + # Send a check-in slip. # NOTE: borrower may be undef. Do not try to send messages then. + if ( $patron ) { + my $circulation_alert = 'C4::ItemCirculationAlertPreference'; + my %conditions = ( + branchcode => $branch, + categorycode => $patron->categorycode, + item_type => $item->{itype}, + notification => 'CHECKIN', + ); + if ($doreturn && $circulation_alert->is_enabled_for(\%conditions)) { + SendCirculationAlert({ + type => 'CHECKIN', + item => $item, + borrower => $patron->unblessed, + branch => $branch, + }); + } + + logaction("CIRCULATION", "RETURN", $borrowernumber, $item->{'itemnumber'}) + if C4::Context->preference("ReturnLog"); + } + # Remove any OVERDUES related debarment if the borrower has no overdues if ( $borrowernumber - && $borrower->{'debarred'} + && $patron->debarred && C4::Context->preference('AutoRemoveOverduesRestrictions') && !Koha::Patrons->find( $borrowernumber )->has_overdues && @{ GetDebarments({ borrowernumber => $borrowernumber, type => 'OVERDUES' }) } @@ -2099,7 +2102,7 @@ sub AddReturn { } } - return ( $doreturn, $messages, $issue, $borrower ); + return ( $doreturn, $messages, $issue, ( $patron ? $patron->unblessed : {} )); } =head2 MarkIssueReturned @@ -2136,7 +2139,7 @@ sub MarkIssueReturned { # Note that a warning should appear on the about page (System information tab). $anonymouspatron = C4::Context->preference('AnonymousPatron'); die "Fatal error: the patron ($borrowernumber) has requested their circulation history be anonymized on check-in, but the AnonymousPatron system preference is empty or not set correctly." - unless C4::Members::GetMember( borrowernumber => $anonymouspatron ); + unless Koha::Patrons->find( $anonymouspatron ); } my $database = Koha::Database->new(); my $schema = $database->schema; @@ -2619,7 +2622,7 @@ sub CanBookBeRenewed { return ( 0, 'onsite_checkout' ) if $issue->onsite_checkout; $borrowernumber ||= $issue->borrowernumber; - my $borrower = C4::Members::GetMember( borrowernumber => $borrowernumber ) + my $patron = Koha::Patrons->find( $borrowernumber ) or return; my ( $resfound, $resrec, undef ) = C4::Reserves::CheckReserves($itemnumber); @@ -2673,7 +2676,7 @@ sub CanBookBeRenewed { my $item = GetItem($i); next if IsItemOnHoldAndFound($i); for my $b (@borrowernumbers) { - my $borr = $borrowers{$b}//= C4::Members::GetMember(borrowernumber => $b); + my $borr = $borrowers{$b} //= Koha::Patrons->find( $b )->unblessed; next unless IsAvailableForItemLevelRequest($item, $borr); next unless CanItemBeReserved($b,$i); @@ -2691,9 +2694,9 @@ sub CanBookBeRenewed { return ( 1, undef ) if $override_limit; - my $branchcode = _GetCircControlBranch( $item, $borrower ); + my $branchcode = _GetCircControlBranch( $item, $patron->unblessed ); my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule( - { categorycode => $borrower->{categorycode}, + { categorycode => $patron->categorycode, itemtype => $item->{itype}, branchcode => $branchcode } @@ -2704,7 +2707,7 @@ sub CanBookBeRenewed { my $overduesblockrenewing = C4::Context->preference('OverduesBlockRenewing'); my $restrictionblockrenewing = C4::Context->preference('RestrictionBlockRenewing'); - my $patron = Koha::Patrons->find($borrowernumber); + $patron = Koha::Patrons->find($borrowernumber); # FIXME Is this really useful? my $restricted = $patron->is_debarred; my $hasoverdues = $patron->has_overdues; @@ -2738,7 +2741,7 @@ sub CanBookBeRenewed { if ( C4::Context->preference('OPACFineNoRenewalsBlockAutoRenew') ) { my $fine_no_renewals = C4::Context->preference("OPACFineNoRenewals"); - my ( $amountoutstanding ) = C4::Members::GetMemberAccountRecords($borrower->{borrowernumber}); + my ( $amountoutstanding ) = C4::Members::GetMemberAccountRecords($patron->borrowernumber); if ( $amountoutstanding and $amountoutstanding > $fine_no_renewals ) { return ( 0, "auto_too_much_oweing" ); } @@ -2831,10 +2834,11 @@ sub AddRenewal { return; } - my $borrower = C4::Members::GetMember( borrowernumber => $borrowernumber ) or return; + my $patron = Koha::Patrons->find( $borrowernumber ) or return; # FIXME Should do more than just return + my $patron_unblessed = $patron->unblessed; if ( C4::Context->preference('CalculateFinesOnReturn') && $issue->is_overdue ) { - _CalculateAndUpdateFine( { issue => $issue, item => $item, borrower => $borrower } ); + _CalculateAndUpdateFine( { issue => $issue, item => $item, borrower => $patron_unblessed } ); } _FixOverduesOnReturn( $borrowernumber, $itemnumber ); @@ -2847,7 +2851,7 @@ sub AddRenewal { $datedue = (C4::Context->preference('RenewalPeriodBase') eq 'date_due') ? dt_from_string( $issue->date_due, 'sql' ) : DateTime->now( time_zone => C4::Context->tz()); - $datedue = CalcDateDue($datedue, $itemtype, _GetCircControlBranch($item, $borrower), $borrower, 'is a renewal'); + $datedue = CalcDateDue($datedue, $itemtype, _GetCircControlBranch($item, $patron_unblessed), $patron_unblessed, 'is a renewal'); } # Update the issues record to have the new due date, and a new count @@ -2883,11 +2887,10 @@ sub AddRenewal { # Send a renewal slip according to checkout alert preferencei if ( C4::Context->preference('RenewalSendNotice') eq '1' ) { - $borrower = C4::Members::GetMember( borrowernumber => $borrowernumber ); my $circulation_alert = 'C4::ItemCirculationAlertPreference'; my %conditions = ( branchcode => $branch, - categorycode => $borrower->{categorycode}, + categorycode => $patron->categorycode, item_type => $item->{itype}, notification => 'CHECKOUT', ); @@ -2896,7 +2899,7 @@ sub AddRenewal { { type => 'RENEWAL', item => $item, - borrower => $borrower, + borrower => $patron->unblessed, branch => $branch, } ); @@ -2904,10 +2907,9 @@ sub AddRenewal { } # Remove any OVERDUES related debarment if the borrower has no overdues - $borrower = C4::Members::GetMember( borrowernumber => $borrowernumber ); - if ( $borrowernumber - && $borrower->{'debarred'} - && !Koha::Patrons->find( $borrowernumber )->has_overdues + if ( $patron + && $patron->is_debarred + && ! $patron->has_overdues && @{ GetDebarments({ borrowernumber => $borrowernumber, type => 'OVERDUES' }) } ) { DelUniqueDebarment({ borrowernumber => $borrowernumber, type => 'OVERDUES' }); @@ -2939,8 +2941,10 @@ sub GetRenewCount { my $renewsallowed = 0; my $renewsleft = 0; - my $borrower = C4::Members::GetMember( borrowernumber => $bornum); - my $item = GetItem($itemno); + my $patron = Koha::Patrons->find( $bornum ); + my $item = GetItem($itemno); + + return (0, 0, 0) unless $patron or $item; # Wrong call, no renewal allowed # Look in the issues table for this item, lent to this borrower, # and not yet returned. @@ -2955,16 +2959,16 @@ sub GetRenewCount { my $data = $sth->fetchrow_hashref; $renewcount = $data->{'renewals'} if $data->{'renewals'}; # $item and $borrower should be calculated - my $branchcode = _GetCircControlBranch($item, $borrower); + my $branchcode = _GetCircControlBranch($item, $patron->unblessed); my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule( - { categorycode => $borrower->{categorycode}, + { categorycode => $patron->categorycode, itemtype => $item->{itype}, branchcode => $branchcode } ); - $renewsallowed = $issuing_rule ? $issuing_rule->renewalsallowed : undef; # FIXME Just replace undef with 0 to get what we expected. But what about the side-effects? TODO LATER + $renewsallowed = $issuing_rule ? $issuing_rule->renewalsallowed : 0; $renewsleft = $renewsallowed - $renewcount; if($renewsleft < 0){ $renewsleft = 0; } return ( $renewcount, $renewsallowed, $renewsleft ); @@ -2998,12 +3002,12 @@ sub GetSoonestRenewDate { my $itemissue = Koha::Checkouts->find( { itemnumber => $itemnumber } ) or return; $borrowernumber ||= $itemissue->borrowernumber; - my $borrower = C4::Members::GetMember( borrowernumber => $borrowernumber ) + my $patron = Koha::Patrons->find( $borrowernumber ) or return; - my $branchcode = _GetCircControlBranch( $item, $borrower ); + my $branchcode = _GetCircControlBranch( $item, $patron->unblessed ); my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule( - { categorycode => $borrower->{categorycode}, + { categorycode => $patron->categorycode, itemtype => $item->{itype}, branchcode => $branchcode } @@ -3057,12 +3061,12 @@ sub GetLatestAutoRenewDate { my $itemissue = Koha::Checkouts->find( { itemnumber => $itemnumber } ) or return; $borrowernumber ||= $itemissue->borrowernumber; - my $borrower = C4::Members::GetMember( borrowernumber => $borrowernumber ) + my $patron = Koha::Patrons->find( $borrowernumber ) or return; - my $branchcode = _GetCircControlBranch( $item, $borrower ); + my $branchcode = _GetCircControlBranch( $item, $patron->unblessed ); my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule( - { categorycode => $borrower->{categorycode}, + { categorycode => $patron->categorycode, itemtype => $item->{itype}, branchcode => $branchcode } @@ -3606,12 +3610,12 @@ sub ReturnLostItem{ my ( $borrowernumber, $itemnum ) = @_; MarkIssueReturned( $borrowernumber, $itemnum ); - my $borrower = C4::Members::GetMember( 'borrowernumber'=>$borrowernumber ); + my $patron = Koha::Patrons->find( $borrowernumber ); my $item = C4::Items::GetItem( $itemnum ); my $old_note = ($item->{'paidfor'} && ($item->{'paidfor'} ne q{})) ? $item->{'paidfor'}.' / ' : q{}; my @datearr = localtime(time); my $date = ( 1900 + $datearr[5] ) . "-" . ( $datearr[4] + 1 ) . "-" . $datearr[3]; - my $bor = "$borrower->{'firstname'} $borrower->{'surname'} $borrower->{'cardnumber'}"; + my $bor = $patron->firstname . ' ' . $patron->surname . ' ' . $patron->cardnumber; ModItem({ paidfor => $old_note."Paid for by $bor $date" }, undef, $itemnum); } @@ -3630,7 +3634,7 @@ sub LostItem{ # If a borrower lost the item, add a replacement cost to the their record if ( my $borrowernumber = $issues->{borrowernumber} ){ - my $borrower = C4::Members::GetMember( borrowernumber => $borrowernumber ); + my $patron = Koha::Patrons->find( $borrowernumber ); if (C4::Context->preference('WhenLostForgiveFine')){ my $fix = _FixOverduesOnReturn($borrowernumber, $itemnumber, 1, 0); # 1, 0 = exemptfine, no-dropbox @@ -3642,7 +3646,7 @@ sub LostItem{ #warn " $issues->{'borrowernumber'} / $itemnumber "; } - MarkIssueReturned($borrowernumber,$itemnumber,undef,undef,$borrower->{'privacy'}) if $mark_returned; + MarkIssueReturned($borrowernumber,$itemnumber,undef,undef,$patron->privacy) if $mark_returned; } } @@ -3727,9 +3731,9 @@ sub ProcessOfflineReturn { sub ProcessOfflineIssue { my $operation = shift; - my $borrower = C4::Members::GetMember( cardnumber => $operation->{cardnumber} ); + my $patron = Koha::Patrons->find( { cardnumber => $operation->{cardnumber} } ); - if ( $borrower->{borrowernumber} ) { + if ( $patron ) { my $item = Koha::Items->find({ barcode => $operation->{barcode} }); unless ($item) { return "Barcode not found."; @@ -3737,7 +3741,7 @@ sub ProcessOfflineIssue { my $itemnumber = $item->itemnumber; my $issue = GetOpenIssue( $itemnumber ); - if ( $issue and ( $issue->{borrowernumber} ne $borrower->{borrowernumber} ) ) { # Item already issued to another borrower, mark it returned + if ( $issue and ( $issue->{borrowernumber} ne $patron->borrowernumber ) ) { # Item already issued to another patron mark it returned MarkIssueReturned( $issue->{borrowernumber}, $itemnumber, @@ -3746,7 +3750,7 @@ sub ProcessOfflineIssue { ); } AddIssue( - $borrower, + $patron->unblessed, $operation->{'barcode'}, undef, 1, diff --git a/C4/HoldsQueue.pm b/C4/HoldsQueue.pm index 0f2ad221a2..218260e0fd 100755 --- a/C4/HoldsQueue.pm +++ b/C4/HoldsQueue.pm @@ -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}; diff --git a/C4/ILSDI/Services.pm b/C4/ILSDI/Services.pm index 387dac2727..5d35b2b1b4 100644 --- a/C4/ILSDI/Services.pm +++ b/C4/ILSDI/Services.pm @@ -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'); diff --git a/C4/Letters.pm b/C4/Letters.pm index ada27943b0..8fbe2e404d 100644 --- a/C4/Letters.pm +++ b/C4/Letters.pm @@ -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'}, diff --git a/C4/Members.pm b/C4/Members.pm index 73f3383018..3726e002c6 100644 --- a/C4/Members.pm +++ b/C4/Members.pm @@ -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 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, diff --git a/C4/Reserves.pm b/C4/Reserves.pm index 97dec5e1b6..6d52d6d10b 100644 --- a/C4/Reserves.pm +++ b/C4/Reserves.pm @@ -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 ); diff --git a/C4/SIP/ILS/Item.pm b/C4/SIP/ILS/Item.pm index 7f19e9d240..7ef1d3a5be 100644 --- a/C4/SIP/ILS/Item.pm +++ b/C4/SIP/ILS/Item.pm @@ -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; diff --git a/C4/SIP/ILS/Patron.pm b/C4/SIP/ILS/Patron.pm index 391926b06c..d548a18425 100644 --- a/C4/SIP/ILS/Patron.pm +++ b/C4/SIP/ILS/Patron.pm @@ -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}); diff --git a/C4/SIP/ILS/Transaction/Hold.pm b/C4/SIP/ILS/Transaction/Hold.pm index 50bc914da1..3d38bc4027 100644 --- a/C4/SIP/ILS/Transaction/Hold.pm +++ b/C4/SIP/ILS/Transaction/Hold.pm @@ -8,7 +8,7 @@ use Modern::Perl; use C4::SIP::ILS::Transaction; use C4::Reserves; # AddReserve -use C4::Members; # GetMember +use Koha::Patrons; use parent qw(C4::SIP::ILS::Transaction); use Koha::Items; @@ -41,8 +41,8 @@ sub do_hold { $self->ok(0); return $self; } - my $borrower = GetMember( 'cardnumber' => $self->{patron}->id ); - unless ($borrower) { + my $patron = Koha::Patrons->find( { cardnumber => $self->{patron}->id } ); + unless ($patron) { $self->screen_msg( 'No borrower matches cardnumber "' . $self->{patron}->id . '".' ); $self->ok(0); return $self; @@ -59,7 +59,7 @@ sub do_hold { $self->ok(0); return $self; } - AddReserve( $branch, $borrower->{borrowernumber}, $item->biblionumber ); + AddReserve( $branch, $patron->borrowernumber, $item->biblionumber ); # unfortunately no meaningful return value $self->ok(1); @@ -73,8 +73,8 @@ sub drop_hold { $self->ok(0); return $self; } - my $borrower = GetMember( 'cardnumber'=>$self->{patron}->id); - unless ($borrower) { + my $patron = Koha::Patrons->find( { cardnumber => $self->{patron}->id } ); + unless ($patron) { $self->screen_msg('No borrower matches cardnumber "' . $self->{patron}->id . '".'); $self->ok(0); return $self; @@ -84,7 +84,7 @@ sub drop_hold { CancelReserve({ biblionumber => $item->biblionumber, itemnumber => $self->{item}->id, - borrowernumber => $borrower->{borrowernumber} + borrowernumber => $patron->borrowernumber }); $self->ok(1); @@ -98,8 +98,8 @@ sub change_hold { $self->ok(0); return $self; } - my $borrower = GetMember( 'cardnumber'=>$self->{patron}->id); - unless ($borrower) { + my $patron = Koha::Patrons->find( { cardnumber => $self->{patron}->id } ); + unless ($patron) { $self->screen_msg('No borrower matches cardnumber "' . $self->{patron}->id . '".'); $self->ok(0); return $self; @@ -116,7 +116,7 @@ sub change_hold { $self->ok(0); return $self; } - ModReserve({ biblionumber => $item->biblionumber, borrowernumber => $borrower->{borrowernumber}, branchcode => $branch }); + ModReserve({ biblionumber => $item->biblionumber, borrowernumber => $patron->borrowernumber, branchcode => $branch }); $self->ok(1); return $self; diff --git a/C4/SIP/ILS/Transaction/Renew.pm b/C4/SIP/ILS/Transaction/Renew.pm index 699f5663a4..7e1e9b7496 100644 --- a/C4/SIP/ILS/Transaction/Renew.pm +++ b/C4/SIP/ILS/Transaction/Renew.pm @@ -8,7 +8,7 @@ use warnings; use strict; use C4::Circulation; -use C4::Members; +use Koha::Patrons; use Koha::DateUtils; use parent qw(C4::SIP::ILS::Transaction); @@ -60,8 +60,8 @@ sub do_renew_for { sub do_renew { my $self = shift; - my $borrower = GetMember( cardnumber => $self->{patron}->id ); - return $self->do_renew_for($borrower); + my $patron = Koha::Patrons->find( { cardnumber => $self->{patron}->id } ); + return $self->do_renew_for($patron->unblessed); } 1; diff --git a/C4/SIP/ILS/Transaction/RenewAll.pm b/C4/SIP/ILS/Transaction/RenewAll.pm index 845a5092b9..ee4f978c40 100644 --- a/C4/SIP/ILS/Transaction/RenewAll.pm +++ b/C4/SIP/ILS/Transaction/RenewAll.pm @@ -10,7 +10,7 @@ use Sys::Syslog qw(syslog); use C4::SIP::ILS::Item; -use C4::Members qw( GetMember ); +use Koha::Patrons; use parent qw(C4::SIP::ILS::Transaction::Renew); @@ -34,7 +34,7 @@ sub new { sub do_renew_all { my $self = shift; my $patron = $self->{patron}; # SIP's patron - my $borrower = GetMember( cardnumber => $patron->id ); # Koha's patron + my $borrower = Koha::Patrons->find( { cardnumber => $patron->id } )->unblessed; # Koha's patron my $all_ok = 1; $self->{renewed} = []; $self->{unrenewed} = []; diff --git a/acqui/acqui-home.pl b/acqui/acqui-home.pl index fe53174e3f..4da1eaf2dc 100755 --- a/acqui/acqui-home.pl +++ b/acqui/acqui-home.pl @@ -38,6 +38,7 @@ use C4::Members; use C4::Debug; use C4::Suggestions; use Koha::Acquisition::Currencies; +use Koha::Patrons; my $query = CGI->new; my ( $template, $loggedinuser, $cookie, $userflags ) = get_template_and_user( @@ -70,11 +71,12 @@ my @budget_loop; foreach my $budget ( @{$budget_arr} ) { next unless (CanUserUseBudget($loggedinuser, $budget, $userflags)); - my $member = GetMember( borrowernumber => $budget->{budget_owner_id} ); - if ($member) { - $budget->{budget_owner_firstname} = $member->{'firstname'}; - $budget->{budget_owner_surname} = $member->{'surname'}; - $budget->{budget_owner_borrowernumber} = $member->{'borrowernumber'}; + my $patron = Koha::Patrons->find( $budget->{budget_owner_id} ); + if ( $patron ) { + # FIXME should pass the entire object into budget_owner + $budget->{budget_owner_firstname} = $patron->firstname; + $budget->{budget_owner_surname} = $patron->surname; + $budget->{budget_owner_borrowernumber} = $patron->borrowernumber; } if ( !defined $budget->{budget_amount} ) { diff --git a/acqui/addorderiso2709.pl b/acqui/addorderiso2709.pl index 5d3ee540af..1469817891 100755 --- a/acqui/addorderiso2709.pl +++ b/acqui/addorderiso2709.pl @@ -47,6 +47,7 @@ use Koha::Libraries; use Koha::Acquisition::Currencies; use Koha::Acquisition::Order; use Koha::Acquisition::Booksellers; +use Koha::Patrons; my $input = new CGI; my ($template, $loggedinuser, $cookie, $userflags) = get_template_and_user({ @@ -310,14 +311,14 @@ if ($op eq ""){ } } else { # 3rd add order - my $patron = C4::Members::GetMember( borrowernumber => $loggedinuser ); + my $patron = Koha::Patrons->find( $loggedinuser ); # get quantity in the MARC record (1 if none) my $quantity = GetMarcQuantity($marcrecord, C4::Context->preference('marcflavour')) || 1; my %orderinfo = ( biblionumber => $biblionumber, basketno => $cgiparams->{'basketno'}, quantity => $c_quantity, - branchcode => $patron->{branchcode}, + branchcode => $patron->branchcode, budget_id => $c_budget_id, uncertainprice => 1, sort1 => $c_sort1, @@ -417,15 +418,14 @@ if ($op eq ""){ my $budgets = GetBudgets(); my $budget_id = @$budgets[0]->{'budget_id'}; # build bookfund list -my $borrower = GetMember( 'borrowernumber' => $loggedinuser ); -my ( $flags, $homebranch ) = ( $borrower->{'flags'}, $borrower->{'branchcode'} ); +my $patron = Koha::Patrons->find( $loggedinuser )->unblessed; my $budget = GetBudget($budget_id); # build budget list my $budget_loop = []; my $budgets_hierarchy = GetBudgetHierarchy; foreach my $r ( @{$budgets_hierarchy} ) { - next unless (CanUserUseBudget($borrower, $r, $userflags)); + next unless (CanUserUseBudget($patron, $r, $userflags)); if ( !defined $r->{budget_amount} || $r->{budget_amount} == 0 ) { next; } diff --git a/acqui/basket.pl b/acqui/basket.pl index 244e471a9b..b3dfa8bf11 100755 --- a/acqui/basket.pl +++ b/acqui/basket.pl @@ -30,7 +30,6 @@ use C4::Budgets; use C4::Contract; use C4::Debug; use C4::Biblio; -use C4::Members qw/GetMember/; #needed for permissions checking for changing basketgroup of a basket use C4::Items; use C4::Suggestions; use Koha::Biblios; @@ -41,6 +40,7 @@ use Date::Calc qw/Add_Delta_Days/; use Koha::Database; use Koha::EDI qw( create_edi_order get_edifact_ean ); use Koha::CsvProfiles; +use Koha::Patrons; =head1 NAME @@ -291,8 +291,8 @@ if ( $op eq 'list' ) { #if the basket is closed,and the user has the permission to edit basketgroups, display a list of basketgroups my ($basketgroup, $basketgroups); - my $staffuser = GetMember(borrowernumber => $loggedinuser); - if ($basket->{closedate} && haspermission($staffuser->{userid}, { acquisition => 'group_manage'} )) { + my $patron = Koha::Patrons->find($loggedinuser); + if ($basket->{closedate} && haspermission($patron->userid, { acquisition => 'group_manage'} )) { $basketgroups = GetBasketgroups($basket->{booksellerid}); for my $bg ( @{$basketgroups} ) { if ($basket->{basketgroupid} && $basket->{basketgroupid} == $bg->{id}){ @@ -321,8 +321,9 @@ if ( $op eq 'list' ) { my @basketusers_ids = GetBasketUsers($basketno); my @basketusers; foreach my $basketuser_id (@basketusers_ids) { - my $basketuser = GetMember(borrowernumber => $basketuser_id); - push @basketusers, $basketuser if $basketuser; + # FIXME Could be improved with a search -in + my $basket_patron = Koha::Patrons->find( $basketuser_id ); + push @basketusers, $basket_patron if $basket_patron; } my $active_currency = Koha::Acquisition::Currencies->get_active; @@ -375,7 +376,6 @@ if ( $op eq 'list' ) { if ($basket->{basketgroupid}){ $basketgroup = GetBasketgroup($basket->{basketgroupid}); } - my $borrower= GetMember('borrowernumber' => $loggedinuser); my $budgets = GetBudgetHierarchy; my $has_budgets = 0; foreach my $r (@{$budgets}) { diff --git a/acqui/basketgroup.pl b/acqui/basketgroup.pl index 9e50484de7..333e542e3b 100755 --- a/acqui/basketgroup.pl +++ b/acqui/basketgroup.pl @@ -52,11 +52,11 @@ use C4::Output; use CGI qw ( -utf8 ); use C4::Acquisition qw/CloseBasketgroup ReOpenBasketgroup GetOrders GetBasketsByBasketgroup GetBasketsByBookseller ModBasketgroup NewBasketgroup DelBasketgroup GetBasketgroups ModBasket GetBasketgroup GetBasket GetBasketGroupAsCSV/; -use C4::Members qw/GetMember/; use Koha::EDI qw/create_edi_order get_edifact_ean/; use Koha::Acquisition::Booksellers; use Koha::ItemTypes; +use Koha::Patrons; our $input=new CGI; @@ -273,9 +273,9 @@ if ( $op eq "add" ) { $template->param( closedbg => 0); } # determine default billing and delivery places depending on librarian homebranch and existing basketgroup data - my $borrower = GetMember( ( 'borrowernumber' => $loggedinuser ) ); - $billingplace = $billingplace || $borrower->{'branchcode'}; - $deliveryplace = $deliveryplace || $borrower->{'branchcode'}; + my $patron = Koha::Patrons->find( $loggedinuser ); # FIXME Not needed if billingplace and deliveryplace are set + $billingplace = $billingplace || $patron->branchcode; + $deliveryplace = $deliveryplace || $patron->branchcode; $template->param( billingplace => $billingplace ); $template->param( deliveryplace => $deliveryplace ); diff --git a/acqui/booksellers.pl b/acqui/booksellers.pl index 6081269056..de39f675e6 100755 --- a/acqui/booksellers.pl +++ b/acqui/booksellers.pl @@ -60,10 +60,10 @@ use C4::Output; use CGI qw ( -utf8 ); use C4::Acquisition qw/ GetBasketsInfosByBookseller CanUserManageBasket /; -use C4::Members qw/GetMember/; use C4::Context; use Koha::Acquisition::Booksellers; +use Koha::Patrons; my $query = CGI->new; my ( $template, $loggedinuser, $cookie, $userflags ) = get_template_and_user( @@ -99,8 +99,10 @@ if ( $supplier_count == 1 ) { } my $uid; +# FIXME This script should only be accessed by a valid logged in patron if ($loggedinuser) { - $uid = GetMember( borrowernumber => $loggedinuser )->{userid}; + # FIXME Should not be needed, logged in patron should be cached + $uid = Koha::Patrons->find( $loggedinuser )->userid; } my $userenv = C4::Context::userenv; @@ -130,13 +132,13 @@ for my $vendor (@suppliers) { for my $basket ( @{$baskets} ) { if (CanUserManageBasket($loggedinuser, $basket, $userflags)) { - my $member = GetMember( borrowernumber => $basket->{authorisedby} ); + my $patron = Koha::Patrons->find( $basket->{authorisedby} ); foreach (qw(total_items total_biblios expected_items)) { $basket->{$_} ||= 0; } - if($member) { - $basket->{authorisedby_firstname} = $member->{firstname}; - $basket->{authorisedby_surname} = $member->{surname}; + if ( $patron ) { + $basket->{authorisedby_firstname} = $patron->firstname; + $basket->{authorisedby_surname} = $patron->surname; } if ($basket->{basketgroupid}) { my $basketgroup = C4::Acquisition::GetBasketgroup($basket->{basketgroupid}); diff --git a/acqui/neworderbiblio.pl b/acqui/neworderbiblio.pl index 8c492b74e9..2e65569b15 100755 --- a/acqui/neworderbiblio.pl +++ b/acqui/neworderbiblio.pl @@ -64,13 +64,13 @@ use C4::Biblio; use C4::Auth; use C4::Output; use C4::Koha; -use C4::Members qw/ GetMember /; use C4::Budgets qw/ GetBudgetHierarchy /; use Koha::Acquisition::Booksellers; use Koha::SearchEngine; use Koha::SearchEngine::Search; use Koha::SearchEngine::QueryBuilder; +use Koha::Patrons; my $input = new CGI; @@ -133,8 +133,8 @@ foreach my $result ( @{$marcresults} ) { } -my $borrower= GetMember('borrowernumber' => $loggedinuser); -my $budgets = GetBudgetHierarchy(q{},$borrower->{branchcode},$borrower->{borrowernumber}); +my $patron = Koha::Patrons->find( $loggedinuser ); +my $budgets = GetBudgetHierarchy(q{},$patron->branchcode,$patron->borrowernumber); my $has_budgets = 0; foreach my $r (@{$budgets}) { if (!defined $r->{budget_amount} || $r->{budget_amount} == 0) { diff --git a/acqui/neworderempty.pl b/acqui/neworderempty.pl index c2a5e6fe49..85e0962349 100755 --- a/acqui/neworderempty.pl +++ b/acqui/neworderempty.pl @@ -90,6 +90,7 @@ use C4::ImportBatch qw/GetImportRecordMarc SetImportRecordStatus/; use Koha::Acquisition::Booksellers; use Koha::Acquisition::Currencies; use Koha::ItemTypes; +use Koha::Patrons; our $input = new CGI; my $booksellerid = $input->param('booksellerid'); # FIXME: else ERROR! @@ -198,8 +199,9 @@ else { #modify order @order_user_ids = GetOrderUsers($ordernumber); foreach my $order_user_id (@order_user_ids) { - my $order_user = GetMember(borrowernumber => $order_user_id); - push @order_users, $order_user if $order_user; + # FIXME Could be improved with search -in + my $order_patron = Koha::Patrons->find( $order_user_id ); + push @order_users, $order_patron if $order_patron; } } @@ -210,15 +212,14 @@ my @currencies = Koha::Acquisition::Currencies->search; my $active_currency = Koha::Acquisition::Currencies->get_active; # build bookfund list -my $borrower= GetMember('borrowernumber' => $loggedinuser); -my ( $flags, $homebranch )= ($borrower->{'flags'},$borrower->{'branchcode'}); +my $patron = Koha::Patrons->find( $loggedinuser )->unblessed; my $budget = GetBudget($budget_id); # build budget list my $budget_loop = []; my $budgets = GetBudgetHierarchy; foreach my $r (@{$budgets}) { - next unless (CanUserUseBudget($borrower, $r, $userflags)); + next unless (CanUserUseBudget($patron, $r, $userflags)); if (!defined $r->{budget_amount} || $r->{budget_amount} <0) { next; } diff --git a/acqui/orderreceive.pl b/acqui/orderreceive.pl index 752beba2f8..f09e3644e2 100755 --- a/acqui/orderreceive.pl +++ b/acqui/orderreceive.pl @@ -76,6 +76,7 @@ use C4::Koha; use Koha::Acquisition::Booksellers; use Koha::DateUtils qw( dt_from_string ); use Koha::ItemTypes; +use Koha::Patrons; my $input = new CGI; @@ -180,7 +181,7 @@ if( defined $order->{tax_rate_on_receiving} ) { my $suggestion = GetSuggestionInfoFromBiblionumber($order->{biblionumber}); my $authorisedby = $order->{authorisedby}; -my $member = GetMember( borrowernumber => $authorisedby ); +my $authorised_patron = Koha::Patrons->find( $authorisedby ); my $budget = GetBudget( $order->{budget_id} ); @@ -213,8 +214,8 @@ $template->param( ecost => $ecost, unitprice => $unitprice, tax_rate => $tax_rate, - memberfirstname => $member->{firstname} || "", - membersurname => $member->{surname} || "", + memberfirstname => $authorised_patron->firstname || "", + membersurname => $authorised_patron->surname || "", invoiceid => $invoice->{invoiceid}, invoice => $invoice->{invoicenumber}, datereceived => $datereceived, @@ -226,7 +227,7 @@ $template->param( gst_values => \@gst_values, ); -my $borrower = GetMember( 'borrowernumber' => $loggedinuser ); +my $patron = Koha::Patrons->find( $loggedinuser )->unblessed; my @budget_loop; my $periods = GetBudgetPeriods( ); foreach my $period (@$periods) { @@ -237,7 +238,7 @@ foreach my $period (@$periods) { my $budget_hierarchy = GetBudgetHierarchy( $period->{'budget_period_id'} ); my @funds; foreach my $r ( @{$budget_hierarchy} ) { - next unless ( CanUserUseBudget( $borrower, $r, $userflags ) ); + next unless ( CanUserUseBudget( $patron, $r, $userflags ) ); if ( !defined $r->{budget_amount} || $r->{budget_amount} == 0 ) { next; } diff --git a/acqui/transferorder.pl b/acqui/transferorder.pl index 716c721913..219fb32f99 100755 --- a/acqui/transferorder.pl +++ b/acqui/transferorder.pl @@ -26,7 +26,6 @@ use C4::Auth; use C4::Output; use C4::Context; use C4::Acquisition; -use C4::Members; use Koha::Acquisition::Booksellers; my $input = new CGI; @@ -89,8 +88,8 @@ if( $basketno && $ordernumber) { for( my $i = 0 ; $i < $basketscount ; $i++ ){ my %line; %line = %{ $baskets->[$i] }; - my $createdby = GetMember(borrowernumber => $line{authorisedby}); - $line{createdby} = "$createdby->{surname}, $createdby->{firstname}"; + my $createdby = Koha::Patrons->find( $line{authorisedby} ); + $line{createdby} = $createdby ? $createdby->surname . ', ' . $createdby->firstname : ''; push @basketsloop, \%line unless $line{closedate}; } $template->param( diff --git a/admin/aqbudgets.pl b/admin/aqbudgets.pl index 97664df13b..0dce9ddd89 100755 --- a/admin/aqbudgets.pl +++ b/admin/aqbudgets.pl @@ -29,12 +29,12 @@ use C4::Auth qw/get_user_subpermissions/; use C4::Auth; use C4::Acquisition; use C4::Budgets; -use C4::Members; use C4::Context; use C4::Output; use C4::Koha; use C4::Debug; use Koha::Acquisition::Currencies; +use Koha::Patrons; my $input = new CGI; my $dbh = C4::Context->dbh; @@ -89,8 +89,6 @@ if ( $budget_period_id ) { # USED FOR PERMISSION COMPARISON LATER my $borrower_id = $template->{VARS}->{'USER_INFO'}->{'borrowernumber'}; -my $user = C4::Members::GetMember( borrowernumber => $borrower_id ); -my $user_branchcode = $user->{'branchcode'}; $template->param( show_mine => $show_mine, @@ -117,8 +115,8 @@ if ($op eq 'add_form') { exit; } $dropbox_disabled = BudgetHasChildren($budget_id); - my $borrower = &GetMember( borrowernumber=>$budget->{budget_owner_id} ); - $budget->{budget_owner_name} = ( $borrower ? $borrower->{'firstname'} . ' ' . $borrower->{'surname'} : '' ); + my $patron = Koha::Patrons->find( $budget->{budget_owner_id} ); + $budget->{budget_owner_name} = ( $patron ? $patron->firstname . ' ' . $patron->surname : '' ); } # build budget hierarchy @@ -155,11 +153,10 @@ if ($op eq 'add_form') { my @budgetusers = GetBudgetUsers($budget->{budget_id}); my @budgetusers_loop; foreach my $borrowernumber (@budgetusers) { - my $member = C4::Members::GetMember( - borrowernumber => $borrowernumber); + my $patron = Koha::Patrons->find( $borrowernumber ); push @budgetusers_loop, { - firstname => $member->{firstname}, - surname => $member->{surname}, + firstname => $patron->firstname, # FIXME Should pass the patron object + surname => $patron->surname, borrowernumber => $borrowernumber }; } diff --git a/catalogue/ISBDdetail.pl b/catalogue/ISBDdetail.pl index 60b6053dc4..f5fa00a2be 100755 --- a/catalogue/ISBDdetail.pl +++ b/catalogue/ISBDdetail.pl @@ -43,12 +43,12 @@ use CGI qw ( -utf8 ); use C4::Koha; use C4::Biblio; use C4::Items; -use C4::Members; # to use GetMember use C4::Serials; # CountSubscriptionFromBiblionumber use C4::Search; # enabled_staff_search_views use C4::Acquisition qw(GetOrdersByBiblionumber); use Koha::Biblios; +use Koha::Patrons; use Koha::RecordProcessor; @@ -107,12 +107,12 @@ my $res = GetISBDView({ }); if($query->cookie("holdfor")){ - my $holdfor_patron = GetMember('borrowernumber' => $query->cookie("holdfor")); + my $holdfor_patron = Koha::Patrons->find( $query->cookie("holdfor") ); $template->param( holdfor => $query->cookie("holdfor"), - holdfor_surname => $holdfor_patron->{'surname'}, - holdfor_firstname => $holdfor_patron->{'firstname'}, - holdfor_cardnumber => $holdfor_patron->{'cardnumber'}, + holdfor_surname => $holdfor_patron->surname, + holdfor_firstname => $holdfor_patron->firstname, + holdfor_cardnumber => $holdfor_patron->cardnumber, ); } diff --git a/catalogue/MARCdetail.pl b/catalogue/MARCdetail.pl index 6a6bdb4278..2152ffd299 100755 --- a/catalogue/MARCdetail.pl +++ b/catalogue/MARCdetail.pl @@ -56,12 +56,12 @@ use MARC::Record; use C4::Biblio; use C4::Items; use C4::Acquisition; -use C4::Members; # to use GetMember use C4::Serials; #uses getsubscriptionsfrombiblionumber GetSubscriptionsFromBiblionumber use C4::Search; # enabled_staff_search_views use Koha::Biblios; use Koha::BiblioFrameworks; +use Koha::Patrons; use List::MoreUtils qw( uniq ); @@ -105,12 +105,12 @@ my $tagslib = &GetMarcStructure(1,$frameworkcode); my $biblio = GetBiblioData($biblionumber); if($query->cookie("holdfor")){ - my $holdfor_patron = GetMember('borrowernumber' => $query->cookie("holdfor")); + my $holdfor_patron = Koha::Patrons->find( $query->cookie("holdfor") ); $template->param( holdfor => $query->cookie("holdfor"), - holdfor_surname => $holdfor_patron->{'surname'}, - holdfor_firstname => $holdfor_patron->{'firstname'}, - holdfor_cardnumber => $holdfor_patron->{'cardnumber'}, + holdfor_surname => $holdfor_patron->surname, + holdfor_firstname => $holdfor_patron->firstname, + holdfor_cardnumber => $holdfor_patron->cardnumber, ); } diff --git a/catalogue/detail.pl b/catalogue/detail.pl index 3a632b6049..221532fdf3 100755 --- a/catalogue/detail.pl +++ b/catalogue/detail.pl @@ -29,7 +29,6 @@ use C4::Biblio; use C4::Items; use C4::Circulation; use C4::Reserves; -use C4::Members; # to use GetMember use C4::Serials; use C4::XISBN qw(get_xisbns get_biblionumber_from_isbn); use C4::External::Amazon; @@ -75,12 +74,13 @@ if ( not defined $record ) { } if($query->cookie("holdfor")){ - my $holdfor_patron = GetMember('borrowernumber' => $query->cookie("holdfor")); + my $holdfor_patron = Koha::Patrons->find( $query->cookie("holdfor") ); $template->param( + # FIXME Should pass the patron object holdfor => $query->cookie("holdfor"), - holdfor_surname => $holdfor_patron->{'surname'}, - holdfor_firstname => $holdfor_patron->{'firstname'}, - holdfor_cardnumber => $holdfor_patron->{'cardnumber'}, + holdfor_surname => $holdfor_patron->surname, + holdfor_firstname => $holdfor_patron->firstname, + holdfor_cardnumber => $holdfor_patron->cardnumber, ); } @@ -262,14 +262,14 @@ foreach my $item (@items) { my $item_object = Koha::Items->find( $item->{itemnumber} ); my $holds = $item_object->current_holds; if ( my $first_hold = $holds->next ) { - my $ItemBorrowerReserveInfo = C4::Members::GetMember( borrowernumber => $first_hold->borrowernumber); # FIXME could be improved + my $patron = Koha::Patrons->find( $first_hold->borrowernumber ); $item->{backgroundcolor} = 'reserved'; $item->{reservedate} = $first_hold->reservedate; $item->{ReservedForBorrowernumber} = $first_hold->borrowernumber; - $item->{ReservedForSurname} = $ItemBorrowerReserveInfo->{'surname'}; - $item->{ReservedForFirstname} = $ItemBorrowerReserveInfo->{'firstname'}; + $item->{ReservedForSurname} = $patron->surname; + $item->{ReservedForFirstname} = $patron->firstname; $item->{ExpectedAtLibrary} = $first_hold->branchcode; - $item->{Reservedcardnumber} = $ItemBorrowerReserveInfo->{'cardnumber'}; + $item->{Reservedcardnumber} = $patron->cardnumber; # Check waiting status $item->{waitingdate} = $first_hold->waitingdate; } diff --git a/catalogue/imageviewer.pl b/catalogue/imageviewer.pl index c1db9ebd8e..06c4bbed92 100755 --- a/catalogue/imageviewer.pl +++ b/catalogue/imageviewer.pl @@ -30,6 +30,7 @@ use C4::Search; use C4::Acquisition qw(GetOrdersByBiblionumber); use Koha::Biblios; +use Koha::Patrons; my $query = new CGI; my ( $template, $borrowernumber, $cookie ) = get_template_and_user( @@ -58,13 +59,12 @@ foreach my $item (@items) { } if ( $query->cookie("holdfor") ) { - my $holdfor_patron = - GetMember( 'borrowernumber' => $query->cookie("holdfor") ); + my $holdfor_patron = Koha::Patrons->find( $query->cookie("holdfor") ); $template->param( holdfor => $query->cookie("holdfor"), - holdfor_surname => $holdfor_patron->{'surname'}, - holdfor_firstname => $holdfor_patron->{'firstname'}, - holdfor_cardnumber => $holdfor_patron->{'cardnumber'}, + holdfor_surname => $holdfor_patron->surname, + holdfor_firstname => $holdfor_patron->firstname, + holdfor_cardnumber => $holdfor_patron->cardnumber, ); } diff --git a/catalogue/labeledMARCdetail.pl b/catalogue/labeledMARCdetail.pl index cd07f73135..090326d450 100755 --- a/catalogue/labeledMARCdetail.pl +++ b/catalogue/labeledMARCdetail.pl @@ -27,12 +27,12 @@ use C4::Context; use C4::Output; use C4::Biblio; use C4::Items; -use C4::Members; # to use GetMember use C4::Search; # enabled_staff_search_views use C4::Acquisition qw(GetOrdersByBiblionumber); use Koha::Biblios; use Koha::BiblioFrameworks; +use Koha::Patrons; my $query = new CGI; my $dbh = C4::Context->dbh; @@ -71,12 +71,12 @@ my $tagslib = GetMarcStructure(1,$frameworkcode); my $biblio = GetBiblioData($biblionumber); if($query->cookie("holdfor")){ - my $holdfor_patron = GetMember('borrowernumber' => $query->cookie("holdfor")); + my $holdfor_patron = Koha::Patrons->find( $query->cookie("holdfor") ); $template->param( holdfor => $query->cookie("holdfor"), - holdfor_surname => $holdfor_patron->{'surname'}, - holdfor_firstname => $holdfor_patron->{'firstname'}, - holdfor_cardnumber => $holdfor_patron->{'cardnumber'}, + holdfor_surname => $holdfor_patron->surname, + holdfor_firstname => $holdfor_patron->firstname, + holdfor_cardnumber => $holdfor_patron->cardnumber, ); } diff --git a/catalogue/moredetail.pl b/catalogue/moredetail.pl index 04a0e9d43f..85b491a006 100755 --- a/catalogue/moredetail.pl +++ b/catalogue/moredetail.pl @@ -30,7 +30,6 @@ use C4::Acquisition; use C4::Output; use C4::Auth; use C4::Serials; -use C4::Members; # to use GetMember use C4::Search; # enabled_staff_search_views use Koha::Acquisition::Booksellers; @@ -53,12 +52,12 @@ my ($template, $loggedinuser, $cookie) = get_template_and_user( ); if($query->cookie("holdfor")){ - my $holdfor_patron = GetMember('borrowernumber' => $query->cookie("holdfor")); + my $holdfor_patron = Koha::Patrons->find( $query->cookie("holdfor") ); $template->param( holdfor => $query->cookie("holdfor"), - holdfor_surname => $holdfor_patron->{'surname'}, - holdfor_firstname => $holdfor_patron->{'firstname'}, - holdfor_cardnumber => $holdfor_patron->{'cardnumber'}, + holdfor_surname => $holdfor_patron->surname, + holdfor_firstname => $holdfor_patron->firstname, + holdfor_cardnumber => $holdfor_patron->cardnumber, ); } @@ -190,9 +189,9 @@ foreach my $item (@items){ unless ($hidepatronname) { if ( $item->{'borrowernumber'} ) { - my $curr_borrower = GetMember('borrowernumber' => $item->{'borrowernumber'} ); - $item->{borrowerfirstname} = $curr_borrower->{'firstname'}; - $item->{borrowersurname} = $curr_borrower->{'surname'}; + my $curr_borrower = Koha::Patrons->find( $item->{borrowernumber} ); + $item->{borrowerfirstname} = $curr_borrower->firstname; + $item->{borrowersurname} = $curr_borrower->surname; } } diff --git a/catalogue/search.pl b/catalogue/search.pl index 8488f832a0..e4ca11aff1 100755 --- a/catalogue/search.pl +++ b/catalogue/search.pl @@ -146,16 +146,16 @@ use C4::Auth qw(:DEFAULT get_session); use C4::Search; use C4::Languages qw(getLanguages); use C4::Koha; -use C4::Members qw(GetMember); use URI::Escape; use POSIX qw(ceil floor); use C4::Search::History; use Koha::ItemTypes; use Koha::LibraryCategories; -use Koha::Virtualshelves; +use Koha::Patrons; use Koha::SearchEngine::Search; use Koha::SearchEngine::QueryBuilder; +use Koha::Virtualshelves; use URI::Escape; @@ -196,12 +196,12 @@ if (C4::Context->preference("IntranetNumbersPreferPhrase")) { } if($cgi->cookie("holdfor")){ - my $holdfor_patron = GetMember('borrowernumber' => $cgi->cookie("holdfor")); + my $holdfor_patron = Koha::Patrons->find( $cgi->cookie("holdfor") ); $template->param( holdfor => $cgi->cookie("holdfor"), - holdfor_surname => $holdfor_patron->{'surname'}, - holdfor_firstname => $holdfor_patron->{'firstname'}, - holdfor_cardnumber => $holdfor_patron->{'cardnumber'}, + holdfor_surname => $holdfor_patron->surname, + holdfor_firstname => $holdfor_patron->firstname, + holdfor_cardnumber => $holdfor_patron->cardnumber, ); } diff --git a/cataloguing/additem.pl b/cataloguing/additem.pl index 03adf465c6..9387072a65 100755 --- a/cataloguing/additem.pl +++ b/cataloguing/additem.pl @@ -34,6 +34,7 @@ use Koha::DateUtils; use Koha::Items; use Koha::ItemTypes; use Koha::Libraries; +use Koha::Patrons; use List::MoreUtils qw/any/; use C4::Search; use Storable qw(thaw freeze); @@ -402,7 +403,7 @@ my ($template, $loggedinuser, $cookie) # Does the user have a restricted item editing permission? -my $uid = $loggedinuser ? GetMember( borrowernumber => $loggedinuser )->{userid} : undef; +my $uid = Koha::Patrons->find( $loggedinuser )->userid; my $restrictededition = $uid ? haspermission($uid, {'editcatalogue' => 'edit_items_restricted'}) : undef; # In case user is a superlibrarian, editing is not restricted $restrictededition = 0 if ($restrictededition != 0 && C4::Context->IsSuperLibrarian()); diff --git a/circ/branchtransfers.pl b/circ/branchtransfers.pl index 87104c22fd..32e77f2aa5 100755 --- a/circ/branchtransfers.pl +++ b/circ/branchtransfers.pl @@ -34,6 +34,7 @@ use C4::Members; use Koha::BiblioFrameworks; use Koha::AuthorisedValues; use Koha::Items; +use Koha::Patrons; ############################################### # Getting state @@ -205,11 +206,13 @@ foreach my $code ( keys %$messages ) { elsif ( $code eq 'WasReturned' ) { $err{errwasreturned} = 1; $err{borrowernumber} = $messages->{'WasReturned'}; - my $borrower = GetMember('borrowernumber'=>$messages->{'WasReturned'}); - $err{title} = $borrower->{'title'}; - $err{firstname} = $borrower->{'firstname'}; - $err{surname} = $borrower->{'surname'}; - $err{cardnumber} = $borrower->{'cardnumber'}; + my $patron = Koha::Patrons->find( $messages->{'WasReturned'} ); + if ( $patron ) { # Just in case... + $err{title} = $patron->title; + $err{firstname} = $patron->firstname; + $err{surname} = $patron->surname; + $err{cardnumber} = $patron->cardnumber; + } } $err{errdesteqholding} = ( $code eq 'DestinationEqualsHolding' ); push( @errmsgloop, \%err ); diff --git a/circ/circulation.pl b/circ/circulation.pl index bfe88cfd3d..fad8623fc3 100755 --- a/circ/circulation.pl +++ b/circ/circulation.pl @@ -22,6 +22,8 @@ # You should have received a copy of the GNU General Public License # along with Koha; if not, see . +# FIXME There are too many calls to Koha::Patrons->find in this script + use strict; use warnings; use CGI qw ( -utf8 ); @@ -44,14 +46,13 @@ use CGI::Session; use C4::Members::Attributes qw(GetBorrowerAttributes); use Koha::AuthorisedValues; use Koha::CsvProfiles; -use Koha::Patron; +use Koha::Patrons; use Koha::Patron::Debarments qw(GetDebarments); use Koha::DateUtils; use Koha::Database; use Koha::BiblioFrameworks; use Koha::Items; use Koha::Patron::Messages; -use Koha::Patron::Images; use Koha::SearchEngine; use Koha::SearchEngine::Search; use Koha::Patron::Modifications; @@ -105,13 +106,14 @@ $barcodes = [ uniq @$barcodes ]; my $template_name = q|circ/circulation.tt|; my $borrowernumber = $query->param('borrowernumber'); -my $borrower = $borrowernumber ? GetMember( borrowernumber => $borrowernumber ) : undef; +my $patron = $borrowernumber ? Koha::Patrons->find( $borrowernumber ) : undef; my $batch = $query->param('batch'); my $batch_allowed = 0; if ( $batch && C4::Context->preference('BatchCheckouts') ) { $template_name = q|circ/circulation_batch_checkouts.tt|; my @batch_category_codes = split '\|', C4::Context->preference('BatchCheckoutsValidCategories'); - if ( grep {/^$borrower->{categorycode}$/} @batch_category_codes ) { + my $categorycode = $patron->categorycode; + if ( $categorycode && grep {/^$categorycode$/} @batch_category_codes ) { $batch_allowed = 1; } else { $barcodes = []; @@ -232,9 +234,9 @@ if ( $print eq 'yes' && $borrowernumber ne '' ) { # my $message; if ($findborrower) { - my $borrower = C4::Members::GetMember( cardnumber => $findborrower ); - if ( $borrower ) { - $borrowernumber = $borrower->{borrowernumber}; + my $patron = Koha::Patrons->find( { cardnumber => $findborrower } ); + if ( $patron ) { + $borrowernumber = $patron->borrowernumber; } else { my $dt_params = { iDisplayLength => -1 }; my $results = C4::Utils::DataTables::Members::search( @@ -259,10 +261,8 @@ if ($findborrower) { } # get the borrower information..... -my $patron; if ($borrowernumber) { $patron = Koha::Patrons->find( $borrowernumber ); - $borrower = GetMember( borrowernumber => $borrowernumber ); my $overdues = $patron->get_overdues; my $issues = $patron->checkouts; my $balance = $patron->account->balance; @@ -280,7 +280,7 @@ if ($borrowernumber) { # check for NotifyBorrowerDeparture elsif ( $patron->is_going_to_expire ) { # borrower card soon to expire warn librarian - $template->param( "warndeparture" => $borrower->{dateexpiry} , + $template->param( "warndeparture" => $patron->dateexpiry , ); if (C4::Context->preference('ReturnBeforeExpiry')){ $template->param("returnbeforeexpiry" => 1); @@ -294,12 +294,12 @@ if ($borrowernumber) { if ( $patron and $patron->is_debarred ) { $template->param( - 'userdebarred' => $borrower->{debarred}, - 'debarredcomment' => $borrower->{debarredcomment}, + 'userdebarred' => $patron->debarred, + 'debarredcomment' => $patron->debarredcomment, ); - if ( $borrower->{debarred} ne "9999-12-31" ) { - $template->param( 'userdebarreddate' => $borrower->{debarred} ); + if ( $patron->debarred ne "9999-12-31" ) { + $template->param( 'userdebarreddate' => $patron->debarred ); } } @@ -315,7 +315,7 @@ if (@$barcodes) { my $template_params = { barcode => $barcode }; # always check for blockers on issuing my ( $error, $question, $alerts, $messages ) = CanBookBeIssued( - $borrower, + $patron->unblessed, $barcode, $datedue, $inprocess, undef, @@ -402,7 +402,7 @@ if (@$barcodes) { } unless($confirm_required) { my $switch_onsite_checkout = exists $messages->{ONSITE_CHECKOUT_WILL_BE_SWITCHED}; - my $issue = AddIssue( $borrower, $barcode, $datedue, $cancelreserve, undef, undef, { onsite_checkout => $onsite_checkout, auto_renew => $session->param('auto_renew'), switch_onsite_checkout => $switch_onsite_checkout, } ); + my $issue = AddIssue( $patron->unblessed, $barcode, $datedue, $cancelreserve, undef, undef, { onsite_checkout => $onsite_checkout, auto_renew => $session->param('auto_renew'), switch_onsite_checkout => $switch_onsite_checkout, } ); $template_params->{issue} = $issue; $session->clear('auto_renew'); $inprocess = 1; @@ -439,11 +439,6 @@ if (@$barcodes) { } } -# reload the borrower info for the sake of reseting the flags..... -if ($borrowernumber) { - $borrower = GetMember( borrowernumber => $borrowernumber ); -} - ################################################################################## # BUILD HTML # show all reserves of this borrower, and the position of the reservation .... @@ -455,11 +450,12 @@ if ($borrowernumber) { WaitingHolds => $waiting_holds, ); - $template->param( adultborrower => 1 ) if ( $borrower->{category_type} eq 'A' || $borrower->{category_type} eq 'I' ); + my $category_type = $patron->category->category_type; + $template->param( adultborrower => 1 ) if ( $category_type eq 'A' || $category_type eq 'I' ); } #title -my $flags = $borrower ? C4::Members::patronflags( $borrower ) : {}; +my $flags = $patron ? C4::Members::patronflags( $patron->unblessed ) : {}; foreach my $flag ( sort keys %$flags ) { $flags->{$flag}->{'message'} =~ s#\n#
#g; if ( $flags->{$flag}->{'noissues'} ) { @@ -547,7 +543,7 @@ $amountold =~ s/^.*\$//; # remove upto the $, if any my ( $total, $accts, $numaccts) = GetMemberAccountRecords( $borrowernumber ); -if ( $borrowernumber && $borrower->{'category_type'} eq 'C') { +if ( $patron && $patron->category->category_type eq 'C') { my $patron_categories = Koha::Patron::Categories->search_limited({ category_type => 'A' }, {order_by => ['categorycode']}); $template->param( 'CATCODE_MULTI' => 1) if $patron_categories->count > 1; $template->param( 'catcode' => $patron_categories->next ) if $patron_categories->count == 1; @@ -595,10 +591,20 @@ my $relatives_issues_count = Koha::Database->new()->schema()->resultset('Issue') ->count( { borrowernumber => \@relatives } ); -my $av = Koha::AuthorisedValues->search({ category => 'ROADTYPE', authorised_value => $borrower->{streettype} }); -my $roadtype = $av->count ? $av->next->lib : ''; - -$template->param(%$borrower); +if ( $patron ) { + my $av = Koha::AuthorisedValues->search({ category => 'ROADTYPE', authorised_value => $patron->streettype }); + my $roadtype = $av->count ? $av->next->lib : ''; + $template->param( + %{ $patron->unblessed }, + borrower => $patron->unblessed, + roadtype => $roadtype, + patron => $patron, + categoryname => $patron->category->description, + expiry => $patron->dateexpiry, + is_child => ( $patron->category->category_type eq 'C' ), + picture => ( $patron->image ? 1 : 0 ), + ); +} # Restore date if changed by holds and/or save stickyduedate to session if ($restoreduedatespec || $stickyduedate) { @@ -612,15 +618,10 @@ if ($restoreduedatespec || $stickyduedate) { } $template->param( - patron => $patron, messages => $messages, - borrower => $borrower, borrowernumber => $borrowernumber, - categoryname => $borrower->{'description'}, branch => $branch, was_renewed => scalar $query->param('was_renewed') ? 1 : 0, - expiry => $borrower->{'dateexpiry'}, - roadtype => $roadtype, amountold => $amountold, barcodes => $barcodes, stickyduedate => $stickyduedate, @@ -629,7 +630,6 @@ $template->param( message => $message, totaldue => sprintf('%.2f', $total), inprocess => $inprocess, - is_child => ($borrowernumber && $borrower->{'category_type'} eq 'C'), $view => 1, batch_allowed => $batch_allowed, batch => $batch, @@ -643,8 +643,6 @@ $template->param( relatives_borrowernumbers => \@relatives, ); -my $patron_image = Koha::Patron::Images->find($borrower->{borrowernumber}); -$template->param( picture => 1 ) if $patron_image; if ( C4::Context->preference("ExportCircHistory") ) { $template->param(csv_profiles => [ Koha::CsvProfiles->search({ type => 'marc' }) ]); diff --git a/circ/returns.pl b/circ/returns.pl index 984f030842..26286e8fc2 100755 --- a/circ/returns.pl +++ b/circ/returns.pl @@ -30,6 +30,8 @@ script to execute returns of books use strict; use warnings; +# FIXME There are weird things going on with $patron and $borrowernumber in this script + use Carp 'verbose'; $SIG{ __DIE__ } = sub { Carp::confess( @_ ) }; @@ -167,8 +169,8 @@ if ( $query->param('reserve_id') ) { # check if we have other reserves for this document, if we have a return send the message of transfer my ( $messages, $nextreservinfo ) = GetOtherReserves($itemnumber); - my $borr = GetMember( borrowernumber => $nextreservinfo ); - my $name = $borr->{'surname'} . ", " . $borr->{'title'} . " " . $borr->{'firstname'}; + my $patron = Koha::Patrons->find( $nextreservinfo ); + my $name = $patron->surname . ", " . $patron->title . " " . $patron->firstname; if ( $messages->{'transfert'} ) { $template->param( itemtitle => $biblio->title, @@ -177,10 +179,10 @@ if ( $query->param('reserve_id') ) { iteminfo => $biblio->author, name => $name, borrowernumber => $borrowernumber, - borcnum => $borr->{'cardnumber'}, - borfirstname => $borr->{'firstname'}, - borsurname => $borr->{'surname'}, - borcategory => $borr->{'description'}, + borcnum => $patron->cardnumber, + borfirstname => $patron->firstname, + borsurname => $patron->surname, + borcategory => $patron->category->description, diffbranch => 1, ); } @@ -399,27 +401,31 @@ if ( $messages->{'WrongTransfer'} and not $messages->{'WasTransfered'}) { ); my $reserve = $messages->{'ResFound'}; - my $borr = C4::Members::GetMember( borrowernumber => $reserve->{'borrowernumber'} ); - my $name = $borr->{'surname'} . ", " . $borr->{'title'} . " " . $borr->{'firstname'}; + if ( $reserve ) { + my $patron = Koha::Patrons->find( $reserve->{'borrowernumber'} ); + my $name = $patron->surname . ", " . $patron->title . " " . $patron->firstname; + $template->param( + # FIXME The full patron object should be passed to the template + wname => $name, + wborfirstname => $patron->firstname, + wborsurname => $patron->surname, + wborcategory => $patron->category->description, + wbortitle => $patron->title, + wborphone => $patron->phone, + wboremail => $patron->email, + streetnumber => $patron->streetnumber, + address => $patron->address, + address2 => $patron->address2, + city => $patron->city, + zipcode => $patron->zipcode, + state => $patron->state, + country => $patron->country, + wborrowernumber => $reserve->{'borrowernumber'}, + wborcnum => $patron->cardnumber, + ); + } $template->param( - wname => $name, - wborfirstname => $borr->{'firstname'}, - wborsurname => $borr->{'surname'}, - wborcategory => $borr->{'description'}, - wbortitle => $borr->{'title'}, - wborphone => $borr->{'phone'}, - wboremail => $borr->{'email'}, - streetnumber => $borr->{streetnumber}, - streettype => $borr->{streettype}, - address => $borr->{'address'}, - address2 => $borr->{'address2'}, - city => $borr->{'city'}, - zipcode => $borr->{'zipcode'}, - state => $borr->{'state'}, - country => $borr->{'country'}, - wborrowernumber => $reserve->{'borrowernumber'}, - wborcnum => $borr->{'cardnumber'}, - wtransfertFrom => $userenv_branch, + wtransfertFrom => $userenv_branch, ); } @@ -428,7 +434,7 @@ if ( $messages->{'WrongTransfer'} and not $messages->{'WasTransfered'}) { # if ( $messages->{'ResFound'}) { my $reserve = $messages->{'ResFound'}; - my $borr = C4::Members::GetMember( borrowernumber => $reserve->{'borrowernumber'} ); + my $patron = Koha::Patrons->find( $reserve->{borrowernumber} ); my $holdmsgpreferences = C4::Members::Messaging::GetMessagingPreferences( { borrowernumber => $reserve->{'borrowernumber'}, message_name => 'Hold_Filled' } ); if ( $reserve->{'ResFound'} eq "Waiting" or $reserve->{'ResFound'} eq "Reserved" ) { if ( $reserve->{'ResFound'} eq "Waiting" ) { @@ -446,25 +452,25 @@ if ( $messages->{'ResFound'}) { # same params for Waiting or Reserved $template->param( + # FIXME The full patron object should be passed to the template found => 1, - name => $borr->{'surname'} . ", " . $borr->{'title'} . " " . $borr->{'firstname'}, - borfirstname => $borr->{'firstname'}, - borsurname => $borr->{'surname'}, - borcategory => $borr->{'description'}, - bortitle => $borr->{'title'}, - borphone => $borr->{'phone'}, - boremail => $borr->{'email'}, - streetnumber => $borr->{streetnumber}, - streettype => $borr->{streettype}, - address => $borr->{'address'}, - address2 => $borr->{'address2'}, - city => $borr->{'city'}, - zipcode => $borr->{'zipcode'}, - state => $borr->{'state'}, - country => $borr->{'country'}, - borcnum => $borr->{'cardnumber'}, - debarred => $borr->{'debarred'}, - gonenoaddress => $borr->{'gonenoaddress'}, + name => $patron->surname . ", " . $patron->title . " " . $patron->firstname, + borfirstname => $patron->firstname, + borsurname => $patron->surname, + borcategory => $patron->category->description, + bortitle => $patron->title, + borphone => $patron->phone, + boremail => $patron->email, + boraddress => $patron->address, + boraddress2 => $patron->address2, + streetnumber => $patron->streetnumber, + city => $patron->city, + zipcode => $patron->zipcode, + state => $patron->state, + country => $patron->country, + borcnum => $patron->cardnumber, + debarred => $patron->debarred, + gonenoaddress => $patron->gonenoaddress, barcode => $barcode, destbranch => $reserve->{'branchcode'}, borrowernumber => $reserve->{'borrowernumber'}, @@ -572,19 +578,19 @@ foreach ( sort { $a <=> $b } keys %returneditems ) { $ri{hour} = $duedate->hour(); $ri{minute} = $duedate->minute(); $ri{duedate} = output_pref($duedate); - my $b = C4::Members::GetMember( borrowernumber => $riborrowernumber{$_} ); + my $patron = Koha::Patrons->find( $riborrowernumber{$_} ); unless ( $dropboxmode ) { $ri{return_overdue} = 1 if (DateTime->compare($duedate, DateTime->now()) == -1); } else { $ri{return_overdue} = 1 if (DateTime->compare($duedate, $dropboxdate) == -1); } - $ri{borrowernumber} = $b->{'borrowernumber'}; - $ri{borcnum} = $b->{'cardnumber'}; - $ri{borfirstname} = $b->{'firstname'}; - $ri{borsurname} = $b->{'surname'}; - $ri{bortitle} = $b->{'title'}; - $ri{bornote} = $b->{'borrowernotes'}; - $ri{borcategorycode}= $b->{'categorycode'}; + $ri{borrowernumber} = $patron->borrowernumber; + $ri{borcnum} = $patron->cardnumber; + $ri{borfirstname} = $patron->firstname; + $ri{borsurname} = $patron->surname; + $ri{bortitle} = $patron->title; + $ri{bornote} = $patron->borrowernotes; + $ri{borcategorycode}= $patron->categorycode; $ri{borissuescount} = Koha::Checkouts->count( { borrowernumber => $b->{'borrowernumber'} } ); } else { diff --git a/circ/transferstoreceive.pl b/circ/transferstoreceive.pl index 1ef3f0c3a5..88f9aa607a 100755 --- a/circ/transferstoreceive.pl +++ b/circ/transferstoreceive.pl @@ -40,6 +40,7 @@ use Koha::ItemTypes; use Koha::Libraries; use Koha::DateUtils; use Koha::BiblioFrameworks; +use Koha::Patrons; my $input = new CGI; my $itemnumber = $input->param('itemnumber'); @@ -114,12 +115,13 @@ while ( my $library = $libraries->next ) { # we check if we have a reserv for this transfer my $holds = $item->current_holds; if ( my $first_hold = $holds->next ) { - my $getborrower = C4::Members::GetMember( borrowernumber => $first_hold->borrowernumber ); - $getransf{'borrowernum'} = $getborrower->{'borrowernumber'}; - $getransf{'borrowername'} = $getborrower->{'surname'}; - $getransf{'borrowerfirstname'} = $getborrower->{'firstname'}; - $getransf{'borrowermail'} = $getborrower->{'email'} if $getborrower->{'email'}; - $getransf{'borrowerphone'} = $getborrower->{'phone'}; + my $patron = Koha::Patrons->find( $first_hold->borrowernumber ); + # FIXME The full patron object should be passed to the template + $getransf{'borrowernum'} = $patron->borrowernumber; + $getransf{'borrowername'} = $patron->surname; + $getransf{'borrowerfirstname'} = $patron->firstname; + $getransf{'borrowermail'} = $patron->email if $patron->email; + $getransf{'borrowerphone'} = $patron->phone; } push( @transferloop, \%getransf ); } diff --git a/circ/waitingreserves.pl b/circ/waitingreserves.pl index a3dfd29692..555d04ede8 100755 --- a/circ/waitingreserves.pl +++ b/circ/waitingreserves.pl @@ -39,6 +39,7 @@ use Koha::DateUtils; use Koha::BiblioFrameworks; use Koha::Items; use Koha::ItemTypes; +use Koha::Patrons; my $input = new CGI; @@ -104,7 +105,7 @@ foreach my $num (@getreserves) { borrowernum => $borrowernum, ); - my $getborrower = GetMember(borrowernumber => $num->{'borrowernumber'}); + my $patron = Koha::Patrons->find( $num->{borrowernumber} ); my $itemtype = Koha::ItemTypes->find( $item->effective_itemtype ); $getreserv{'waitingdate'} = $num->{'waitingdate'}; my ( $expire_year, $expire_month, $expire_day ) = split (/-/, $num->{'expirationdate'}); @@ -123,9 +124,9 @@ foreach my $num (@getreserves) { if ( $homebranch ne $holdingbranch ) { $getreserv{'dotransfer'} = 1; } - $getreserv{'borrowername'} = $getborrower->{'surname'}; - $getreserv{'borrowerfirstname'} = $getborrower->{'firstname'}; - $getreserv{'borrowerphone'} = $getborrower->{'phone'}; + $getreserv{'borrowername'} = $patron->surname; + $getreserv{'borrowerfirstname'} = $patron->firstname; + $getreserv{'borrowerphone'} = $patron->phone; my $borEmail = GetFirstValidEmailAddress( $borrowernum ); @@ -189,7 +190,7 @@ sub cancel { # if we have a result if ($nextreservinfo) { my %res; - my $borrowerinfo = C4::Members::GetMember( borrowernumber => $nextreservinfo ); + my $patron = Koha::Patrons->find( $nextreservinfo ); my $title = Koha::Items->find( $item )->biblio->title; if ( $messages->{'transfert'} ) { $res{messagetransfert} = $messages->{'transfert'}; @@ -198,8 +199,8 @@ sub cancel { $res{message} = 1; $res{nextreservnumber} = $nextreservinfo; - $res{nextreservsurname} = $borrowerinfo->{'surname'}; - $res{nextreservfirstname} = $borrowerinfo->{'firstname'}; + $res{nextreservsurname} = $patron->surname; + $res{nextreservfirstname} = $patron->firstname; $res{nextreservitem} = $item; $res{nextreservtitle} = $title; $res{waiting} = $messages->{'waiting'} ? 1 : 0; diff --git a/members/boraccount.pl b/members/boraccount.pl index 4f8ddf04b0..8abb373f2e 100755 --- a/members/boraccount.pl +++ b/members/boraccount.pl @@ -31,8 +31,7 @@ use CGI qw ( -utf8 ); use C4::Members; use C4::Accounts; use C4::Members::Attributes qw(GetBorrowerAttributes); -use Koha::Patron::Images; - +use Koha::Patrons; use Koha::Patron::Categories; my $input=new CGI; @@ -53,14 +52,14 @@ my ($template, $loggedinuser, $cookie) = get_template_and_user( my $borrowernumber=$input->param('borrowernumber'); my $action = $input->param('action') || ''; -#get borrower details -my $data=GetMember('borrowernumber' => $borrowernumber); +#get patron details +my $patron = Koha::Patrons->find( $borrowernumber ); if ( $action eq 'reverse' ) { ReversePayment( $input->param('accountlines_id') ); } -if ( $data->{'category_type'} eq 'C') { +if ( $patron->category->category_type eq 'C') { my $patron_categories = Koha::Patron::Categories->search_limited({ category_type => 'A' }, {order_by => ['categorycode']}); $template->param( 'CATCODE_MULTI' => 1) if $patron_categories->count > 1; $template->param( 'catcode' => $patron_categories->next ) if $patron_categories->count == 1; @@ -92,10 +91,9 @@ foreach my $accountline ( @{$accts}) { } } -$template->param( adultborrower => 1 ) if ( $data->{'category_type'} eq 'A' || $data->{'category_type'} eq 'I' ); +$template->param( adultborrower => 1 ) if ( $patron->category->category_type =~ /^(A|I)$/ ); -my $patron_image = Koha::Patron::Images->find($data->{borrowernumber}); -$template->param( picture => 1 ) if $patron_image; +$template->param( picture => 1 ) if $patron->image; if (C4::Context->preference('ExtendedPatronAttributes')) { my $attributes = GetBorrowerAttributes($borrowernumber); @@ -105,14 +103,14 @@ if (C4::Context->preference('ExtendedPatronAttributes')) { ); } -$template->param(%$data); +$template->param(%{ $patron->unblessed }); $template->param( finesview => 1, borrowernumber => $borrowernumber, total => sprintf("%.2f",$total), totalcredit => $totalcredit, - is_child => ($data->{'category_type'} eq 'C'), + is_child => ($patron->category->category_type eq 'C'), reverse_col => $reverse_col, accounts => $accts, RoutingSerials => C4::Context->preference('RoutingSerials'), diff --git a/members/deletemem.pl b/members/deletemem.pl index 00d21f02e2..5ea015ada7 100755 --- a/members/deletemem.pl +++ b/members/deletemem.pl @@ -31,7 +31,6 @@ use C4::Auth; use C4::Members; use Module::Load; use Koha::Patrons; -use Koha::Patron::Images; use Koha::Token; if ( C4::Context->preference('NorwegianPatronDBEnable') && C4::Context->preference('NorwegianPatronDBEnable') == 1 ) { @@ -75,13 +74,13 @@ if ( C4::Context->preference('NorwegianPatronDBEnable') && C4::Context->preferen my $issues = GetPendingIssues($member); # FIXME: wasteful call when really, we only want the count my $countissues = scalar(@$issues); -my $bor = C4::Members::GetMember( borrowernumber => $member ); -my $flags = C4::Members::patronflags( $bor ); +my $patron = Koha::Patrons->find( $member ); +my $flags = C4::Members::patronflags( $patron->unblessed ); my $userenv = C4::Context->userenv; -if ($bor->{category_type} eq "S") { +if ($patron->category->category_type eq "S") { unless(C4::Auth::haspermission($userenv->{'id'},{'staffaccess'=>1})) { print $input->redirect("/cgi-bin/koha/members/moremember.pl?borrowernumber=$member&error=CANT_DELETE_STAFF"); exit 0; # Exit without error @@ -95,8 +94,8 @@ if ($bor->{category_type} eq "S") { if (C4::Context->preference("IndependentBranches")) { my $userenv = C4::Context->userenv; - if ( !C4::Context->IsSuperLibrarian() && $bor->{'branchcode'}){ - unless ($userenv->{branch} eq $bor->{'branchcode'}){ + if ( !C4::Context->IsSuperLibrarian() && $patron->branchcode){ + unless ($userenv->{branch} eq $patron->branchcode){ print $input->redirect("/cgi-bin/koha/members/moremember.pl?borrowernumber=$member&error=CANT_DELETE_OTHERLIBRARY"); exit 0; # Exit without error } @@ -107,27 +106,28 @@ my $op = $input->param('op') || 'delete_confirm'; my $dbh = C4::Context->dbh; my $is_guarantor = $dbh->selectrow_array("SELECT COUNT(*) FROM borrowers WHERE guarantorid=?", undef, $member); if ( $op eq 'delete_confirm' or $countissues > 0 or $flags->{'CHARGES'} or $is_guarantor or $deletelocal == 0) { - my $patron_image = Koha::Patron::Images->find($bor->{borrowernumber}); - $template->param( picture => 1 ) if $patron_image; - - $template->param( adultborrower => 1 ) if ( $bor->{category_type} eq 'A' || $bor->{category_type} eq 'I' ); - - $template->param(borrowernumber => $member, - surname => $bor->{'surname'}, - title => $bor->{'title'}, - cardnumber => $bor->{'cardnumber'}, - firstname => $bor->{'firstname'}, - categorycode => $bor->{'categorycode'}, - category_type => $bor->{'category_type'}, - categoryname => $bor->{'description'}, - address => $bor->{'address'}, - address2 => $bor->{'address2'}, - city => $bor->{'city'}, - zipcode => $bor->{'zipcode'}, - country => $bor->{'country'}, - phone => $bor->{'phone'}, - email => $bor->{'email'}, - branchcode => $bor->{'branchcode'}, + $template->param( picture => 1 ) if $patron->image; + + $template->param( adultborrower => 1 ) if $patron->category->category_type =~ /^(A|I)$/; + + $template->param( + # FIXME The patron object should be passed to the template + borrowernumber => $patron->borrowernumber, + surname => $patron->surname, + title => $patron->title, + cardnumber => $patron->cardnumber, + firstname => $patron->firstname, + categorycode => $patron->categorycode, + category_type => $patron->category->category_type, + categoryname => $patron->category->description, + address => $patron->address, + address2 => $patron->address2, + city => $patron->city, + zipcode => $patron->zipcode, + country => $patron->country, + phone => $patron->phone, + email => $patron->email, + branchcode => $patron->branchcode, RoutingSerials => C4::Context->preference('RoutingSerials'), ); if ($countissues >0) { diff --git a/members/discharge.pl b/members/discharge.pl index 23b437847a..b24c41b1db 100755 --- a/members/discharge.pl +++ b/members/discharge.pl @@ -37,7 +37,6 @@ use C4::Members; use C4::Reserves; use C4::Letters; use Koha::Patron::Discharge; -use Koha::Patron::Images; use Koha::Patrons; use Koha::DateUtils; @@ -59,19 +58,16 @@ unless ( C4::Context->preference('useDischarge') ) { exit; } -my $data; if ( $input->param('borrowernumber') ) { $borrowernumber = $input->param('borrowernumber'); # Getting member data - $data = GetMember( borrowernumber => $borrowernumber ); + my $patron = Koha::Patrons->find( $borrowernumber ); my $can_be_discharged = Koha::Patron::Discharge::can_be_discharged({ borrowernumber => $borrowernumber }); - # Getting reserves - my $patron = Koha::Patrons->find( $borrowernumber ); my $holds = $patron->holds; my $has_reserves = $holds->count; @@ -87,7 +83,7 @@ if ( $input->param('borrowernumber') ) { } eval { my $pdf_path = Koha::Patron::Discharge::generate_as_pdf( - { borrowernumber => $borrowernumber, branchcode => $data->{'branchcode'} } ); + { borrowernumber => $borrowernumber, branchcode => $patron->branchcode } ); binmode(STDOUT); print $input->header( @@ -112,31 +108,30 @@ if ( $input->param('borrowernumber') ) { borrowernumber => $borrowernumber, }); - my $patron_image = Koha::Patron::Images->find($borrowernumber); - $template->param( picture => 1 ) if $patron_image; + $template->param( picture => 1 ) if $patron->image; $template->param( + # FIXME The patron object should be passed to the template borrowernumber => $borrowernumber, - biblionumber => $data->{'biblionumber'}, - title => $data->{'title'}, - initials => $data->{'initials'}, - surname => $data->{'surname'}, + title => $patron->title, + initials => $patron->initials, + surname => $patron->surname, borrowernumber => $borrowernumber, - firstname => $data->{'firstname'}, - cardnumber => $data->{'cardnumber'}, - categorycode => $data->{'categorycode'}, - category_type => $data->{'category_type'}, - categoryname => $data->{'description'}, - address => $data->{'address'}, - streetnumber => $data->{streetnumber}, - streettype => $data->{streettype}, - address2 => $data->{'address2'}, - city => $data->{'city'}, - zipcode => $data->{'zipcode'}, - country => $data->{'country'}, - phone => $data->{'phone'}, - email => $data->{'email'}, - branchcode => $data->{'branchcode'}, + firstname => $patron->firstname, + cardnumber => $patron->cardnumber, + categorycode => $patron->categorycode, + category_type => $patron->category->category_type, + categoryname => $patron->category->description, + address => $patron->address, + streetnumber => $patron->streetnumber, + streettype => $patron->streettype, + address2 => $patron->address2, + city => $patron->city, + zipcode => $patron->zipcode, + country => $patron->country, + phone => $patron->phone, + email => $patron->email, + branchcode => $patron->branchcode, has_reserves => $has_reserves, can_be_discharged => $can_be_discharged, validated_discharges => $validated_discharges, diff --git a/members/files.pl b/members/files.pl index 5002c3ea80..ddb99f7628 100755 --- a/members/files.pl +++ b/members/files.pl @@ -29,8 +29,8 @@ use C4::Members::Attributes qw(GetBorrowerAttributes); use C4::Debug; use Koha::DateUtils; +use Koha::Patrons; use Koha::Patron::Files; -use Koha::Patron::Images; my $cgi = CGI->new; @@ -63,8 +63,8 @@ if ( $op eq 'download' ) { print $file->{'file_content'}; } else { - my $data = GetMember( borrowernumber => $borrowernumber ); - $template->param(%$data); + my $patron = Koha::Patrons->find( $borrowernumber ); + $template->param(%{ $patron->unblessed}); my %errors; @@ -102,7 +102,7 @@ else { } $template->param( - categoryname => $data->{'description'}, + categoryname => $patron->category->description, RoutingSerials => C4::Context->preference('RoutingSerials'), ); @@ -114,8 +114,7 @@ else { ); } - my $patron_image = Koha::Patron::Images->find($data->{borrowernumber}); - $template->param( picture => 1 ) if $patron_image; + $template->param( picture => 1 ) if $patron->image; $template->param( adultborrower => 1 ) if ( $data->{category_type} eq 'A' || $data->{category_type} eq 'I' ); $template->param( diff --git a/members/housebound.pl b/members/housebound.pl index 0ffe685548..b334999b9e 100755 --- a/members/housebound.pl +++ b/members/housebound.pl @@ -66,7 +66,7 @@ push @messages, { type => 'error', code => 'error_on_patron_load' } # Get supporting cast my ( $branch, $category, $houseboundprofile, $visit, $patron_image ); if ( $patron ) { - $patron_image = Koha::Patron::Images->find($patron->borrowernumber); + $patron_image = $patron->image; $branch = Koha::Libraries->new->find($patron->branchcode); $category = Koha::Patron::Categories->new->find($patron->categorycode); $houseboundprofile = $patron->housebound_profile; diff --git a/members/mancredit.pl b/members/mancredit.pl index f8a3681f61..4855c24cde 100755 --- a/members/mancredit.pl +++ b/members/mancredit.pl @@ -33,7 +33,7 @@ use C4::Members; use C4::Accounts; use C4::Items; use C4::Members::Attributes qw(GetBorrowerAttributes); -use Koha::Patron::Images; +use Koha::Patrons; use Koha::Patron::Categories; @@ -42,8 +42,7 @@ my $flagsrequired = { borrowers => 1, updatecharges => 1 }; my $borrowernumber=$input->param('borrowernumber'); -#get borrower details -my $data=GetMember('borrowernumber' => $borrowernumber); +my $patron = Koha::Patrons->find( $borrowernumber ); my $add=$input->param('add'); if ($add){ @@ -74,15 +73,14 @@ if ($add){ } ); - if ( $data->{'category_type'} eq 'C') { + if ( $patron->category->category_type eq 'C') { my $patron_categories = Koha::Patron::Categories->search_limited({ category_type => 'A' }, {order_by => ['categorycode']}); $template->param( 'CATCODE_MULTI' => 1) if $patron_categories->count > 1; $template->param( 'catcode' => $patron_categories->next ) if $patron_categories->count == 1; } - $template->param( adultborrower => 1 ) if ( $data->{category_type} eq 'A' || $data->{category_type} eq 'I' ); - my $patron_image = Koha::Patron::Images->find($data->{borrowernumber}); - $template->param( picture => 1 ) if $patron_image; + $template->param( adultborrower => 1 ) if ( $patron->category->category_type =~ /^(A|I)$/ ); + $template->param( picture => 1 ) if $patron->image; if (C4::Context->preference('ExtendedPatronAttributes')) { my $attributes = GetBorrowerAttributes($borrowernumber); @@ -92,13 +90,13 @@ if ($add){ ); } - $template->param(%$data); + $template->param(%{ $patron->unblessed}); $template->param( finesview => 1, borrowernumber => $borrowernumber, - categoryname => $data->{'description'}, - is_child => ($data->{'category_type'} eq 'C'), + categoryname => $patron->category->description, + is_child => ($patron->category->category_type eq 'C'), # FIXME is_child should be a Koha::Patron method RoutingSerials => C4::Context->preference('RoutingSerials'), ); output_html_with_http_headers $input, $cookie, $template->output; diff --git a/members/maninvoice.pl b/members/maninvoice.pl index e69a1ca348..2c1c05f01f 100755 --- a/members/maninvoice.pl +++ b/members/maninvoice.pl @@ -32,7 +32,8 @@ use C4::Members; use C4::Accounts; use C4::Items; use C4::Members::Attributes qw(GetBorrowerAttributes); -use Koha::Patron::Images; + +use Koha::Patrons; use Koha::Patron::Categories; @@ -41,9 +42,7 @@ my $flagsrequired = { borrowers => 1 }; my $borrowernumber=$input->param('borrowernumber'); - -# get borrower details -my $data=GetMember('borrowernumber'=>$borrowernumber); +my $patron = Koha::Patrons->find( $borrowernumber ); my $add=$input->param('add'); if ($add){ if ( checkauth( $input, 0, $flagsrequired, 'intranet' ) ) { @@ -100,15 +99,14 @@ if ($add){ } $template->param( invoice_types_loop => \@invoice_types ); - if ( $data->{'category_type'} eq 'C') { + if ( $patron->category->category_type eq 'C') { my $patron_categories = Koha::Patron::Categories->search_limited({ category_type => 'A' }, {order_by => ['categorycode']}); $template->param( 'CATCODE_MULTI' => 1) if $patron_categories->count > 1; $template->param( 'catcode' => $patron_categories->next ) if $patron_categories->count == 1; } - $template->param( adultborrower => 1 ) if ( $data->{'category_type'} eq 'A' || $data->{'category_type'} eq 'I' ); - my $patron_image = Koha::Patron::Images->find($data->{borrowernumber}); - $template->param( picture => 1 ) if $patron_image; + $template->param( adultborrower => 1 ) if ( $patron->category->category_type =~ /^(A|I)$/ ); + $template->param( picture => 1 ) if $patron->image; if (C4::Context->preference('ExtendedPatronAttributes')) { my $attributes = GetBorrowerAttributes($borrowernumber); @@ -118,12 +116,12 @@ if ($add){ ); } - $template->param(%$data); + $template->param(%{ $patron->unblessed }); $template->param( finesview => 1, borrowernumber => $borrowernumber, - categoryname => $data->{'description'}, - is_child => ($data->{'category_type'} eq 'C'), + categoryname => $patron->category->description, + is_child => ($patron->category->category_type eq 'C'), RoutingSerials => C4::Context->preference('RoutingSerials'), ); output_html_with_http_headers $input, $cookie, $template->output; diff --git a/members/member-flags.pl b/members/member-flags.pl index 95f533017d..2b872624e4 100755 --- a/members/member-flags.pl +++ b/members/member-flags.pl @@ -16,6 +16,7 @@ use C4::Members::Attributes qw(GetBorrowerAttributes); #use C4::Acquisitions; use Koha::Patron::Categories; +use Koha::Patrons; use C4::Output; use Koha::Patron::Images; @@ -25,8 +26,10 @@ my $input = new CGI; my $flagsrequired = { permissions => 1 }; my $member=$input->param('member'); -my $bor = GetMember( borrowernumber => $member ); -if( $bor->{'category_type'} eq 'S' ) { +my $patron = Koha::Patrons->find( $member ); +my $category_type = $patron->category->category_type; +my $bor = $patron->unblessed; +if( $category_type eq 'S' ) { $flagsrequired->{'staffaccess'} = 1; } my ($template, $loggedinuser, $cookie) = get_template_and_user({ @@ -170,15 +173,14 @@ if ($input->param('newflags')) { push @loop, \%row; } - if ( $bor->{'category_type'} eq 'C') { + if ( $category_type eq 'C') { my $patron_categories = Koha::Patron::Categories->search_limited({ category_type => 'A' }, {order_by => ['categorycode']}); $template->param( 'CATCODE_MULTI' => 1) if $patron_categories->count > 1; $template->param( 'catcode' => $patron_categories->next ) if $patron_categories->count == 1; } -$template->param( adultborrower => 1 ) if ( $bor->{'category_type'} eq 'A' || $bor->{'category_type'} eq 'I' ); - my $patron_image = Koha::Patron::Images->find($bor->{borrowernumber}); - $template->param( picture => 1 ) if $patron_image; +$template->param( adultborrower => 1 ) if ( $category_type =~ /^(A|I)$/ ); + $template->param( picture => 1 ) if $patron->image; if (C4::Context->preference('ExtendedPatronAttributes')) { my $attributes = GetBorrowerAttributes($bor->{'borrowernumber'}); @@ -195,7 +197,7 @@ $template->param( firstname => $bor->{'firstname'}, othernames => $bor->{'othernames'}, categorycode => $bor->{'categorycode'}, - category_type => $bor->{'category_type'}, + category_type => $category_type, categoryname => $bor->{'description'}, address => $bor->{address}, address2 => $bor->{'address2'}, @@ -211,7 +213,7 @@ $template->param( emailpro => $bor->{'emailpro'}, branchcode => $bor->{'branchcode'}, loop => \@loop, - is_child => ($bor->{'category_type'} eq 'C'), + is_child => ($category_type eq 'C'), RoutingSerials => C4::Context->preference('RoutingSerials'), csrf_token => Koha::Token->new->generate_csrf( { session_id => scalar $input->cookie('CGISESSID'), } ), ); diff --git a/members/member-password.pl b/members/member-password.pl index 4fdf699427..4cf00bfde4 100755 --- a/members/member-password.pl +++ b/members/member-password.pl @@ -15,9 +15,9 @@ use C4::Members; use C4::Circulation; use CGI qw ( -utf8 ); use C4::Members::Attributes qw(GetBorrowerAttributes); -use Koha::Patron::Images; use Koha::Token; +use Koha::Patrons; use Koha::Patron::Categories; my $input = new CGI; @@ -48,9 +48,11 @@ my $newpassword2 = $input->param('newpassword2'); my @errors; -my ($bor) = GetMember( 'borrowernumber' => $member ); +my $patron = Koha::Patrons->find( $member ); +my $category_type = $patron->category->category_type; +my $bor = $patron->unblessed; -if ( ( $member ne $loggedinuser ) && ( $bor->{'category_type'} eq 'S' ) ) { +if ( ( $member ne $loggedinuser ) && ( $category_type eq 'S' ) ) { push( @errors, 'NOPERMISSION' ) unless ( $staffflags->{'superlibrarian'} || $staffflags->{'staffaccess'} ); @@ -99,16 +101,15 @@ else { $template->param( defaultnewpassword => $defaultnewpassword ); } -if ( $bor->{'category_type'} eq 'C') { +if ( $category_type eq 'C') { my $patron_categories = Koha::Patron::Categories->search_limited({ category_type => 'A' }, {order_by => ['categorycode']}); $template->param( 'CATCODE_MULTI' => 1) if $patron_categories->count > 1; $template->param( 'catcode' => $patron_categories->next ) if $patron_categories->count == 1; } -$template->param( adultborrower => 1 ) if ( $bor->{'category_type'} eq 'A' || $bor->{'category_type'} eq 'I' ); +$template->param( adultborrower => 1 ) if ( $category_type =~ /^(A|I)$/ ); -my $patron_image = Koha::Patron::Images->find($bor->{borrowernumber}); -$template->param( picture => 1 ) if $patron_image; +$template->param( picture => 1 ) if $patron->image; if ( C4::Context->preference('ExtendedPatronAttributes') ) { my $attributes = GetBorrowerAttributes( $bor->{'borrowernumber'} ); @@ -125,7 +126,7 @@ $template->param( borrowernumber => $bor->{'borrowernumber'}, cardnumber => $bor->{'cardnumber'}, categorycode => $bor->{'categorycode'}, - category_type => $bor->{'category_type'}, + category_type => $category_type, categoryname => $bor->{'description'}, address => $bor->{address}, address2 => $bor->{'address2'}, @@ -143,7 +144,7 @@ $template->param( branchcode => $bor->{'branchcode'}, userid => $bor->{'userid'}, destination => $destination, - is_child => ( $bor->{'category_type'} eq 'C' ), + is_child => ( $category_type eq 'C' ), minPasswordLength => $minpw, RoutingSerials => C4::Context->preference('RoutingSerials'), csrf_token => Koha::Token->new->generate_csrf({ session_id => scalar $input->cookie('CGISESSID'), }), diff --git a/members/member.pl b/members/member.pl index cf00f915ba..02ccbd13e7 100755 --- a/members/member.pl +++ b/members/member.pl @@ -27,9 +27,9 @@ use Modern::Perl; use C4::Auth; use C4::Output; use CGI qw( -utf8 ); -use C4::Members qw( GetMember ); use Koha::DateUtils; use Koha::List::Patron; +use Koha::Patrons; my $input = new CGI; @@ -52,12 +52,9 @@ if ( $quicksearch and $searchmember ) { my $userenv = C4::Context->userenv; $branchcode = $userenv->{'branch'}; } - my $member = GetMember( - cardnumber => $searchmember, - ( $branchcode ? ( branchcode => $branchcode ) : () ), - ); - if( $member ){ - print $input->redirect("/cgi-bin/koha/members/moremember.pl?borrowernumber=" . $member->{borrowernumber}); + my $patron = Koha::Patrons->find( { cardnumber => $searchmember } ); + if( ( $branchcode and $patron->branchcode eq $branchcode ) or ( not $branchcode and $patron ) ){ + print $input->redirect("/cgi-bin/koha/members/moremember.pl?borrowernumber=" . $patron->borrowernumber); exit; } } diff --git a/members/memberentry.pl b/members/memberentry.pl index 2ffea5de4c..050153442c 100755 --- a/members/memberentry.pl +++ b/members/memberentry.pl @@ -42,6 +42,7 @@ use Koha::Patron::Debarments; use Koha::Cities; use Koha::DateUtils; use Koha::Libraries; +use Koha::Patrons; use Koha::Patron::Categories; use Koha::Patron::HouseboundRole; use Koha::Patron::HouseboundRoles; @@ -152,7 +153,11 @@ $template->param( "add" => 1 ) if ( $op eq 'add' ); $template->param( "quickadd" => 1 ) if ( $quickadd ); $template->param( "duplicate" => 1 ) if ( $op eq 'duplicate' ); $template->param( "checked" => 1 ) if ( defined($nodouble) && $nodouble eq 1 ); -( $borrower_data = GetMember( 'borrowernumber' => $borrowernumber ) ) if ( $op eq 'modify' or $op eq 'save' or $op eq 'duplicate' ); +if ( $op eq 'modify' or $op eq 'save' or $op eq 'duplicate' ) { + my $patron = Koha::Patrons->find( $borrowernumber ); + $borrower_data = $patron->unblessed; + $borrower_data->{category_type} = $patron->category->category_type; +} my $categorycode = $input->param('categorycode') || $borrower_data->{'categorycode'}; my $category_type = $input->param('category_type') || ''; unless ($category_type or !($categorycode)){ @@ -242,7 +247,8 @@ if ( ( $op eq 'insert' ) and !$nodouble ) { #recover all data from guarantor address phone ,fax... if ( $guarantorid ) { - if (my $guarantordata=GetMember(borrowernumber => $guarantorid)) { + if (my $guarantor = Koha::Patrons->find( $guarantorid )) { + my $guarantordata = $guarantor->unblessed; $category_type = $guarantordata->{categorycode} eq 'I' ? 'P' : 'C'; $guarantorinfo=$guarantordata->{'surname'}." , ".$guarantordata->{'firstname'}; $newdata{'contactfirstname'}= $guarantordata->{'firstname'}; @@ -307,8 +313,8 @@ if ($op eq 'save' || $op eq 'insert'){ my $dateofbirth; if ($op eq 'save' && $step == 3) { - my $borrower = C4::Members::GetMember(borrowernumber => $borrowernumber); - $dateofbirth = $borrower->{dateofbirth}; + my $patron = Koha::Patrons->find( $borrowernumber ); + $dateofbirth = $patron->dateofbirth; } else { $dateofbirth = $newdata{dateofbirth}; diff --git a/members/moremember.pl b/members/moremember.pl index 0649dcfd76..320feee16f 100755 --- a/members/moremember.pl +++ b/members/moremember.pl @@ -120,6 +120,12 @@ my $error = $input->param('error'); $template->param( error => $error ) if ( $error ); my $patron = Koha::Patrons->find($borrowernumber); +unless ( $patron ) { + $template->param (unknowuser => 1); + output_html_with_http_headers $input, $cookie, $template->output; + exit; +} + my $issues = $patron->checkouts; my $balance = $patron->account->balance; $template->param( @@ -127,16 +133,8 @@ $template->param( fines => $balance, ); - -my $data = GetMember( 'borrowernumber' => $borrowernumber ); - -if ( not defined $data ) { - $template->param (unknowuser => 1); - output_html_with_http_headers $input, $cookie, $template->output; - exit; -} - -my $category_type = $data->{'category_type'}; +my $category_type = $patron->category->category_type; +my $data = $patron->unblessed; $debug and printf STDERR "dates (enrolled,expiry,birthdate) raw: (%s, %s, %s)\n", map {$data->{$_}} qw(dateenrolled dateexpiry dateofbirth); foreach (qw(dateenrolled dateexpiry dateofbirth)) { @@ -279,8 +277,7 @@ if ( C4::Context->preference('NorwegianPatronDBEnable') && C4::Context->preferen # check to see if patron's image exists in the database # basically this gives us a template var to condition the display of # patronimage related interface on -my $patron_image = Koha::Patron::Images->find($data->{borrowernumber}); -$template->param( picture => 1 ) if $patron_image; +$template->param( picture => 1 ) if $patron->image; # Generate CSRF token for upload and delete image buttons $template->param( csrf_token => Koha::Token->new->generate_csrf({ session_id => $input->cookie('CGISESSID'),}), diff --git a/members/notices.pl b/members/notices.pl index 58d4f6ead3..977c921e89 100755 --- a/members/notices.pl +++ b/members/notices.pl @@ -27,14 +27,14 @@ use CGI qw ( -utf8 ); use C4::Members; use C4::Letters; use C4::Members::Attributes qw(GetBorrowerAttributes); -use Koha::Patron::Images; +use Koha::Patrons; my $input=new CGI; my $borrowernumber = $input->param('borrowernumber'); -#get borrower details -my $borrower = GetMember(borrowernumber => $borrowernumber); +my $patron = Koha::Patrons->find( $borrowernumber ); +my $borrower = $patron->unblessed; my ($template, $loggedinuser, $cookie) = get_template_and_user({template_name => "members/notices.tt", @@ -46,8 +46,7 @@ my ($template, $loggedinuser, $cookie) }); $template->param( $borrower ); -my $patron_image = Koha::Patron::Images->find($borrower->{borrowernumber}); -$template->param( picture => 1 ) if $patron_image; +$template->param( picture => 1 ) if $patron->image; # Allow resending of messages in Notices tab my $op = $input->param('op') || q{}; @@ -78,7 +77,7 @@ $template->param( QUEUED_MESSAGES => $queued_messages, borrowernumber => $borrowernumber, sentnotices => 1, - categoryname => $borrower->{'description'}, + categoryname => $patron->category->description, RoutingSerials => C4::Context->preference('RoutingSerials'), ); output_html_with_http_headers $input, $cookie, $template->output; diff --git a/members/pay.pl b/members/pay.pl index 3400ee0667..e4d0a955d3 100755 --- a/members/pay.pl +++ b/members/pay.pl @@ -40,6 +40,7 @@ use C4::Stats; use C4::Koha; use C4::Overdues; use C4::Members::Attributes qw(GetBorrowerAttributes); +use Koha::Patrons; use Koha::Patron::Images; use Koha::Patron::Categories; @@ -66,7 +67,11 @@ if ( !$borrowernumber ) { } # get borrower details -our $borrower = GetMember( borrowernumber => $borrowernumber ); +my $patron = Koha::Patrons->find( $borrowernumber ); +my $category = $patron->category; +our $borrower = $patron->unblessed; +$borrower->{description} = $category->description; +$borrower->{category_type} = $category->category_type; our $user = $input->remote_user; $user ||= q{}; diff --git a/members/paycollect.pl b/members/paycollect.pl index 9784e88d35..3b8b9228a5 100755 --- a/members/paycollect.pl +++ b/members/paycollect.pl @@ -29,6 +29,7 @@ use C4::Members::Attributes qw(GetBorrowerAttributes); use C4::Accounts; use C4::Koha; use Koha::Patron::Images; +use Koha::Patrons; use Koha::Account; use Koha::Patron::Categories; @@ -48,7 +49,11 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( # get borrower details my $borrowernumber = $input->param('borrowernumber'); -my $borrower = GetMember( borrowernumber => $borrowernumber ); +my $patron = Koha::Patrons->find( $borrowernumber ); +my $borrower = $patron->unblessed; +my $category = $patron->category; +$borrower->{description} = $category->description; +$borrower->{category_type} = $category->category_type; my $user = $input->remote_user; my $branch = C4::Context->userenv->{'branch'}; diff --git a/members/printfeercpt.pl b/members/printfeercpt.pl index 4351aae1af..8863d1c373 100755 --- a/members/printfeercpt.pl +++ b/members/printfeercpt.pl @@ -31,7 +31,7 @@ use CGI qw ( -utf8 ); use C4::Members; use C4::Accounts; use Koha::DateUtils; -use Koha::Patron::Images; +use Koha::Patrons; use Koha::Patron::Categories; my $input=new CGI; @@ -50,8 +50,11 @@ my $borrowernumber=$input->param('borrowernumber'); my $action = $input->param('action') || ''; my $accountlines_id = $input->param('accountlines_id'); -#get borrower details -my $data=GetMember('borrowernumber' => $borrowernumber); +my $patron = Koha::Patrons->find( $borrowernumber ); +my $category = $patron->category; +my $data = $patron->unblessed; +$data->{description} = $category->description; +$data->{category_type} = $category->category_type; if ( $action eq 'print' ) { # ReversePayment( $borrowernumber, $input->param('accountno') ); @@ -114,8 +117,7 @@ for (my $i=0;$i<$numaccts;$i++){ $template->param( adultborrower => 1 ) if ( $data->{'category_type'} eq 'A' || $data->{'category_type'} eq 'I' ); -my $patron_image = Koha::Patron::Images->find($data->{borrowernumber}); -$template->param( picture => 1 ) if $patron_image; +$template->param( picture => 1 ) if $patron->image; $template->param( finesview => 1, diff --git a/members/printinvoice.pl b/members/printinvoice.pl index 77f315630d..ad823d5005 100755 --- a/members/printinvoice.pl +++ b/members/printinvoice.pl @@ -29,8 +29,8 @@ use Koha::DateUtils; use CGI qw ( -utf8 ); use C4::Members; use C4::Accounts; -use Koha::Patron::Images; +use Koha::Patrons; use Koha::Patron::Categories; my $input = new CGI; @@ -49,8 +49,11 @@ my $borrowernumber = $input->param('borrowernumber'); my $action = $input->param('action') || ''; my $accountlines_id = $input->param('accountlines_id'); -#get borrower details -my $data = GetMember( 'borrowernumber' => $borrowernumber ); +my $patron = Koha::Patrons->find( $borrowernumber ); +my $category = $patron->category; +my $data = $patron->unblessed; +$data->{description} = $category->description; +$data->{category_type} = $category->category_type; if ( $data->{'category_type'} eq 'C' ) { my $patron_categories = Koha::Patron::Categories->search_limited({ category_type => 'A' }, {order_by => ['categorycode']}); @@ -114,8 +117,7 @@ for ( my $i = 0 ; $i < $numaccts ; $i++ ) { $template->param( adultborrower => 1 ) if ( $data->{'category_type'} eq 'A' || $data->{'category_type'} eq 'I' ); -my $patron_image = Koha::Patron::Images->find($data->{borrowernumber}); -$template->param( picture => 1 ) if $patron_image; +$template->param( picture => 1 ) if $patron->image; $template->param( finesview => 1, diff --git a/members/purchase-suggestions.pl b/members/purchase-suggestions.pl index f967b10a1a..9e352590e1 100755 --- a/members/purchase-suggestions.pl +++ b/members/purchase-suggestions.pl @@ -26,7 +26,7 @@ use C4::Output; use C4::Members; use C4::Members::Attributes qw(GetBorrowerAttributes); use C4::Suggestions; -use Koha::Patron::Images; +use Koha::Patrons; my $input = new CGI; @@ -43,13 +43,17 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( my $borrowernumber = $input->param('borrowernumber'); # Set informations for the patron -my $borrower = GetMember( borrowernumber => $borrowernumber ); -foreach my $key ( keys %$borrower ) { - $template->param( $key => $borrower->{$key} ); +my $patron = Koha::Patrons->find( $borrowernumber ); +my $category = $patron->category; +my $data = $patron->unblessed; +$data->{description} = $category->description; +$data->{category_type} = $category->category_type; +foreach my $key ( keys %$data ) { + $template->param( $key => $data->{$key} ); } $template->param( suggestionsview => 1, - categoryname => $borrower->{'description'}, + categoryname => $data->{'description'}, RoutingSerials => C4::Context->preference('RoutingSerials'), ); @@ -61,8 +65,7 @@ if (C4::Context->preference('ExtendedPatronAttributes')) { ); } -my $patron_image = Koha::Patron::Images->find($borrowernumber); -$template->param( picture => 1 ) if $patron_image; +$template->param( picture => 1 ) if $patron->image; my $suggestions = SearchSuggestion( { suggestedby => $borrowernumber } ); diff --git a/members/readingrec.pl b/members/readingrec.pl index 9daf48c314..b0b563c816 100755 --- a/members/readingrec.pl +++ b/members/readingrec.pl @@ -31,8 +31,8 @@ use C4::Members; use List::MoreUtils qw/any uniq/; use Koha::DateUtils; use C4::Members::Attributes qw(GetBorrowerAttributes); -use Koha::Patron::Images; +use Koha::Patrons; use Koha::Patron::Categories; my $input = CGI->new; @@ -51,14 +51,17 @@ my ($template, $loggedinuser, $cookie)= get_template_and_user({template_name => }); my $op = $input->param('op') || ''; +my $patron; if ($input->param('cardnumber')) { $cardnumber = $input->param('cardnumber'); - $data = GetMember(cardnumber => $cardnumber); + $patron = Koha::Patrons->find( { cardnumber => $cardnumber } ); + $data = $patron->unblessed; $borrowernumber = $data->{'borrowernumber'}; # we must define this as it is used to retrieve other data about the patron } if ($input->param('borrowernumber')) { $borrowernumber = $input->param('borrowernumber'); - $data = GetMember(borrowernumber => $borrowernumber); + $patron = Koha::Patrons->find( $borrowernumber ); + $data = $patron->unblessed; } my $order = 'date_due desc'; @@ -79,8 +82,7 @@ if ( $op eq 'export_barcodes' ) { my $today = output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1 }); my @barcodes = map { $_->{barcode} } grep { $_->{returndate} =~ m/^$today/o } @{$issues}; - my $borrowercardnumber = - GetMember( borrowernumber => $borrowernumber )->{'cardnumber'}; + my $borrowercardnumber = $data->{cardnumber}; my $delimiter = "\n"; binmode( STDOUT, ":encoding(UTF-8)" ); print $input->header( @@ -106,8 +108,7 @@ if (! $limit){ $limit = 'full'; } -my $patron_image = Koha::Patron::Images->find($data->{borrowernumber}); -$template->param( picture => 1 ) if $patron_image; +$template->param( picture => 1 ) if $patron->image; if (C4::Context->preference('ExtendedPatronAttributes')) { my $attributes = GetBorrowerAttributes($borrowernumber); diff --git a/members/routing-lists.pl b/members/routing-lists.pl index c3e6c8d965..2f3c4aca60 100755 --- a/members/routing-lists.pl +++ b/members/routing-lists.pl @@ -26,7 +26,7 @@ use C4::Members; use C4::Members::Attributes qw(GetBorrowerAttributes); use C4::Context; use C4::Serials; -use Koha::Patron::Images; +use Koha::Patrons; use CGI::Session; my $query = new CGI; @@ -49,18 +49,14 @@ my $borrowernumber = $query->param('borrowernumber'); my $branch = C4::Context->userenv->{'branch'}; # get the borrower information..... -my $borrower; +my ( $patron, $patron_info ); if ($borrowernumber) { - $borrower = GetMember( borrowernumber => $borrowernumber ); -} - + $patron = Koha::Patrons->find( $borrowernumber ); + my $category = $patron->category; + my $patron_info = $patron->unblessed; + $patron_info->{description} = $category->description; + $patron_info->{category_type} = $category->category_type; -################################################################################## -# BUILD HTML -# I'm trying to show the title of subscriptions where the borrowernumber is attached via a routing list - -if ($borrowernumber) { -# new op dev my $count; my @borrowerSubscriptions; ($count, @borrowerSubscriptions) = GetSubscriptionsFromBorrower($borrowernumber ); @@ -80,19 +76,19 @@ if ($borrowernumber) { routinglistview => 1 ); - $template->param( adultborrower => 1 ) if ( $borrower->{'category_type'} eq 'A' || $borrower->{'category_type'} eq 'I' ); + $template->param( adultborrower => 1 ) if ( $patron_info->{category_type} =~ /^(A|I)$/ ); } ################################################################################## -$template->param(%$borrower); +$template->param(%$patron_info); $template->param( findborrower => $findborrower, - borrower => $borrower, + borrower => $patron_info, borrowernumber => $borrowernumber, branch => $branch, - categoryname => $borrower->{description}, + categoryname => $patron_info->{description}, RoutingSerials => C4::Context->preference('RoutingSerials'), ); @@ -104,7 +100,6 @@ if (C4::Context->preference('ExtendedPatronAttributes')) { ); } -my $patron_image = Koha::Patron::Images->find($borrower->{borrowernumber}); -$template->param( picture => 1 ) if $patron_image; +$template->param( picture => 1 ) if $patron and $patron->image; output_html_with_http_headers $query, $cookie, $template->output; diff --git a/members/statistics.pl b/members/statistics.pl index a63d3285b3..5979e7f1dd 100755 --- a/members/statistics.pl +++ b/members/statistics.pl @@ -31,7 +31,7 @@ use C4::Members; use C4::Members::Statistics; use C4::Members::Attributes qw(GetBorrowerAttributes); use C4::Output; -use Koha::Patron::Images; +use Koha::Patrons; my $input = new CGI; @@ -48,13 +48,18 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( my $borrowernumber = $input->param('borrowernumber'); # Set informations for the patron -my $borrower = GetMember( borrowernumber => $borrowernumber ); -if ( not defined $borrower ) { +my $patron = Koha::Patrons->find( $borrowernumber ); +unless ( $patron ) { $template->param (unknowuser => 1); output_html_with_http_headers $input, $cookie, $template->output; exit; } +my $category = $patron->category; +my $borrower= $patron->unblessed; +$borrower->{description} = $category->description; +$borrower->{category_type} = $category->category_type; + foreach my $key ( keys %$borrower ) { $template->param( $key => $borrower->{$key} ); } @@ -92,8 +97,7 @@ if (C4::Context->preference('ExtendedPatronAttributes')) { ); } -my $patron_image = Koha::Patron::Images->find($borrower->{borrowernumber}); -$template->param( picture => 1 ) if $patron_image; +$template->param( picture => 1 ) if $patron->image; $template->param(%$borrower); diff --git a/members/summary-print.pl b/members/summary-print.pl index a3d438c65e..546e93121b 100755 --- a/members/summary-print.pl +++ b/members/summary-print.pl @@ -27,6 +27,7 @@ use C4::Reserves; use C4::Items; use Koha::Holds; use Koha::ItemTypes; +use Koha::Patrons; my $input = CGI->new; my $borrowernumber = $input->param('borrowernumber'); @@ -42,7 +43,11 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( } ); -my $data = GetMember( 'borrowernumber' => $borrowernumber ); +my $patron = Koha::Patrons->find( $borrowernumber ); +my $category = $patron->category; +my $data = $patron->unblessed; +$data->{description} = $category->description; +$data->{category_type} = $category->category_type; my ( $total, $accts, $numaccts ) = GetMemberAccountRecords($borrowernumber); foreach my $accountline (@$accts) { diff --git a/members/update-child.pl b/members/update-child.pl index 5d50d931b4..bedf9b5fb3 100755 --- a/members/update-child.pl +++ b/members/update-child.pl @@ -33,6 +33,7 @@ use C4::Context; use C4::Auth; use C4::Output; use C4::Members; +use Koha::Patrons; use Koha::Patron::Categories; # use Smart::Comments; @@ -71,7 +72,8 @@ if ( $op eq 'multi' ) { } elsif ( $op eq 'update' ) { - my $member = GetMember('borrowernumber'=>$borrowernumber); + my $patron = Koha::Patrons->find( $borrowernumber ); + my $member = $patron->unblessed; $member->{'guarantorid'} = 0; $member->{'categorycode'} = $catcode; my $borcat = Koha::Patron::Categories->find($catcode); diff --git a/misc/cronjobs/advance_notices.pl b/misc/cronjobs/advance_notices.pl index c367446b32..0475ee0dfb 100755 --- a/misc/cronjobs/advance_notices.pl +++ b/misc/cronjobs/advance_notices.pl @@ -511,9 +511,8 @@ sub get_branch_info { my ( $borrowernumber ) = @_; ## Get branch info for borrowers home library. - my $borrower_details = C4::Members::GetMember( borrowernumber => $borrowernumber ); - my $borrower_branchcode = $borrower_details->{'branchcode'}; - my $branch = Koha::Libraries->find( $borrower_branchcode )->unblessed; + my $patron = Koha::Patrons->find( $borrowernumber ); + my $branch = $patron->library->unblessed; my %branch_info; foreach my $key( keys %$branch ) { $branch_info{"branches.$key"} = $branch->{$key}; diff --git a/misc/cronjobs/notice_unprocessed_suggestions.pl b/misc/cronjobs/notice_unprocessed_suggestions.pl index a0c42ed662..f8f2e8fb51 100755 --- a/misc/cronjobs/notice_unprocessed_suggestions.pl +++ b/misc/cronjobs/notice_unprocessed_suggestions.pl @@ -6,9 +6,9 @@ use Pod::Usage; use Getopt::Long; use C4::Budgets qw( GetBudget ); -use C4::Members qw( GetMember ); use C4::Suggestions qw( GetUnprocessedSuggestions ); use Koha::Libraries; +use Koha::Patrons; my ( $help, $verbose, $confirm, @days ); GetOptions( @@ -45,38 +45,38 @@ for my $number_of_days (@days) { say "Suggestion $suggestion->{suggestionid} should be processed" if $verbose; my $budget = C4::Budgets::GetBudget( $suggestion->{budgetid} ); - my $patron = C4::Members::GetMember( borrowernumber => $budget->{budget_owner_id} ); + my $patron = Koha::Patrons->find( $budget->{budget_owner_id} ); my $email_address = C4::Members::GetNoticeEmailAddress( $budget->{budget_owner_id} ); - my $library = Koha::Libraries->find( $patron->{branchcode} ); + my $library = $patron->library; my $admin_email_address = $library->branchemail || C4::Context->preference('KohaAdminEmailAddress'); if ($email_address) { - say "Patron $patron->{borrowernumber} is going to be notified" if $verbose; + say "Patron " . $patron->borrowernumber . " is going to be notified" if $verbose; my $letter = C4::Letters::GetPreparedLetter( module => 'suggestions', letter_code => 'TO_PROCESS', - branchcode => $patron->{branchcode}, - lang => $patron->{lang}, + branchcode => $patron->branchcode, + lang => $patron->lang, tables => { suggestions => $suggestion->{suggestionid}, - branches => $patron->{branchcode}, - borrowers => $patron->{borrowernumber}, + branches => $patron->branchcode, + borrowers => $patron->borrowernumber, }, ); if ( $confirm ) { C4::Letters::EnqueueLetter( { letter => $letter, - borrowernumber => $patron->{borrowernumber}, + borrowernumber => $patron->borrowernumber, message_transport_type => 'email', from_address => $admin_email_address, } ); } } else { - say "Patron $patron->{borrowernumber} does not have an email address" if $verbose; + say "Patron " . $patron->borrowernumber . " does not have an email address" if $verbose; } } diff --git a/misc/export_borrowers.pl b/misc/export_borrowers.pl index 5a2b92023f..5f5c7f74ed 100755 --- a/misc/export_borrowers.pl +++ b/misc/export_borrowers.pl @@ -24,7 +24,7 @@ use Text::CSV; use Getopt::Long qw(:config no_ignore_case); use C4::Context; -use C4::Members; +use Koha::Patrons; binmode STDOUT, ":encoding(UTF-8)"; @@ -41,7 +41,7 @@ $0 [--field=FIELD [--field=FIELD [...]]] [--separator=CHAR] [--show-header] [--w $0 -h -f, --field=FIELD Field to export. It is repeatable and has to match - keys returned by the GetMember function. + column names of the borrower table (also as 'description' and 'category_type' If no field is specified, then all fields will be exported. -s, --separator=CHAR This character will be used to separate fields. @@ -99,8 +99,13 @@ my $csv = Text::CSV->new( { sep_char => $separator, binary => 1 } ); # If the user did not specify any field to export, we assume they want them all # We retrieve the first borrower informations to get field names my ($borrowernumber) = $sth->fetchrow_array or die "No borrower to export"; -my $member = GetMember($borrowernumber); # FIXME Now is_expired is no longer available +my $patron = Koha::Patrons->find( $borrowernumber ); # FIXME Now is_expired is no longer available # We will have to use Koha::Patron and allow method calls +my $category = $patron->category; +my $member = $patron->unblessed; +$member->{description} = $category->description; +$member->{category_type} = $category->category_type; + @fields = keys %$member unless (@fields); if ($show_header) { @@ -121,7 +126,11 @@ die "Invalid character at borrower $borrowernumber: [" print $csv->string . "\n"; while ( my $borrowernumber = $sth->fetchrow_array ) { - $member = GetMember( borrowernumber => $borrowernumber ); + my $patron = Koha::Patrons->find( $borrowernumber ); + my $category = $patron->category; + my $member = $patron->unblessed; + $member->{description} = $category->description; + $member->{category_type} = $category->category_type; $csv->combine( map { ( defined $member->{$_} and !ref $member->{$_} ) diff --git a/misc/load_testing/benchmark_staff.pl b/misc/load_testing/benchmark_staff.pl index 56085c82b7..f060464435 100644 --- a/misc/load_testing/benchmark_staff.pl +++ b/misc/load_testing/benchmark_staff.pl @@ -18,8 +18,8 @@ use Data::Dumper; use HTTP::Cookies; use C4::Context; use C4::Debug; -use C4::Members qw ( GetMember ); use URI::Escape; +use Koha::Patrons; my ($help, $steps, $baseurl, $max_tries, $user, $password,$short_print); GetOptions( @@ -91,7 +91,7 @@ if( $resp->is_success and $resp->content =~ m|ok| ) { } die "You cannot use the database administrator account to launch this script" - unless defined C4::Members::GetMember(userid => $user); + unless defined Koha::Patrons->find( { userid => $user } ); # remove some unnecessary garbage from the cookie $cookie =~ s/ path_spec; discard; version=0//; diff --git a/offline_circ/list.pl b/offline_circ/list.pl index fb550494b4..5981f35e24 100755 --- a/offline_circ/list.pl +++ b/offline_circ/list.pl @@ -29,6 +29,7 @@ use C4::Context; use C4::Circulation; use C4::Members; use C4::Biblio; +use Koha::Patrons; use Koha::Items; @@ -49,10 +50,10 @@ for (@$operations) { my $biblio = $item->biblio; $_->{'bibliotitle'} = $biblio->title; $_->{'biblionumber'} = $biblio->biblionumber; - my $borrower = C4::Members::GetMember( cardnumber => $_->{'cardnumber'} ); - if ($borrower) { - $_->{'borrowernumber'} = $borrower->{'borrowernumber'}; - $_->{'borrower'} = ($borrower->{'firstname'}?$borrower->{'firstname'}:'').' '.$borrower->{'surname'}; + my $patron = $_->{cardnumber} ? Koha::Patrons->find( { cardnumber => $_->{cardnumber} } ) : undef; + if ($patron) { + $_->{'borrowernumber'} = $patron->borrowernumber; + $_->{'borrower'} = ($patron->firstname ? $patron->firstname:'').' '.$patron->surname; } $_->{'actionissue'} = $_->{'action'} eq 'issue'; $_->{'actionreturn'} = $_->{'action'} eq 'return'; diff --git a/offline_circ/process_koc.pl b/offline_circ/process_koc.pl index fa092ffcfa..d2d8553d29 100755 --- a/offline_circ/process_koc.pl +++ b/offline_circ/process_koc.pl @@ -249,7 +249,8 @@ sub kocIssueItem { $circ->{ 'barcode' } = barcodedecode($circ->{'barcode'}) if( $circ->{'barcode'} && C4::Context->preference('itemBarcodeInputFilter')); my $branchcode = C4::Context->userenv->{branch}; - my $borrower = GetMember( 'cardnumber'=>$circ->{ 'cardnumber' } ); + my $patron = Koha::Patrons->find( { cardnumber => $circ->{cardnumber} } ); + my $borrower = $patron->unblessed; my $item = Koha::Items->find({ barcode => $circ->{barcode} }); my $issue = Koha::Checkouts->find( { itemnumber => $item->itemnumber } ); my $biblio = $item->biblio; @@ -331,29 +332,30 @@ sub kocReturnItem { my $biblio = $item->biblio; my $borrowernumber = _get_borrowernumber_from_barcode( $circ->{'barcode'} ); if ( $borrowernumber ) { - my $borrower = GetMember( 'borrowernumber' => $borrowernumber ); + my $patron = Koha::Patrons->find( $borrowernumber ); C4::Circulation::MarkIssueReturned( $borrowernumber, $item->itemnumber, undef, $circ->{'date'}, - $borrower->{'privacy'} + $patron->privacy ); ModItem({ onloan => undef }, $biblio->biblionumber, $item->itemnumber); ModDateLastSeen( $item->itemnumber ); - push @output, { - return => 1, - title => $biblio->title, - biblionumber => $biblio->biblionumber, - barcode => $item->barcode, - borrowernumber => $borrower->{'borrowernumber'}, - firstname => $borrower->{'firstname'}, - surname => $borrower->{'surname'}, - cardnumber => $borrower->{'cardnumber'}, - datetime => $circ->{ 'datetime' } - }; + push @output, + { + return => 1, + title => $biblio->title, + biblionumber => $biblio->biblionumber, + barcode => $item->barcode, + borrowernumber => $patron->borrowernumber, + firstname => $patron->firstname, + surname => $patron->surname, + cardnumber => $patron->cardnumber, + datetime => $circ->{'datetime'} + }; } else { push @output, { ERROR_no_borrower_from_item => 1, diff --git a/opac/opac-ISBDdetail.pl b/opac/opac-ISBDdetail.pl index 6cb502c614..175d3465ce 100755 --- a/opac/opac-ISBDdetail.pl +++ b/opac/opac-ISBDdetail.pl @@ -52,8 +52,8 @@ use C4::Reserves; use C4::Acquisition; use C4::Serials; # uses getsubscriptionfrom biblionumber use C4::Koha; -use C4::Members; # GetMember use Koha::ItemTypes; +use Koha::Patrons; use Koha::RecordProcessor; @@ -164,7 +164,7 @@ my $res = GetISBDView({ }); my $itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search_with_localization->unblessed } }; -my $borrower = GetMember( 'borrowernumber' => $loggedinuser ); +my $patron = Koha::Patrons->find( $loggedinuser ); for my $itm (@items) { $norequests = 0 if $norequests @@ -174,7 +174,7 @@ for my $itm (@items) { && !$itemtypes->{$itm->{'itype'}}->{notforloan} && $itm->{'itemnumber'}; - $allow_onshelf_holds = C4::Reserves::OnShelfHoldsAllowed($itm, $borrower) + $allow_onshelf_holds = C4::Reserves::OnShelfHoldsAllowed($itm, $patron->unblessed) unless $allow_onshelf_holds; } diff --git a/opac/opac-MARCdetail.pl b/opac/opac-MARCdetail.pl index 3c9c2c23c8..d758af2891 100755 --- a/opac/opac-MARCdetail.pl +++ b/opac/opac-MARCdetail.pl @@ -57,6 +57,7 @@ use C4::Members; use C4::Acquisition; use C4::Koha; use List::MoreUtils qw( any uniq ); +use Koha::Patrons; use Koha::RecordProcessor; my $query = new CGI; @@ -126,9 +127,9 @@ if(my $cart_list = $query->cookie("bib_list")){ } my $allow_onshelf_holds; -my $borrower = GetMember( 'borrowernumber' => $loggedinuser ); +my $patron = Koha::Patrons->find( $loggedinuser )->unblessed; for my $itm (@all_items) { - $allow_onshelf_holds = C4::Reserves::OnShelfHoldsAllowed($itm, $borrower); + $allow_onshelf_holds = C4::Reserves::OnShelfHoldsAllowed($itm, $patron); last if $allow_onshelf_holds; } diff --git a/opac/opac-account-pay-paypal-return.pl b/opac/opac-account-pay-paypal-return.pl index eb870cc226..64292d480d 100755 --- a/opac/opac-account-pay-paypal-return.pl +++ b/opac/opac-account-pay-paypal-return.pl @@ -29,9 +29,9 @@ use URI; use C4::Auth; use C4::Output; use C4::Accounts; -use C4::Members; use Koha::Acquisition::Currencies; use Koha::Database; +use Koha::Patrons; my $cgi = new CGI; @@ -117,8 +117,9 @@ else { $error = "PAYPAL_UNABLE_TO_CONNECT"; } +my $patron = Koha::Patrons->find( $borrowernumber ); $template->param( - borrower => GetMember( borrowernumber => $borrowernumber ), + borrower => $patron->unblessed, accountview => 1 ); diff --git a/opac/opac-account.pl b/opac/opac-account.pl index e02e5f398e..9888f88556 100755 --- a/opac/opac-account.pl +++ b/opac/opac-account.pl @@ -19,12 +19,12 @@ # along with Koha; if not, see . -use strict; +use Modern::Perl; use CGI qw ( -utf8 ); use C4::Members; use C4::Auth; use C4::Output; -use warnings; +use Koha::Patrons; my $query = new CGI; my ( $template, $borrowernumber, $cookie ) = get_template_and_user( @@ -37,7 +37,11 @@ my ( $template, $borrowernumber, $cookie ) = get_template_and_user( } ); -my $borrower = C4::Members::GetMember( borrowernumber => $borrowernumber ); +my $patron = Koha::Patrons->find( $borrowernumber ); +my $category = $patron->category; +my $borrower= $patron->unblessed; +$borrower->{description} = $category->description; +$borrower->{category_type} = $category->category_type; $template->param( BORROWER_INFO => $borrower ); #get account details diff --git a/opac/opac-detail.pl b/opac/opac-detail.pl index f2c2f6fe6a..a56ed6a96b 100755 --- a/opac/opac-detail.pl +++ b/opac/opac-detail.pl @@ -53,6 +53,7 @@ use Koha::AuthorisedValues; use Koha::Biblios; use Koha::ItemTypes; use Koha::Virtualshelves; +use Koha::Patrons; use Koha::Ratings; use Koha::Reviews; @@ -655,7 +656,7 @@ if ( not $viewallitems and @items > $max_items_to_display ) { ); } else { my $allow_onshelf_holds; - my $borrower = GetMember( 'borrowernumber' => $borrowernumber ); + my $patron = Koha::Patrons->find( $borrowernumber ); for my $itm (@items) { $itm->{holds_count} = $item_reserves{ $itm->{itemnumber} }; $itm->{priority} = $priority{ $itm->{itemnumber} }; @@ -667,7 +668,7 @@ if ( not $viewallitems and @items > $max_items_to_display ) { && !$itemtypes->{$itm->{'itype'}}->{notforloan} && $itm->{'itemnumber'}; - $allow_onshelf_holds = C4::Reserves::OnShelfHoldsAllowed( $itm, $borrower ) + $allow_onshelf_holds = C4::Reserves::OnShelfHoldsAllowed( $itm, $patron->unblessed ) unless $allow_onshelf_holds; # get collection code description, too @@ -839,19 +840,19 @@ if ( C4::Context->preference('reviewson') ) { } } for my $review (@$reviews) { - my $borrowerData = GetMember( 'borrowernumber' => $review->{borrowernumber} ); + my $patron = Koha::Patrons->find( $review->{borrowernumber} ); # setting some borrower info into this hash - $review->{title} = $borrowerData->{'title'}; - $review->{surname} = $borrowerData->{'surname'}; - $review->{firstname} = $borrowerData->{'firstname'}; - if ( $libravatar_enabled and $borrowerData->{'email'} ) { - $review->{avatarurl} = libravatar_url( email => $borrowerData->{'email'}, https => $ENV{HTTPS} ); + $review->{title} = $patron->title; + $review->{surname} = $patron->surname; + $review->{firstname} = $patron->firstname; + if ( $libravatar_enabled and $patron->email ) { + $review->{avatarurl} = libravatar_url( email => $patron->email, https => $ENV{HTTPS} ); } - $review->{userid} = $borrowerData->{'userid'}; - $review->{cardnumber} = $borrowerData->{'cardnumber'}; + $review->{userid} = $patron->userid; + $review->{cardnumber} = $patron->cardnumber; - if ( $borrowerData->{'borrowernumber'} eq $borrowernumber ) { + if ( $patron->borrowernumber eq $borrowernumber ) { $review->{your_comment} = 1; $loggedincommenter = 1; } diff --git a/opac/opac-discharge.pl b/opac/opac-discharge.pl index e5fc49b27e..4ce1322c5f 100755 --- a/opac/opac-discharge.pl +++ b/opac/opac-discharge.pl @@ -26,7 +26,7 @@ use C4::Context; use C4::Output; use C4::Log; use C4::Debug; -use C4::Members; +use Koha::Patrons; use Koha::Patron::Discharge; use Koha::DateUtils; @@ -63,10 +63,10 @@ elsif ( $op eq 'get' ) { eval { # Getting member data - my $data = GetMember( borrowernumber => $loggedinuser ); + my $patron = Koha::Patrons->find( $loggedinuser ); my $pdf_path = Koha::Patron::Discharge::generate_as_pdf({ borrowernumber => $loggedinuser, - branchcode => $data->{'branchcode'}, + branchcode => $patron->branchcode, }); binmode(STDOUT); diff --git a/opac/opac-memberentry.pl b/opac/opac-memberentry.pl index 1e4034c6c9..957c38d539 100755 --- a/opac/opac-memberentry.pl +++ b/opac/opac-memberentry.pl @@ -208,8 +208,8 @@ if ( $action eq 'create' ) { C4::Form::MessagingPreferences::handle_form_action($cgi, { borrowernumber => $borrowernumber }, $template, 1, C4::Context->preference('PatronSelfRegistrationDefaultCategory') ) if $borrowernumber && C4::Context->preference('EnhancedMessagingPreferences'); $template->param( password_cleartext => $password ); - $template->param( - borrower => GetMember( borrowernumber => $borrowernumber ) ); + my $patron = Koha::Patrons->find( $borrowernumber ); + $template->param( borrower => $patron->unblessed ); $template->param( PatronSelfRegistrationAdditionalInstructions => C4::Context->preference( @@ -220,7 +220,7 @@ if ( $action eq 'create' ) { } elsif ( $action eq 'update' ) { - my $borrower = GetMember( borrowernumber => $borrowernumber ); + my $borrower = Koha::Patrons->find( $borrowernumber )->unblessed; die "Wrong CSRF token" unless Koha::Token->new->check_csrf({ session_id => scalar $cgi->cookie('CGISESSID'), @@ -277,15 +277,15 @@ elsif ( $action eq 'update' ) { my $m = Koha::Patron::Modification->new( \%borrower_changes )->store(); - $template->param( - borrower => GetMember( borrowernumber => $borrowernumber ), - ); + my $patron = Koha::Patrons->find( $borrowernumber ); + $template->param( borrower => $patron->unblessed ); } else { + my $patron = Koha::Patrons->find( $borrowernumber ); $template->param( action => 'edit', nochanges => 1, - borrower => GetMember( borrowernumber => $borrowernumber ), + borrower => $patron->unblessed, patron_attribute_classes => GeneratePatronAttributesForm( $borrowernumber, $attributes ), csrf_token => Koha::Token->new->generate_csrf({ session_id => scalar $cgi->cookie('CGISESSID'), @@ -295,7 +295,8 @@ elsif ( $action eq 'update' ) { } } elsif ( $action eq 'edit' ) { #Display logged in borrower's data - my $borrower = GetMember( borrowernumber => $borrowernumber ); + my $patron = Koha::Patrons->find( $borrowernumber ); + my $borrower = $patron->unblessed; $template->param( borrower => $borrower, @@ -307,8 +308,7 @@ elsif ( $action eq 'edit' ) { #Display logged in borrower's data ); if (C4::Context->preference('OPACpatronimages')) { - my $patron_image = Koha::Patron::Images->find($borrower->{borrowernumber}); - $template->param( display_patron_image => 1 ) if $patron_image; + $template->param( display_patron_image => 1 ) if $patron->image; } $template->param( patron_attribute_classes => GeneratePatronAttributesForm( $borrowernumber ) ); @@ -450,7 +450,8 @@ sub ParseCgiForBorrower { sub DelUnchangedFields { my ( $borrowernumber, %new_data ) = @_; - my $current_data = GetMember( borrowernumber => $borrowernumber ); + my $patron = Koha::Patrons->find( $borrowernumber ); + my $current_data = $patron->unblessed; foreach my $key ( keys %new_data ) { if ( $current_data->{$key} eq $new_data{$key} ) { diff --git a/opac/opac-messaging.pl b/opac/opac-messaging.pl index 47b09e53f9..906d56fe4e 100755 --- a/opac/opac-messaging.pl +++ b/opac/opac-messaging.pl @@ -50,7 +50,7 @@ my ( $template, $borrowernumber, $cookie ) = get_template_and_user( } ); -my $borrower = C4::Members::GetMember( borrowernumber => $borrowernumber ); +my $borrower = Koha::Patrons->find( $borrowernumber )->unblessed; my $messaging_options = C4::Members::Messaging::GetMessagingOptions(); if ( defined $query->param('modify') && $query->param('modify') eq 'yes' ) { @@ -63,7 +63,8 @@ if ( defined $query->param('modify') && $query->param('modify') eq 'yes' ) { smsalertnumber => $sms, sms_provider_id => $sms_provider_id, ); - $borrower = C4::Members::GetMember( borrowernumber => $borrowernumber ); + # FIXME will not be needed when ModMember will be replaced + $borrower = Koha::Patrons->find( $borrowernumber )->unblessed; } C4::Form::MessagingPreferences::handle_form_action($query, { borrowernumber => $borrowernumber }, $template); diff --git a/opac/opac-passwd.pl b/opac/opac-passwd.pl index 4b33413f3e..db63cd3ae5 100755 --- a/opac/opac-passwd.pl +++ b/opac/opac-passwd.pl @@ -30,6 +30,7 @@ use C4::Circulation; use C4::Members; use C4::Output; use Koha::AuthUtils qw(hash_password); +use Koha::Patrons; my $query = new CGI; my $dbh = C4::Context->dbh; @@ -44,7 +45,7 @@ my ( $template, $borrowernumber, $cookie ) = get_template_and_user( } ); -my $borr = C4::Members::GetMember( borrowernumber => $borrowernumber ); +my $patron = Koha::Patrons->find( $borrowernumber ); my $minpasslen = C4::Context->preference("minPasswordLength"); if ( C4::Context->preference("OpacPasswordChange") ) { my $sth = $dbh->prepare("UPDATE borrowers SET password = ? WHERE borrowernumber=?"); @@ -103,8 +104,8 @@ if ( C4::Context->preference("OpacPasswordChange") ) { } } } -$template->param(firstname => $borr->{'firstname'}, - surname => $borr->{'surname'}, +$template->param(firstname => $patron->firstname, + surname => $patron->surname, minpasslen => $minpasslen, passwdview => 1, ); diff --git a/opac/opac-readingrecord.pl b/opac/opac-readingrecord.pl index 940bd91c3a..879a31ea61 100755 --- a/opac/opac-readingrecord.pl +++ b/opac/opac-readingrecord.pl @@ -31,6 +31,7 @@ use MARC::Record; use C4::Output; use C4::Charset qw(StripNonXmlChars); +use Koha::Patrons; use Koha::ItemTypes; @@ -52,8 +53,7 @@ my ( $template, $borrowernumber, $cookie ) = get_template_and_user( } ); -# get borrower information .... -my ( $borr ) = GetMember( borrowernumber => $borrowernumber ); +my $borr = Koha::Patrons->find( $borrowernumber )->unblessed; $template->param(%{$borr}); diff --git a/opac/opac-registration-verify.pl b/opac/opac-registration-verify.pl index 1098af079f..9d49c04ab1 100755 --- a/opac/opac-registration-verify.pl +++ b/opac/opac-registration-verify.pl @@ -23,6 +23,7 @@ use C4::Auth; use C4::Output; use C4::Members; use C4::Form::MessagingPreferences; +use Koha::Patrons; use Koha::Patron::Modifications; my $cgi = new CGI; @@ -60,8 +61,8 @@ if ( $m ) { C4::Form::MessagingPreferences::handle_form_action($cgi, { borrowernumber => $borrowernumber }, $template, 1, C4::Context->preference('PatronSelfRegistrationDefaultCategory') ) if C4::Context->preference('EnhancedMessagingPreferences'); $template->param( password_cleartext => $password ); - $template->param( - borrower => GetMember( borrowernumber => $borrowernumber ) ); + my $patron = Koha::Patrons->find( $borrowernumber ); + $template->param( borrower => $patron->unblessed ); $template->param( PatronSelfRegistrationAdditionalInstructions => C4::Context->preference( diff --git a/opac/opac-renew.pl b/opac/opac-renew.pl index 03c4a714a4..ad9cacfa72 100755 --- a/opac/opac-renew.pl +++ b/opac/opac-renew.pl @@ -70,8 +70,7 @@ else { $branchcode = $item->{'homebranch'}; } elsif ( $renewalbranch eq 'patronhomebranch' ) { - my $borrower = GetMember( borrowernumber => $borrowernumber ); - $branchcode = $borrower->{'branchcode'}; + $branchcode = Koha::Patrons->find( $borrowernumber )->branchcode; } elsif ( $renewalbranch eq 'checkoutbranch' ) { my $issue = GetOpenIssue($itemnumber); diff --git a/opac/opac-reserve.pl b/opac/opac-reserve.pl index 3e2cf7b14b..bf50f366a3 100755 --- a/opac/opac-reserve.pl +++ b/opac/opac-reserve.pl @@ -73,15 +73,14 @@ sub get_out { exit; } -# get borrower information .... -my ( $borr ) = GetMember( borrowernumber => $borrowernumber ); my $patron = Koha::Patrons->find( $borrowernumber ); my $can_place_hold_if_available_at_pickup = C4::Context->preference('OPACHoldsIfAvailableAtPickup'); unless ( $can_place_hold_if_available_at_pickup ) { my @patron_categories = split '\|', C4::Context->preference('OPACHoldsIfAvailableAtPickupExceptions'); if ( @patron_categories ) { - $can_place_hold_if_available_at_pickup = grep /$borr->{categorycode}/, @patron_categories; + my $categorycode = $patron->categorycode; + $can_place_hold_if_available_at_pickup = grep /^$categorycode$/, @patron_categories; } } @@ -135,7 +134,7 @@ if (($#biblionumbers < 0) && (! $query->param('place_reserve'))) { # pass the pickup branch along.... -my $branch = $query->param('branch') || $borr->{'branchcode'} || C4::Context->userenv->{branch} || '' ; +my $branch = $query->param('branch') || $patron->branchcode || C4::Context->userenv->{branch} || '' ; $template->param( branch => $branch ); # Is the person allowed to choose their branch @@ -240,7 +239,7 @@ if ( $query->param('place_reserve') ) { my $singleBranchMode = Koha::Libraries->search->count == 1; if ( $singleBranchMode || !$OPACChooseBranch ) { # single branch mode or disabled user choosing - $branch = $borr->{'branchcode'}; + $branch = $patron->branchcode; } #item may belong to a host biblio, if yes change biblioNum to hosts bilbionumber @@ -336,7 +335,7 @@ if ( $amountoutstanding && ($amountoutstanding > $maxoutstanding) ) { $template->param( too_much_oweing => $amount ); } -if ( $borr->{gonenoaddress} && ($borr->{gonenoaddress} == 1) ) { +if ( $patron->gonenoaddress && ($patron->gonenoaddress == 1) ) { $noreserves = 1; $template->param( message => 1, @@ -344,7 +343,7 @@ if ( $borr->{gonenoaddress} && ($borr->{gonenoaddress} == 1) ) { ); } -if ( $borr->{lost} && ($borr->{lost} == 1) ) { +if ( $patron->lost && ($patron->lost == 1) ) { $noreserves = 1; $template->param( message => 1, @@ -357,8 +356,8 @@ if ( $patron->is_debarred ) { $template->param( message => 1, debarred => 1, - debarred_comment => $borr->{debarredcomment}, - debarred_date => $borr->{debarred}, + debarred_comment => $patron->debarredcomment, + debarred_date => $patron->debarred, ); } @@ -478,12 +477,12 @@ foreach my $biblioNum (@biblionumbers) { my $holds = $item->current_holds; if ( my $first_hold = $holds->next ) { - my $ItemBorrowerReserveInfo = GetMember( borrowernumber => $first_hold->borrowernumber ); + my $patron = Koha::Patrons->find( $first_hold->borrowernumber ); $itemLoopIter->{backgroundcolor} = 'reserved'; $itemLoopIter->{reservedate} = output_pref({ dt => dt_from_string($first_hold->reservedate), dateonly => 1 }); # FIXME Should be formatted in the template $itemLoopIter->{ReservedForBorrowernumber} = $first_hold->borrowernumber; - $itemLoopIter->{ReservedForSurname} = $ItemBorrowerReserveInfo->{'surname'}; - $itemLoopIter->{ReservedForFirstname} = $ItemBorrowerReserveInfo->{'firstname'}; + $itemLoopIter->{ReservedForSurname} = $patron->surname; + $itemLoopIter->{ReservedForFirstname} = $patron->firstname; $itemLoopIter->{ExpectedAtLibrary} = $first_hold->branchcode; $itemLoopIter->{waitingdate} = $first_hold->waitingdate; } @@ -529,15 +528,16 @@ foreach my $biblioNum (@biblionumbers) { # If there is no loan, return and transfer, we show a checkbox. $itemLoopIter->{notforloan} = $itemLoopIter->{notforloan} || 0; - my $branch = GetReservesControlBranch( $itemInfo, $borr ); + my $patron_unblessed = $patron->unblessed; + my $branch = GetReservesControlBranch( $itemInfo, $patron_unblessed ); my $policy_holdallowed = !$itemLoopIter->{already_reserved}; $policy_holdallowed &&= - IsAvailableForItemLevelRequest($itemInfo,$borr) && + IsAvailableForItemLevelRequest($itemInfo,$patron_unblessed) && CanItemBeReserved($borrowernumber,$itemNum) eq 'OK'; if ($policy_holdallowed) { - if ( my $hold_allowed = OPACItemHoldsAllowed( $itemInfo, $borr ) ) { + if ( my $hold_allowed = OPACItemHoldsAllowed( $itemInfo, $patron_unblessed ) ) { $itemLoopIter->{available} = 1; $numCopiesOPACAvailable++; $biblioLoopIter{force_hold} = 1 if $hold_allowed eq 'F'; diff --git a/opac/opac-sendbasket.pl b/opac/opac-sendbasket.pl index 063dd8bf06..b7167e8667 100755 --- a/opac/opac-sendbasket.pl +++ b/opac/opac-sendbasket.pl @@ -33,6 +33,7 @@ use C4::Output; use C4::Members; use C4::Templates (); use Koha::Email; +use Koha::Patrons; use Koha::Token; my $query = new CGI; @@ -57,11 +58,11 @@ if ( $email_add ) { token => scalar $query->param('csrf_token'), }); my $email = Koha::Email->new(); - my $user = GetMember(borrowernumber => $borrowernumber); + my $patron = Koha::Patrons->find( $borrowernumber ); my $user_email = GetFirstValidEmailAddress($borrowernumber) || C4::Context->preference('KohaAdminEmailAddress'); - my $email_replyto = "$user->{firstname} $user->{surname} <$user_email>"; + my $email_replyto = $patron->firstname . " " . $patron->surname . " <$user_email>"; my $comment = $query->param('comment'); # if you want to use the KohaAdmin address as from, that is the default no need to set it @@ -114,8 +115,8 @@ if ( $email_add ) { $template2->param( BIBLIO_RESULTS => $resultsarray, comment => $comment, - firstname => $user->{firstname}, - surname => $user->{surname}, + firstname => $patron->firstname, + surname => $patron->surname, ); # Getting template result diff --git a/opac/opac-sendshelf.pl b/opac/opac-sendshelf.pl index 242caca7d0..e58ce7c6b3 100755 --- a/opac/opac-sendshelf.pl +++ b/opac/opac-sendshelf.pl @@ -33,6 +33,7 @@ use C4::Items; use C4::Output; use C4::Members; use Koha::Email; +use Koha::Patrons; use Koha::Virtualshelves; my $query = new CGI; @@ -109,14 +110,14 @@ if ( $email ) { push( @results, $dat ); } - my $user = GetMember(borrowernumber => $borrowernumber); + my $patron = Koha::Patrons->find( $borrowernumber ); $template2->param( BIBLIO_RESULTS => \@results, comment => $comment, shelfname => $shelf->shelfname, - firstname => $user->{firstname}, - surname => $user->{surname}, + firstname => $patron->firstname, + surname => $patron->surname, ); # Getting template result diff --git a/opac/opac-shelves.pl b/opac/opac-shelves.pl index 39aa93cad6..e790b43710 100755 --- a/opac/opac-shelves.pl +++ b/opac/opac-shelves.pl @@ -32,6 +32,7 @@ use C4::XSLT; use Koha::Biblioitems; use Koha::Items; use Koha::ItemTypes; +use Koha::Patrons; use Koha::Virtualshelves; use Koha::RecordProcessor; @@ -68,7 +69,7 @@ if ( $op eq 'add_form' ) { if ( $shelf ) { $category = $shelf->category; - my $patron = GetMember( 'borrowernumber' => $shelf->owner ); + my $patron = Koha::Patrons->find( $shelf->owner ); $template->param( owner => $patron, ); unless ( $shelf->can_be_managed( $loggedinuser ) ) { push @messages, { type => 'error', code => 'unauthorized_on_update' }; @@ -257,7 +258,7 @@ if ( $op eq 'view' ) { @cart_list = split(/\//, $cart_list); } - my $borrower = GetMember( borrowernumber => $loggedinuser ); + my $patron = Koha::Patrons->find( $loggedinuser ); # Lists display falls back to search results configuration my $xslfile = C4::Context->preference('OPACXSLTListsDisplay'); @@ -314,7 +315,7 @@ if ( $op eq 'view' ) { }); } - $this_item->{allow_onshelf_holds} = C4::Reserves::OnShelfHoldsAllowed($this_item, $borrower); + $this_item->{allow_onshelf_holds} = C4::Reserves::OnShelfHoldsAllowed($this_item, $patron); if ( grep {$_ eq $biblionumber} @cart_list) { diff --git a/opac/opac-showreviews.pl b/opac/opac-showreviews.pl index f85a833c56..99a7ed1c5d 100755 --- a/opac/opac-showreviews.pl +++ b/opac/opac-showreviews.pl @@ -27,8 +27,8 @@ use C4::Koha; use C4::Output; use C4::Circulation; use C4::Biblio; -use C4::Members qw/GetMember/; use Koha::DateUtils; +use Koha::Patrons; use Koha::Reviews; use POSIX qw(ceil floor strftime); @@ -92,7 +92,7 @@ for my $result (@$reviews){ my $bib = &GetBiblioData($biblionumber); my $record = GetMarcBiblio($biblionumber); my $frameworkcode = GetFrameworkCode($biblionumber); - my ( $borr ) = GetMember( borrowernumber => $result->{borrowernumber} ); + my $borr = Koha::Patrons->find( $result->{borrowernumber} )->unblessed; $result->{normalized_upc} = GetNormalizedUPC($record,$marcflavour); $result->{normalized_ean} = GetNormalizedEAN($record,$marcflavour); $result->{normalized_oclc} = GetNormalizedOCLCNumber($record,$marcflavour); diff --git a/opac/opac-suggestions.pl b/opac/opac-suggestions.pl index d300769b2c..e086b14ffb 100755 --- a/opac/opac-suggestions.pl +++ b/opac/opac-suggestions.pl @@ -30,6 +30,7 @@ use C4::Scrubber; use Koha::AuthorisedValues; use Koha::Libraries; +use Koha::Patrons; use Koha::DateUtils qw( dt_from_string ); @@ -195,14 +196,17 @@ my $patron_reason_loop = GetAuthorisedValues("OPAC_SUG"); # Is the person allowed to choose their branch if ( C4::Context->preference("AllowPurchaseSuggestionBranchChoice") ) { - my ( $borr ) = GetMember( borrowernumber => $borrowernumber ); # pass the pickup branch along.... my $userbranch = ''; if (C4::Context->userenv && C4::Context->userenv->{'branch'}) { $userbranch = C4::Context->userenv->{'branch'}; } - my $branchcode = $input->param('branchcode') || $borr->{'branchcode'} || $userbranch || '' ; + my $branchcode = $input->param('branchcode'); + unless ( $branchcode ) { + my $patron = Koha::Patrons->find( $borrowernumber ); + $branchcode = $patron->branchcode || $userbranch || '' ; + } $template->param( branchcode => $branchcode ); } diff --git a/opac/opac-user.pl b/opac/opac-user.pl index 395b148bac..e7c3a06c34 100755 --- a/opac/opac-user.pl +++ b/opac/opac-user.pl @@ -88,7 +88,7 @@ if (!$borrowernumber) { } # get borrower information .... -my ( $borr ) = GetMember( borrowernumber => $borrowernumber ); +my $borr = Koha::Patrons->find( $borrowernumber )->unblessed; my ( $today_year, $today_month, $today_day) = Today(); my ($warning_year, $warning_month, $warning_day) = split /-/, $borr->{'dateexpiry'}; diff --git a/opac/sco/sco-main.pl b/opac/sco/sco-main.pl index 4153277fdb..80ac47da28 100755 --- a/opac/sco/sco-main.pl +++ b/opac/sco/sco-main.pl @@ -45,6 +45,7 @@ use C4::Biblio; use C4::Items; use Koha::DateUtils qw( dt_from_string ); use Koha::Acquisition::Currencies; +use Koha::Patrons; use Koha::Patron::Images; use Koha::Patron::Messages; use Koha::Token; @@ -106,15 +107,14 @@ my ($op, $patronid, $patronlogin, $patronpw, $barcode, $confirmed) = ( ); my $issuenoconfirm = 1; #don't need to confirm on issue. -#warn "issuerid: " . $issuerid; -my $issuer = GetMember( borrowernumber => $issuerid ); +my $issuer = Koha::Patrons->find( $issuerid )->unblessed; my $item = GetItem(undef,$barcode); if (C4::Context->preference('SelfCheckoutByLogin') && !$patronid) { my $dbh = C4::Context->dbh; my $resval; ($resval, $patronid) = checkpw($dbh, $patronlogin, $patronpw); } -my $borrower = GetMember( cardnumber => $patronid ); +my $borrower = Koha::Patrons->find( { cardnumber => $patronid } )->unblessed; my $currencySymbol = ""; if ( my $active_currency = Koha::Acquisition::Currencies->get_active ) { @@ -132,7 +132,7 @@ if ($op eq "logout") { elsif ( $op eq "returnbook" && $allowselfcheckreturns ) { my ($doreturn) = AddReturn( $barcode, $branch ); #warn "returnbook: " . $doreturn; - $borrower = GetMember( cardnumber => $patronid ); + $borrower = Koha::Patrons->find( { cardnumber => $patronid } )->unblessed; } elsif ( $op eq "checkout" ) { my $impossible = {}; diff --git a/patroncards/create-pdf.pl b/patroncards/create-pdf.pl index 05cfcbd9d7..6c19ce24ea 100755 --- a/patroncards/create-pdf.pl +++ b/patroncards/create-pdf.pl @@ -29,10 +29,10 @@ use autouse 'Data::Dumper' => qw(Dumper); use C4::Debug; use C4::Context; -use autouse 'C4::Members' => qw(GetMember); use C4::Creators; use C4::Patroncards; use Koha::List::Patron; +use Koha::Patrons; use Koha::Patron::Images; my $cgi = new CGI; @@ -135,7 +135,7 @@ foreach my $item (@{$items}) { $cardscount ++; my $borrower_number = $item->{'borrower_number'}; - my $card_number = GetMember(borrowernumber => $borrower_number)->{'cardnumber'}; + my $card_number = Koha::Patrons->find( $borrower_number)->cardnumber; # Set barcode data $print_layout_xml->{'barcode'}->[0]->{'data'} = $card_number if $print_layout_xml->{'barcode'}; diff --git a/patroncards/edit-batch.pl b/patroncards/edit-batch.pl index cd1f774b5d..56410079ae 100755 --- a/patroncards/edit-batch.pl +++ b/patroncards/edit-batch.pl @@ -29,7 +29,8 @@ use C4::Auth qw(get_template_and_user); use C4::Output qw(output_html_with_http_headers); use C4::Creators; use C4::Patroncards; -use C4::Members qw(GetMember); +use Koha::Patrons; + my $cgi = new CGI; my ( $template, $loggedinuser, $cookie ) = get_template_and_user( { @@ -84,7 +85,7 @@ if ($bor_num_list) { my @bor_nums_unchecked = split /\n/, $bor_num_list; # $bor_num_list is effectively passed in as a separated list foreach my $number (@bor_nums_unchecked) { $number =~ s/\r$//; # strip any naughty return chars - if ( GetMember(borrowernumber => $number)) { # we must test in case an invalid borrowernumber is passed in; we effectively disgard them atm + if ( Koha::Patrons->find( $number )) { # we must test in case an invalid borrowernumber is passed in; we effectively disgard them atm my $borrower_number = $number; push @borrower_numbers, $borrower_number; } diff --git a/reserve/placerequest.pl b/reserve/placerequest.pl index 92f3c48b01..403321c818 100755 --- a/reserve/placerequest.pl +++ b/reserve/placerequest.pl @@ -32,6 +32,7 @@ use C4::Reserves; use C4::Circulation; use C4::Members; use C4::Auth qw/checkauth/; +use Koha::Patrons; my $input = CGI->new(); @@ -51,7 +52,8 @@ my $checkitem = $input->param('checkitem'); my $expirationdate = $input->param('expiration_date'); my $itemtype = $input->param('itemtype') || undef; -my $borrower = GetMember( 'borrowernumber' => $borrowernumber ); +my $borrower = Koha::Patrons->find( $borrowernumber ); +$borrower = $borrower->unblessed if $borrower; my $multi_hold = $input->param('multi_hold'); my $biblionumbers = $multi_hold ? $input->param('biblionumbers') : ($biblionumber . '/'); @@ -128,7 +130,7 @@ if ( $type eq 'str8' && $borrower ) { print $input->redirect("request.pl?biblionumber=$biblionumber"); } } -elsif ( $borrower eq '' ) { +elsif ( $borrowernumber eq '' ) { print $input->header(); print "Invalid borrower number please try again"; diff --git a/reserve/request.pl b/reserve/request.pl index 791a2bdb48..b0c3329487 100755 --- a/reserve/request.pl +++ b/reserve/request.pl @@ -100,9 +100,9 @@ if ( $action eq 'move' ) { } if ($findborrower) { - my $borrower = C4::Members::GetMember( cardnumber => $findborrower ); - if ( $borrower ) { - $borrowernumber_hold = $borrower->{borrowernumber}; + my $patron = Koha::Patrons->find( { cardnumber => $findborrower } ); + if ( $patron ) { + $borrowernumber_hold = $patron->borrowernumber; } else { my $dt_params = { iDisplayLength => -1 }; my $results = C4::Utils::DataTables::Members::search( @@ -134,14 +134,14 @@ if ($multihold) { # If we have the borrowernumber because we've performed an action, then we # don't want to try to place another reserve. if ($borrowernumber_hold && !$action) { - my $borrowerinfo = GetMember( borrowernumber => $borrowernumber_hold ); + my $patron = Koha::Patrons->find( $borrowernumber_hold ); my $diffbranch; # we check the reserves of the user, and if they can reserve a document # FIXME At this time we have a simple count of reservs, but, later, we could improve the infos "title" ... my $reserves_count = - GetReserveCount( $borrowerinfo->{'borrowernumber'} ); + GetReserveCount( $patron->borrowernumber ); my $new_reserves_count = scalar( @biblionumbers ); @@ -164,7 +164,7 @@ if ($borrowernumber_hold && !$action) { } # we check the date expiry of the borrower (only if there is an expiry date, otherwise, set to 1 (warn) - my $expiry_date = $borrowerinfo->{dateexpiry}; + my $expiry_date = $patron->dateexpiry; my $expiry = 0; # flag set if patron account has expired if ($expiry_date and $expiry_date ne '0000-00-00' and Date_to_Days(split /-/,$date) > Date_to_Days(split /-/,$expiry_date)) { @@ -172,38 +172,37 @@ if ($borrowernumber_hold && !$action) { } # check if the borrower make the reserv in a different branch - if ( $borrowerinfo->{'branchcode'} ne C4::Context->userenv->{'branch'} ) { + if ( $patron->branchcode ne C4::Context->userenv->{'branch'} ) { $diffbranch = 1; } - my $is_debarred = Koha::Patrons->find( $borrowerinfo->{borrowernumber} )->is_debarred; + my $is_debarred = $patron->is_debarred; $template->param( - borrowernumber => $borrowerinfo->{'borrowernumber'}, - borrowersurname => $borrowerinfo->{'surname'}, - borrowerfirstname => $borrowerinfo->{'firstname'}, - borrowerstreetaddress => $borrowerinfo->{'address'}, - borrowercity => $borrowerinfo->{'city'}, - borrowerphone => $borrowerinfo->{'phone'}, - borrowermobile => $borrowerinfo->{'mobile'}, - borrowerfax => $borrowerinfo->{'fax'}, - borrowerphonepro => $borrowerinfo->{'phonepro'}, - borroweremail => $borrowerinfo->{'email'}, - borroweremailpro => $borrowerinfo->{'emailpro'}, - borrowercategory => $borrowerinfo->{'category'}, - cardnumber => $borrowerinfo->{'cardnumber'}, + borrowernumber => $patron->borrowernumber, + borrowersurname => $patron->surname, + borrowerfirstname => $patron->firstname, + borrowerstreetaddress => $patron->address, + borrowercity => $patron->city, + borrowerphone => $patron->phone, + borrowermobile => $patron->mobile, + borrowerfax => $patron->fax, + borrowerphonepro => $patron->phonepro, + borroweremail => $patron->email, + borroweremailpro => $patron->emailpro, + cardnumber => $patron->cardnumber, expiry => $expiry, diffbranch => $diffbranch, messages => $messages, warnings => $warnings, restricted => $is_debarred, - amount_outstanding => GetMemberAccountRecords($borrowerinfo->{borrowernumber}), + amount_outstanding => GetMemberAccountRecords($patron->borrowernumber), ); } $template->param( messageborrower => $messageborrower ); -# FIXME launch another time GetMember perhaps until -my $borrowerinfo = GetMember( borrowernumber => $borrowernumber_hold ); +# FIXME launch another time GetMember perhaps until (Joubu: Why?) +my $patron = Koha::Patrons->find( $borrowernumber_hold ); my $logged_in_patron = Koha::Patrons->find( $borrowernumber ); @@ -216,7 +215,7 @@ foreach my $biblionumber (@biblionumbers) { my $dat = GetBiblioData($biblionumber); - my $canReserve = CanBookBeReserved( $borrowerinfo->{borrowernumber}, $biblionumber ); + my $canReserve = CanBookBeReserved( $patron->borrowernumber, $biblionumber ); $canReserve //= ''; if ( $canReserve eq 'OK' ) { @@ -238,7 +237,7 @@ foreach my $biblionumber (@biblionumbers) { } my $force_hold_level; - if ( $borrowerinfo->{borrowernumber} ) { + if ( $patron->borrowernumber ) { # For multiple holds per record, if a patron has previously placed a hold, # the patron can only place more holds of the same type. That is, if the # patron placed a record level hold, all the holds the patron places must @@ -246,7 +245,7 @@ foreach my $biblionumber (@biblionumbers) { # the patron places must be item level my $holds = Koha::Holds->search( { - borrowernumber => $borrowerinfo->{borrowernumber}, + borrowernumber => $patron->borrowernumber, biblionumber => $biblionumber, found => undef, } @@ -257,7 +256,7 @@ foreach my $biblionumber (@biblionumbers) { # For a librarian to be able to place multiple record holds for a patron for a record, # we must find out what the maximum number of holds they can place for the patron is - my $max_holds_for_record = GetMaxPatronHoldsForRecord( $borrowerinfo->{borrowernumber}, $biblionumber ); + my $max_holds_for_record = GetMaxPatronHoldsForRecord( $patron->borrowernumber, $biblionumber ); my $remaining_holds_for_record = $max_holds_for_record - $holds->count(); $biblioloopiter{remaining_holds_for_record} = $max_holds_for_record; $template->param( max_holds_for_record => $max_holds_for_record ); @@ -268,7 +267,7 @@ foreach my $biblionumber (@biblionumbers) { # patron already has an item from that record checked out my $alreadypossession; if ( !C4::Context->preference('AllowHoldsOnPatronsPossessions') - && CheckIfIssuedToPatron( $borrowerinfo->{borrowernumber}, $biblionumber ) ) + && CheckIfIssuedToPatron( $patron->borrowernumber, $biblionumber ) ) { $template->param( alreadypossession => $alreadypossession, ); } @@ -393,13 +392,13 @@ foreach my $biblionumber (@biblionumbers) { # checking reserve my $holds = Koha::Items->find( $itemnumber )->current_holds; if ( my $first_hold = $holds->next ) { - my $ItemBorrowerReserveInfo = GetMember( borrowernumber => $first_hold->borrowernumber ); + my $patron = Koha::Patrons->find( $first_hold->borrowernumber ); $item->{backgroundcolor} = 'reserved'; $item->{reservedate} = output_pref({ dt => dt_from_string( $first_hold->reservedate ), dateonly => 1 }); # FIXME Should be formatted in the template $item->{ReservedForBorrowernumber} = $first_hold->borrowernumber; - $item->{ReservedForSurname} = $ItemBorrowerReserveInfo->{'surname'}; - $item->{ReservedForFirstname} = $ItemBorrowerReserveInfo->{'firstname'}; + $item->{ReservedForSurname} = $patron->surname; + $item->{ReservedForFirstname} = $patron->firstname; $item->{ExpectedAtLibrary} = $first_hold->branchcode; $item->{waitingdate} = $first_hold->waitingdate; } @@ -452,21 +451,22 @@ foreach my $biblionumber (@biblionumbers) { } } - my $branch = C4::Circulation::_GetCircControlBranch($item, $borrowerinfo); + my $patron_unblessed = $patron->unblessed; + my $branch = C4::Circulation::_GetCircControlBranch($item, $patron_unblessed); my $branchitemrule = GetBranchItemRule( $branch, $item->{'itype'} ); $item->{'holdallowed'} = $branchitemrule->{'holdallowed'}; - my $can_item_be_reserved = CanItemBeReserved( $borrowerinfo->{borrowernumber}, $itemnumber ); + my $can_item_be_reserved = CanItemBeReserved( $patron->borrowernumber, $itemnumber ); $item->{not_holdable} = $can_item_be_reserved unless ( $can_item_be_reserved eq 'OK' ); - $item->{item_level_holds} = OPACItemHoldsAllowed( $item, $borrowerinfo ); + $item->{item_level_holds} = OPACItemHoldsAllowed( $item, $patron_unblessed); if ( !$item->{cantreserve} && !$exceeded_maxreserves - && IsAvailableForItemLevelRequest($item, $borrowerinfo) + && IsAvailableForItemLevelRequest($item, $patron_unblessed) && $can_item_be_reserved eq 'OK' ) { @@ -611,8 +611,8 @@ foreach my $biblionumber (@biblionumbers) { holdsview => 1, C4::Search::enabled_staff_search_views, ); - if (defined $borrowerinfo && exists $borrowerinfo->{'branchcode'}) { - $template->param( borrower_branchcode => $borrowerinfo->{'branchcode'},); + if ( $patron ) { # FIXME This test seems very useless + $template->param( borrower_branchcode => $patron->branchcode ); } $biblioloopiter{biblionumber} = $biblionumber; diff --git a/reviews/reviewswaiting.pl b/reviews/reviewswaiting.pl index 452b54c283..26696645b5 100755 --- a/reviews/reviewswaiting.pl +++ b/reviews/reviewswaiting.pl @@ -21,8 +21,8 @@ use CGI qw ( -utf8 ); use C4::Auth; use C4::Output; use C4::Context; -use C4::Members; use C4::Biblio; +use Koha::Patrons; use Koha::Reviews; my $query = new CGI; @@ -68,12 +68,12 @@ my $reviews = Koha::Reviews->search( foreach ( @$reviews ) { my $borrowernumber = $_->{borrowernumber}; - my $borrowerData = GetMember('borrowernumber' => $borrowernumber); + my $patron = Koha::Patrons->find( $borrowernumber); my $biblioData = GetBiblioData($_->{biblionumber}); # setting some borrower info into this hash $_->{bibliotitle} = $biblioData->{'title'}; - $_->{surname} = $borrowerData->{'surname'}; - $_->{firstname} = $borrowerData->{'firstname'}; + $_->{surname} = $patron->surname; + $_->{firstname} = $patron->firstname; } my $url = "/cgi-bin/koha/reviews/reviewswaiting.pl?status=$status"; diff --git a/serials/routing-preview.pl b/serials/routing-preview.pl index 491bf2b2e1..73d89dff0b 100755 --- a/serials/routing-preview.pl +++ b/serials/routing-preview.pl @@ -36,6 +36,7 @@ use URI::Escape; use Koha::Biblios; use Koha::Libraries; +use Koha::Patrons; my $query = new CGI; my $subscriptionid = $query->param('subscriptionid'); @@ -121,7 +122,7 @@ if($ok){ my $memberloop = []; for my $routing (@routinglist) { - my $member = GetMember( borrowernumber => $routing->{borrowernumber} ); + my $member = Koha::Patrons->find( $routing->{borrowernumber} )->unblessed; $member->{name} = "$member->{firstname} $member->{surname}"; push @{$memberloop}, $member; } diff --git a/serials/routing.pl b/serials/routing.pl index 32f42e52ab..af23b6cffd 100755 --- a/serials/routing.pl +++ b/serials/routing.pl @@ -37,6 +37,7 @@ use C4::Context; use C4::Members; use C4::Serials; +use Koha::Patrons; use URI::Escape; @@ -95,7 +96,7 @@ my ($template, $loggedinuser, $cookie) my $member_loop = []; for my $routing ( @routinglist ) { - my $member=GetMember('borrowernumber' => $routing->{borrowernumber}); + my $member = Koha::Patrons->find( $routing->{borrowernumber} )->unblessed; $member->{location} = $member->{branchcode}; if ($member->{firstname} ) { $member->{name} = $member->{firstname} . q| |; diff --git a/suggestion/suggestion.pl b/suggestion/suggestion.pl index fb977623e5..a897ca6bfe 100755 --- a/suggestion/suggestion.pl +++ b/suggestion/suggestion.pl @@ -34,6 +34,7 @@ use Koha::DateUtils qw( dt_from_string ); use Koha::AuthorisedValues; use Koha::Acquisition::Currencies; use Koha::Libraries; +use Koha::Patrons; use URI::Escape; @@ -69,9 +70,9 @@ sub GetCriteriumDesc{ return $av->count ? $av->next->lib : 'Unkown'; } if ($displayby =~/suggestedby/||$displayby =~/managedby/||$displayby =~/acceptedby/){ - my $borr=C4::Members::GetMember(borrowernumber=>$criteriumvalue); - return "" unless $borr; - return $$borr{surname} . ", " . $$borr{firstname}; + my $patron = Koha::Patrons->find( $criteriumvalue ); + return "" unless $patron; + return $patron->surname . ", " . $patron->firstname; } if ( $displayby =~ /budgetid/) { my $budget = GetBudget($criteriumvalue); @@ -281,14 +282,15 @@ if ($op=~/else/) { foreach my $element ( qw(managedby suggestedby acceptedby) ) { # $debug || warn $$suggestion_ref{$element}; if ($$suggestion_ref{$element}){ - my $member=GetMember(borrowernumber=>$$suggestion_ref{$element}); + my $patron = Koha::Patrons->find( $$suggestion_ref{$element} ); + my $category = $patron->category; $template->param( - $element."_borrowernumber"=>$$member{borrowernumber}, - $element."_firstname"=>$$member{firstname}, - $element."_surname"=>$$member{surname}, - $element."_branchcode"=>$$member{branchcode}, - $element."_description"=>$$member{description}, - $element."_category_type"=>$$member{category_type} + $element."_borrowernumber"=>$patron->borrowernumber, + $element."_firstname"=>$patron->firstname, + $element."_surname"=>$patron->surname, + $element."_branchcode"=>$patron->branchcode, + $element."_description"=>$category->description, + $element."_category_type"=>$category->category_type, ); } } diff --git a/svc/members/search b/svc/members/search index 4f798ab871..3276cf8825 100755 --- a/svc/members/search +++ b/svc/members/search @@ -25,6 +25,7 @@ use C4::Output qw( output_with_http_headers ); use C4::Utils::DataTables qw( dt_get_params ); use C4::Utils::DataTables::Members qw( search ); use Koha::DateUtils qw( output_pref dt_from_string ); +use Koha::Patrons; my $input = new CGI; @@ -63,11 +64,11 @@ if ( $searchmember and $searchfieldstype and $searchfieldstype eq 'standard' ) { - my $member = C4::Members::GetMember( cardnumber => $searchmember ); + my $member = Koha::Patrons->find( { cardnumber => $searchmember } ); $results = { iTotalRecords => 1, iTotalDisplayRecords => 1, - patrons => [ $member ], + patrons => [ $member->unblessed ], } if $member; } diff --git a/t/db_dependent/Acquisition/OrderUsers.t b/t/db_dependent/Acquisition/OrderUsers.t index 11ed596164..1c9a4154b9 100644 --- a/t/db_dependent/Acquisition/OrderUsers.t +++ b/t/db_dependent/Acquisition/OrderUsers.t @@ -77,8 +77,6 @@ my $borrowernumber = C4::Members::AddMember( userid => 'TESTUSERID' ); -my $borrower = C4::Members::GetMember( borrowernumber => $borrowernumber ); - C4::Acquisition::ModOrderUsers( $ordernumber, $borrowernumber ); my $is_added = grep { /^$borrowernumber$/ } C4::Acquisition::GetOrderUsers( $ordernumber ); diff --git a/t/db_dependent/Circulation.t b/t/db_dependent/Circulation.t index d1cbc36200..9319924978 100755 --- a/t/db_dependent/Circulation.t +++ b/t/db_dependent/Circulation.t @@ -35,6 +35,7 @@ use Koha::DateUtils; use Koha::Database; use Koha::IssuingRules; use Koha::Checkouts; +use Koha::Patrons; use Koha::Subscriptions; my $schema = Koha::Database->schema; @@ -294,8 +295,8 @@ C4::Context->dbh->do("DELETE FROM accountlines"); my $hold_waiting_borrowernumber = AddMember(%hold_waiting_borrower_data); my $restricted_borrowernumber = AddMember(%restricted_borrower_data); - my $renewing_borrower = GetMember( borrowernumber => $renewing_borrowernumber ); - my $restricted_borrower = GetMember( borrowernumber => $restricted_borrowernumber ); + my $renewing_borrower = Koha::Patrons->find( $renewing_borrowernumber )->unblessed; + my $restricted_borrower = Koha::Patrons->find( $restricted_borrowernumber )->unblessed; my $bibitems = ''; my $priority = '1'; @@ -377,7 +378,7 @@ C4::Context->dbh->do("DELETE FROM accountlines"); is( $error, 'on_reserve', '(Bug 10663) Cannot renew, reserved (returned error is on_reserve)'); my $reserveid = C4::Reserves::GetReserveId({ biblionumber => $biblionumber, borrowernumber => $reserving_borrowernumber}); - my $reserving_borrower = GetMember( borrowernumber => $reserving_borrowernumber ); + my $reserving_borrower = Koha::Patrons->find( $reserving_borrowernumber )->unblessed; AddIssue($reserving_borrower, $barcode3); my $reserve = $dbh->selectrow_hashref( 'SELECT * FROM old_reserves WHERE reserve_id = ?', @@ -841,7 +842,7 @@ C4::Context->dbh->do("DELETE FROM accountlines"); ); my $a_borrower_borrowernumber = AddMember(%a_borrower_data); - my $a_borrower = GetMember( borrowernumber => $a_borrower_borrowernumber ); + my $a_borrower = Koha::Patrons->find( $a_borrower_borrowernumber )->unblessed; my $yesterday = DateTime->today(time_zone => C4::Context->tz())->add( days => -1 ); my $two_days_ahead = DateTime->today(time_zone => C4::Context->tz())->add( days => 2 ); @@ -922,7 +923,8 @@ C4::Context->dbh->do("DELETE FROM accountlines"); my $borrowernumber = AddMember(%a_borrower_data); - my $issue = AddIssue( GetMember( borrowernumber => $borrowernumber ), $barcode ); + my $borrower = Koha::Patrons->find( $borrowernumber )->unblessed; + my $issue = AddIssue( $borrower, $barcode ); UpdateFine( { issue_id => $issue->id(), @@ -992,8 +994,8 @@ C4::Context->dbh->do("DELETE FROM accountlines"); branchcode => $library2->{branchcode}, ); - my $borrower1 = GetMember( borrowernumber => $borrowernumber1 ); - my $borrower2 = GetMember( borrowernumber => $borrowernumber2 ); + my $borrower1 = Koha::Patrons->find( $borrowernumber1 )->unblessed; + my $borrower2 = Koha::Patrons->find( $borrowernumber2 )->unblessed; my $issue = AddIssue( $borrower1, $barcode1 ); @@ -1063,7 +1065,8 @@ C4::Context->dbh->do("DELETE FROM accountlines"); branchcode => $branch, ); - my $borrower = GetMember( borrowernumber => $borrowernumber ); + my $borrower = Koha::Patrons->find( $borrowernumber )->unblessed; + my $issue = AddIssue( $borrower, $barcode, undef, undef, undef, undef, { onsite_checkout => 1 } ); my ( $renewed, $error ) = CanBookBeRenewed( $borrowernumber, $itemnumber ); is( $renewed, 0, 'CanBookBeRenewed should not allow to renew on-site checkout' ); @@ -1089,7 +1092,7 @@ C4::Context->dbh->do("DELETE FROM accountlines"); my $patron = $builder->build({ source => 'Borrower', value => { branchcode => $library->{branchcode} } } ); - my $issue = AddIssue( GetMember( borrowernumber => $patron->{borrowernumber} ), $barcode ); + my $issue = AddIssue( $patron, $barcode ); UpdateFine( { issue_id => $issue->id(), @@ -1393,7 +1396,7 @@ subtest 'MultipleReserves' => sub { branchcode => $branch, ); my $renewing_borrowernumber = AddMember(%renewing_borrower_data); - my $renewing_borrower = GetMember( borrowernumber => $renewing_borrowernumber ); + my $renewing_borrower = Koha::Patrons->find( $renewing_borrowernumber )->unblessed; my $issue = AddIssue( $renewing_borrower, $barcode1); my $datedue = dt_from_string( $issue->date_due() ); is (defined $issue->date_due(), 1, "item 1 checked out"); diff --git a/t/db_dependent/Circulation/Branch.t b/t/db_dependent/Circulation/Branch.t index 3e4606416e..9a040d1076 100644 --- a/t/db_dependent/Circulation/Branch.t +++ b/t/db_dependent/Circulation/Branch.t @@ -143,7 +143,6 @@ my $borrower_id1 = C4::Members::AddMember( categorycode => $samplecat->{categorycode}, branchcode => $samplebranch1->{branchcode}, ); -my $borrower_1 = C4::Members::GetMember(borrowernumber => $borrower_id1); is_deeply( GetBranchBorrowerCircRule(), diff --git a/t/db_dependent/Circulation/CheckIfIssuedToPatron.t b/t/db_dependent/Circulation/CheckIfIssuedToPatron.t index d2396c9c16..f74327ffa8 100644 --- a/t/db_dependent/Circulation/CheckIfIssuedToPatron.t +++ b/t/db_dependent/Circulation/CheckIfIssuedToPatron.t @@ -25,6 +25,7 @@ use C4::Biblio; use C4::Items; use C4::Members; use Koha::Library; +use Koha::Patrons; use MARC::Record; BEGIN { @@ -74,8 +75,8 @@ AddItem({ barcode => $barcode2, %item_info }, $biblionumber2); my $borrowernumber1 = AddMember(categorycode => $categorycode, branchcode => $branchcode); my $borrowernumber2 = AddMember(categorycode => $categorycode, branchcode => $branchcode); -my $borrower1 = GetMember(borrowernumber => $borrowernumber1); -my $borrower2 = GetMember(borrowernumber => $borrowernumber2); +my $borrower1 = Koha::Patrons->find( $borrowernumber1 )->unblessed; +my $borrower2 = Koha::Patrons->find( $borrowernumber2 )->unblessed; my $module = new Test::MockModule('C4::Context'); $module->mock('userenv', sub { { branch => $branchcode } }); diff --git a/t/db_dependent/Circulation/GetPendingOnSiteCheckouts.t b/t/db_dependent/Circulation/GetPendingOnSiteCheckouts.t index 30aadcb160..3d28e505c2 100644 --- a/t/db_dependent/Circulation/GetPendingOnSiteCheckouts.t +++ b/t/db_dependent/Circulation/GetPendingOnSiteCheckouts.t @@ -26,8 +26,8 @@ use C4::Circulation; use C4::Items; use C4::Members; -use Koha::Library; use Koha::Libraries; +use Koha::Patrons; use Koha::Patron::Categories; use MARC::Record; @@ -63,7 +63,7 @@ my $borrowernumber = $builder->build( } )->{borrowernumber}; -my $borrower = GetMember(borrowernumber => $borrowernumber); +my $borrower = Koha::Patrons->find( $borrowernumber )->unblessed; # Need to mock userenv for AddIssue my $module = new Test::MockModule('C4::Context'); diff --git a/t/db_dependent/Circulation/GetTopIssues.t b/t/db_dependent/Circulation/GetTopIssues.t index a008187457..569176b9cb 100644 --- a/t/db_dependent/Circulation/GetTopIssues.t +++ b/t/db_dependent/Circulation/GetTopIssues.t @@ -29,6 +29,7 @@ use C4::Items; use C4::Members; use Koha::Database; +use Koha::Patrons; my $schema = Koha::Database->new()->schema(); my $dbh = $schema->storage->dbh; @@ -67,7 +68,7 @@ my $borrowernumber = AddMember( categorycode => $category, branchcode => $branch_1->{ branchcode } ); -my $borrower = GetMember(borrowernumber => $borrowernumber); +my $borrower = Koha::Patrons->find( $borrowernumber )->unblessed; AddIssue($borrower, 'GTI_BARCODE_001'); AddIssue($borrower, 'GTI_BARCODE_002'); diff --git a/t/db_dependent/Circulation/IsItemIssued.t b/t/db_dependent/Circulation/IsItemIssued.t index ac98edf130..8a8ccf634a 100644 --- a/t/db_dependent/Circulation/IsItemIssued.t +++ b/t/db_dependent/Circulation/IsItemIssued.t @@ -26,6 +26,7 @@ use C4::Items; use C4::Members; use Koha::Database; use Koha::DateUtils; +use Koha::Patrons; use t::lib::TestBuilder; @@ -55,7 +56,7 @@ my $borrowernumber = AddMember( branchcode => $library->{branchcode}, ); -my $borrower = GetMember( borrowernumber => $borrowernumber ); +my $borrower = Koha::Patrons->find( $borrowernumber )->unblessed; my $record = MARC::Record->new(); my ( $biblionumber, $biblioitemnumber ) = AddBiblio( $record, '' ); diff --git a/t/db_dependent/Circulation/IssuingRules/maxsuspensiondays.t b/t/db_dependent/Circulation/IssuingRules/maxsuspensiondays.t index a5b6d6f20a..9e41b464fd 100644 --- a/t/db_dependent/Circulation/IssuingRules/maxsuspensiondays.t +++ b/t/db_dependent/Circulation/IssuingRules/maxsuspensiondays.t @@ -8,7 +8,7 @@ use C4::Context; use C4::Biblio qw( AddBiblio ); use C4::Circulation qw( AddIssue AddReturn ); use C4::Items qw( AddItem ); -use C4::Members qw( AddMember GetMember ); +use C4::Members qw( AddMember ); use Koha::Database; use Koha::DateUtils; use Koha::Patron::Debarments qw( GetDebarments DelDebarment ); @@ -51,7 +51,7 @@ my $borrowernumber = AddMember( categorycode => $patron_category->{categorycode}, branchcode => $branchcode, ); -my $borrower = GetMember( borrowernumber => $borrowernumber ); +my $borrower = Koha::Patrons->find( $borrowernumber )->unblessed; my $record = MARC::Record->new(); $record->append_fields( diff --git a/t/db_dependent/Circulation/Returns.t b/t/db_dependent/Circulation/Returns.t index e8d52af732..3910951bc1 100644 --- a/t/db_dependent/Circulation/Returns.t +++ b/t/db_dependent/Circulation/Returns.t @@ -32,6 +32,7 @@ use Koha::Database; use Koha::Account::Lines; use Koha::DateUtils; use Koha::Items; +use Koha::Patrons; use MARC::Record; use MARC::Field; @@ -162,7 +163,7 @@ subtest "AddReturn logging on statistics table (item-level_itypes=1)" => sub { } ); - my $borrower = GetMember( borrowernumber => $borrowernumber ); + my $borrower = Koha::Patrons->find( $borrowernumber )->unblessed; AddIssue( $borrower, $item_with_itemtype->{ barcode } ); AddReturn( $item_with_itemtype->{ barcode }, $branch ); # Test item-level itemtype was recorded on the 'statistics' table @@ -248,7 +249,7 @@ subtest "AddReturn logging on statistics table (item-level_itypes=0)" => sub { } }); - my $borrower = GetMember( borrowernumber => $borrowernumber ); + my $borrower = Koha::Patrons->find( $borrowernumber )->unblessed; AddIssue( $borrower, $item_with_itemtype->{ barcode } ); AddReturn( $item_with_itemtype->{ barcode }, $branch ); diff --git a/t/db_dependent/Circulation/issue.t b/t/db_dependent/Circulation/issue.t index 312f6a9afd..67195edc94 100644 --- a/t/db_dependent/Circulation/issue.t +++ b/t/db_dependent/Circulation/issue.t @@ -17,7 +17,7 @@ use Modern::Perl; -use Test::More tests => 32; +use Test::More tests => 30; use DateTime::Duration; use t::lib::Mocks; @@ -32,6 +32,7 @@ use C4::Reserves; use Koha::Database; use Koha::DateUtils; use Koha::Library; +use Koha::Patrons; BEGIN { require_ok('C4::Circulation'); @@ -147,14 +148,14 @@ my $borrower_id1 = C4::Members::AddMember( categorycode => $categorycode, branchcode => $branchcode_1 ); -my $borrower_1 = C4::Members::GetMember(borrowernumber => $borrower_id1); +my $borrower_1 = Koha::Patrons->find( $borrower_id1 )->unblessed; my $borrower_id2 = C4::Members::AddMember( firstname => 'firstname2', surname => 'surname2 ', categorycode => $categorycode, branchcode => $branchcode_2, ); -my $borrower_2 = C4::Members::GetMember(borrowernumber => $borrower_id2); +my $borrower_2 = Koha::Patrons->find( $borrower_id2 )->unblessed; my @USERENV = ( $borrower_id1, 'test', 'MASTERTEST', 'firstname', $branchcode_1, @@ -246,19 +247,19 @@ my $issue3 = C4::Circulation::AddIssue( $borrower_1, $barcode_1 ); @renewcount = C4::Circulation::GetRenewCount(); is_deeply( \@renewcount, - [ 0, undef, 0 ], # FIXME Need to be fixed, see FIXME in GetRenewCount + [ 0, 0, 0 ], # FIXME Need to be fixed, see FIXME in GetRenewCount "Without issuing rules and without parameter, GetRenewCount returns renewcount = 0, renewsallowed = undef, renewsleft = 0" ); @renewcount = C4::Circulation::GetRenewCount(-1); is_deeply( \@renewcount, - [ 0, undef, 0 ], # FIXME Need to be fixed + [ 0, 0, 0 ], # FIXME Need to be fixed "Without issuing rules and without wrong parameter, GetRenewCount returns renewcount = 0, renewsallowed = undef, renewsleft = 0" ); @renewcount = C4::Circulation::GetRenewCount($borrower_id1, $item_id1); is_deeply( \@renewcount, - [ 2, undef, 0 ], + [ 2, 0, 0 ], "Without issuing rules and with a valid parameter, renewcount = 2, renewsallowed = undef, renewsleft = 0" ); @@ -291,18 +292,6 @@ is_deeply( $dbh->do(q| UPDATE issuingrules SET renewalsallowed = 3 |); -@renewcount = C4::Circulation::GetRenewCount(); -is_deeply( - \@renewcount, - [ 0, 3, 3 ], - "With issuing rules (renewal allowed) and without parameter, GetRenewCount returns renewcount = 0, renewsallowed = 3, renewsleft = 3" -); -@renewcount = C4::Circulation::GetRenewCount(-1); -is_deeply( - \@renewcount, - [ 0, 3, 3 ], - "With issuing rules (renewal allowed) and without wrong parameter, GetRenewCount returns renewcount = 0, renewsallowed = 3, renewsleft = 3" -); @renewcount = C4::Circulation::GetRenewCount($borrower_id1, $item_id1); is_deeply( \@renewcount, diff --git a/t/db_dependent/Holds/RevertWaitingStatus.t b/t/db_dependent/Holds/RevertWaitingStatus.t index 146adb8d9f..ae7fdaa8dd 100755 --- a/t/db_dependent/Holds/RevertWaitingStatus.t +++ b/t/db_dependent/Holds/RevertWaitingStatus.t @@ -28,6 +28,7 @@ use C4::Members; use C4::Reserves; use Koha::Libraries; +use Koha::Patrons; use t::lib::TestBuilder; @@ -101,7 +102,8 @@ foreach my $borrowernumber (@borrowernumbers) { } ModReserveAffect( $itemnumber, $borrowernumbers[0] ); -C4::Circulation::AddIssue( GetMember( borrowernumber => $borrowernumbers[1] ), +my $patron = Koha::Patrons->find( $borrowernumbers[1] )->unblessed; +C4::Circulation::AddIssue( $patron, $item_barcode, my $datedue, my $cancelreserve = 'revert' ); my $priorities = $dbh->selectall_arrayref( diff --git a/t/db_dependent/Koha/Patrons.t b/t/db_dependent/Koha/Patrons.t index a68ab6c2f7..ef34199788 100644 --- a/t/db_dependent/Koha/Patrons.t +++ b/t/db_dependent/Koha/Patrons.t @@ -467,7 +467,7 @@ subtest 'checkouts + get_overdues' => sub { is( ref($checkouts), 'Koha::Checkouts', 'checkouts should return a Koha::Checkouts object' ); # Not sure how this is useful, but AddIssue pass this variable to different other subroutines - $patron = GetMember( borrowernumber => $patron->borrowernumber ); + $patron = Koha::Patrons->find( $patron->borrowernumber )->unblessed; my $module = new Test::MockModule('C4::Context'); $module->mock( 'userenv', sub { { branch => $library->{branchcode} } } ); diff --git a/t/db_dependent/Members.t b/t/db_dependent/Members.t index 47d0b20fca..f75652c267 100755 --- a/t/db_dependent/Members.t +++ b/t/db_dependent/Members.t @@ -17,7 +17,7 @@ use Modern::Perl; -use Test::More tests => 65; +use Test::More tests => 63; use Test::MockModule; use Data::Dumper qw/Dumper/; use C4::Context; @@ -95,8 +95,9 @@ my %data = ( my $addmem=AddMember(%data); ok($addmem, "AddMember()"); -my $member = GetMember( cardnumber => $CARDNUMBER ) +my $member = Koha::Patrons->find( { cardnumber => $CARDNUMBER } ) or BAIL_OUT("Cannot read member with card $CARDNUMBER"); +$member = $member->unblessed; ok ( $member->{firstname} eq $FIRSTNAME && $member->{surname} eq $SURNAME && @@ -112,7 +113,7 @@ $member->{email} = $EMAIL; $member->{phone} = $PHONE; $member->{emailpro} = $EMAILPRO; ModMember(%$member); -my $changedmember = GetMember( cardnumber => $CARDNUMBER ); +my $changedmember = Koha::Patrons->find( { cardnumber => $CARDNUMBER } )->unblessed; ok ( $changedmember->{firstname} eq $CHANGED_FIRSTNAME && $changedmember->{email} eq $EMAIL && $changedmember->{phone} eq $PHONE && @@ -172,21 +173,21 @@ is( Check_Userid( 'tomasito.none', '' ), 0, is( Check_Userid( 'tomasitoxxx', '' ), 1, 'non-existent userid -> unique (blank borrowernumber)' ); -my $borrower = GetMember( borrowernumber => $borrowernumber ); +my $borrower = Koha::Patrons->find( $borrowernumber )->unblessed; is( $borrower->{dateofbirth}, undef, 'AddMember should undef dateofbirth if empty string is given'); is( $borrower->{debarred}, undef, 'AddMember should undef debarred if empty string is given'); isnt( $borrower->{dateexpiry}, '0000-00-00', 'AddMember should not set dateexpiry to 0000-00-00 if empty string is given'); isnt( $borrower->{dateenrolled}, '0000-00-00', 'AddMember should not set dateenrolled to 0000-00-00 if empty string is given'); ModMember( borrowernumber => $borrowernumber, dateofbirth => '', debarred => '', dateexpiry => '', dateenrolled => '' ); -$borrower = GetMember( borrowernumber => $borrowernumber ); +$borrower = Koha::Patrons->find( $borrowernumber )->unblessed; is( $borrower->{dateofbirth}, undef, 'ModMember should undef dateofbirth if empty string is given'); is( $borrower->{debarred}, undef, 'ModMember should undef debarred if empty string is given'); isnt( $borrower->{dateexpiry}, '0000-00-00', 'ModMember should not set dateexpiry to 0000-00-00 if empty string is given'); isnt( $borrower->{dateenrolled}, '0000-00-00', 'ModMember should not set dateenrolled to 0000-00-00 if empty string is given'); ModMember( borrowernumber => $borrowernumber, dateofbirth => '1970-01-01', debarred => '2042-01-01', dateexpiry => '9999-12-31', dateenrolled => '2015-09-06' ); -$borrower = GetMember( borrowernumber => $borrowernumber ); +$borrower = Koha::Patrons->find( $borrowernumber )->unblessed; is( $borrower->{dateofbirth}, '1970-01-01', 'ModMember should correctly set dateofbirth if a valid date is given'); is( $borrower->{debarred}, '2042-01-01', 'ModMember should correctly set debarred if a valid date is given'); is( $borrower->{dateexpiry}, '9999-12-31', 'ModMember should correctly set dateexpiry if a valid date is given'); @@ -199,25 +200,25 @@ is( Check_Userid( 'tomasito.none', '' ), 0, 'userid not unique (blank borrowernumber)' ); is( Check_Userid( 'tomasito.none', $new_borrowernumber ), 0, 'userid not unique (second borrowernumber passed)' ); -$borrower = GetMember( borrowernumber => $new_borrowernumber ); +$borrower = Koha::Patrons->find( $new_borrowernumber )->unblessed; ok( $borrower->{userid} ne 'tomasito', "Borrower with duplicate userid has new userid generated" ); $data{ cardnumber } = "234567890"; $data{userid} = 'a_user_id'; $borrowernumber = AddMember( %data ); -$borrower = GetMember( borrowernumber => $borrowernumber ); +$borrower = Koha::Patrons->find( $borrowernumber )->unblessed; is( $borrower->{userid}, $data{userid}, 'AddMember should insert the given userid' ); subtest 'ModMember should not update userid if not true' => sub { plan tests => 3; ModMember( borrowernumber => $borrowernumber, firstname => 'Tomas', userid => '' ); - $borrower = GetMember( borrowernumber => $borrowernumber ); + $borrower = Koha::Patrons->find( $borrowernumber )->unblessed; is ( $borrower->{userid}, $data{userid}, 'ModMember should not update the userid with an empty string' ); ModMember( borrowernumber => $borrowernumber, firstname => 'Tomas', userid => 0 ); - $borrower = GetMember( borrowernumber => $borrowernumber ); + $borrower = Koha::Patrons->find( $borrowernumber )->unblessed; is ( $borrower->{userid}, $data{userid}, 'ModMember should not update the userid with an 0'); ModMember( borrowernumber => $borrowernumber, firstname => 'Tomas', userid => undef ); - $borrower = GetMember( borrowernumber => $borrowernumber ); + $borrower = Koha::Patrons->find( $borrowernumber )->unblessed; is ( $borrower->{userid}, $data{userid}, 'ModMember should not update the userid with an undefined value'); }; @@ -372,7 +373,7 @@ $dbh->do(q|UPDATE borrowers SET userid = '' WHERE borrowernumber = ?|, undef, $b # Create another patron and verify the userid has been generated $borrowernumber = AddMember( categorycode => $patron_category->{categorycode}, branchcode => $library2->{branchcode} ); ok( $borrowernumber > 0, 'AddMember should have inserted the patron even if no userid is given' ); -$borrower = GetMember( borrowernumber => $borrowernumber ); +$borrower = Koha::Patrons->find( $borrowernumber )->unblessed; ok( $borrower->{userid}, 'A userid should have been generated correctly' ); # Regression tests for BZ12226 @@ -478,18 +479,10 @@ my $password=""; is( $password =~ /^[a-zA-Z]{10}$/ , 1, 'Test for autogenerated password if none submitted'); ( $borrowernumber, $password ) = AddMember_Opac(surname=>"Deckard",firstname=>"Rick",password=>"Nexus-6",branchcode => $library2->{branchcode}); is( $password eq "Nexus-6", 1, 'Test password used if submitted'); -$borrower = GetMember(borrowernumber => $borrowernumber); +$borrower = Koha::Patrons->find( $borrowernumber )->unblessed; my $hashed_up = Koha::AuthUtils::hash_password("Nexus-6", $borrower->{password}); is( $borrower->{password} eq $hashed_up, 1, 'Check password hash equals hash of submitted password' ); -# regression test for bug 16009 -my $patron; -eval { - my $patron = GetMember(cardnumber => undef); -}; -is($@, '', 'Bug 16009: GetMember(cardnumber => undef) works'); -is($patron, undef, 'Bug 16009: GetMember(cardnumber => undef) returns undef'); - subtest 'Trivial test for AddMember_Auto' => sub { plan tests => 3; my $members_mock = Test::MockModule->new( 'C4::Members' ); @@ -499,7 +492,7 @@ subtest 'Trivial test for AddMember_Auto' => sub { my %borr = AddMember_Auto( surname=> 'Dick3', firstname => 'Philip', branchcode => $library->{branchcode}, categorycode => $category->{categorycode}, password => '34567890' ); ok( $borr{borrowernumber}, 'Borrower hash contains borrowernumber' ); is( $borr{cardnumber}, 12345, 'Borrower hash contains cardnumber' ); - $patron = Koha::Patrons->find( $borr{borrowernumber} ); + my $patron = Koha::Patrons->find( $borr{borrowernumber} ); isnt( $patron, undef, 'Patron found' ); }; diff --git a/t/db_dependent/Members/GetAllIssues.t b/t/db_dependent/Members/GetAllIssues.t index 56864a8cb0..e6d15eeb93 100644 --- a/t/db_dependent/Members/GetAllIssues.t +++ b/t/db_dependent/Members/GetAllIssues.t @@ -27,6 +27,7 @@ use C4::Items; use C4::Members; use C4::Circulation; use Koha::Libraries; +use Koha::Patrons; use MARC::Record; my $schema = Koha::Database->schema; @@ -66,8 +67,8 @@ my $borrowernumber1 = AddMember( categorycode => $categorycode, branchcode => $branchcode ); my $borrowernumber2 = AddMember( categorycode => $categorycode, branchcode => $branchcode ); -my $borrower1 = GetMember( borrowernumber => $borrowernumber1 ); -my $borrower2 = GetMember( borrowernumber => $borrowernumber2 ); +my $borrower1 = Koha::Patrons->find( $borrowernumber1 )->unblessed; +my $borrower2 = Koha::Patrons->find( $borrowernumber2 )->unblessed; my $module = new Test::MockModule('C4::Context'); $module->mock( 'userenv', sub { { branch => $branchcode } } ); diff --git a/t/db_dependent/Members/GetOverdues.t b/t/db_dependent/Members/GetOverdues.t index 0f29b80346..c18726be95 100644 --- a/t/db_dependent/Members/GetOverdues.t +++ b/t/db_dependent/Members/GetOverdues.t @@ -27,6 +27,7 @@ use C4::Items; use C4::Members; use C4::Circulation; use Koha::Libraries; +use Koha::Patrons; use MARC::Record; my $schema = Koha::Database->schema; @@ -64,7 +65,7 @@ my $itemnumber3 = my $borrowernumber = AddMember( categorycode => $categorycode, branchcode => $branchcode ); -my $borrower = GetMember( borrowernumber => $borrowernumber ); +my $borrower = Koha::Patrons->find( $borrowernumber )->unblessed; my $module = new Test::MockModule('C4::Context'); $module->mock( 'userenv', sub { { branch => $branchcode } } ); diff --git a/t/db_dependent/Members/GetPendingIssues.t b/t/db_dependent/Members/GetPendingIssues.t index 4906118198..b2319d14b4 100644 --- a/t/db_dependent/Members/GetPendingIssues.t +++ b/t/db_dependent/Members/GetPendingIssues.t @@ -27,6 +27,7 @@ use C4::Items; use C4::Members; use C4::Circulation; use Koha::Library; +use Koha::Patrons; use MARC::Record; my $schema = Koha::Database->schema; @@ -67,8 +68,8 @@ my $borrowernumber1 = AddMember( categorycode => $categorycode, branchcode => $branchcode ); my $borrowernumber2 = AddMember( categorycode => $categorycode, branchcode => $branchcode ); -my $borrower1 = GetMember( borrowernumber => $borrowernumber1 ); -my $borrower2 = GetMember( borrowernumber => $borrowernumber2 ); +my $borrower1 = Koha::Patrons->find( $borrowernumber1 )->unblessed; +my $borrower2 = Koha::Patrons->find( $borrowernumber2 )->unblessed; my $module = new Test::MockModule('C4::Context'); $module->mock( 'userenv', sub { { branch => $branchcode } } ); diff --git a/t/db_dependent/Members/IssueSlip.t b/t/db_dependent/Members/IssueSlip.t index d161602d22..c22cb5a446 100644 --- a/t/db_dependent/Members/IssueSlip.t +++ b/t/db_dependent/Members/IssueSlip.t @@ -29,6 +29,7 @@ use C4::Circulation; use Koha::DateUtils qw( dt_from_string output_pref ); use Koha::Library; +use Koha::Patrons; use DateTime::Duration; use MARC::Record; @@ -117,7 +118,7 @@ my $itemnumber2 = my $borrowernumber = AddMember( categorycode => $categorycode, branchcode => $branchcode ); -my $borrower = GetMember( borrowernumber => $borrowernumber ); +my $borrower = Koha::Patrons->find( $borrowernumber )->unblessed; my $module = new Test::MockModule('C4::Context'); $module->mock( 'userenv', sub { { branch => $branchcode } } ); diff --git a/t/db_dependent/Patron/Borrower_Debarments.t b/t/db_dependent/Patron/Borrower_Debarments.t index 2003b7e2cd..ac59f1b34c 100755 --- a/t/db_dependent/Patron/Borrower_Debarments.t +++ b/t/db_dependent/Patron/Borrower_Debarments.t @@ -66,8 +66,7 @@ ModDebarment({ $debarments = GetDebarments({ borrowernumber => $borrowernumber }); is( $debarments->[1]->{'comment'}, 'Test 3', "ModDebarment functions correctly" ); - -my $patron = GetMember( borrowernumber => $borrowernumber ); +my $patron = Koha::Patrons->find( $borrowernumber )->unblessed; is( $patron->{'debarred'}, '9999-06-10', "Field borrowers.debarred set correctly" ); is( $patron->{'debarredcomment'}, "Test 1\nTest 3", "Field borrowers.debarredcomment set correctly" ); diff --git a/t/db_dependent/Patron/Borrower_Discharge.t b/t/db_dependent/Patron/Borrower_Discharge.t index 88785bdeef..d5e3e2de7d 100644 --- a/t/db_dependent/Patron/Borrower_Discharge.t +++ b/t/db_dependent/Patron/Borrower_Discharge.t @@ -23,7 +23,7 @@ use C4::Biblio qw( AddBiblio ); use C4::Circulation qw( AddIssue AddReturn ); use C4::Context; use C4::Items qw( AddItem ); -use C4::Members qw( AddMember GetMember ); +use C4::Members qw( AddMember ); use Koha::Patron::Discharge; use Koha::Database; diff --git a/t/db_dependent/Patron/Borrower_PrevCheckout.t b/t/db_dependent/Patron/Borrower_PrevCheckout.t index 453ccf1129..3ff2094505 100644 --- a/t/db_dependent/Patron/Borrower_PrevCheckout.t +++ b/t/db_dependent/Patron/Borrower_PrevCheckout.t @@ -5,7 +5,6 @@ use C4::Members; use C4::Circulation; use Koha::Database; use Koha::Patrons; -use Koha::Patron; use Test::More tests => 59; @@ -303,8 +302,7 @@ my $cpvmappings = [ test_it($cpvmappings, "PreIssue"); # Issue item_1 to $patron: -my $patron_get_mem = - GetMember(%{{borrowernumber => $patron->{borrowernumber}}}); +my $patron_get_mem = Koha::Patrons->find( $patron->{borrowernumber} )->unblessed; BAIL_OUT("Issue failed") unless AddIssue($patron_get_mem, $item_1->{barcode}); @@ -375,14 +373,13 @@ test_it($cpvPmappings, "PostReturn"); # [!$issuingimpossible,$needsconfirmation->{PREVISSUE}] # Needs: -# - $patron_from_GetMember +# - $patron # - $item objects (one not issued, another prevIssued) # - $checkprevcheckout pref (first hardno, then hardyes) # Our Patron my $CBBI_patron = $builder->build({source => 'Borrower'}); -my $p_from_GetMember = - GetMember(%{{borrowernumber => $CBBI_patron->{borrowernumber}}}); +$patron = Koha::Patrons->find( $CBBI_patron->{borrowernumber} )->unblessed; # Our Items my $new_item = $builder->build({ source => 'Item', @@ -402,7 +399,7 @@ my $prev_item = $builder->build({ }); # Second is Checked Out BAIL_OUT("CanBookBeIssued Issue failed") - unless AddIssue($p_from_GetMember, $prev_item->{barcode}); + unless AddIssue($patron, $prev_item->{barcode}); # Mappings my $CBBI_mappings = [ @@ -438,7 +435,7 @@ map { t::lib::Mocks::mock_preference('checkprevcheckout', $_->{syspref}); my ( $issuingimpossible, $needsconfirmation ) = C4::Circulation::CanBookBeIssued( - $p_from_GetMember, $_->{item}->{barcode} + $patron, $_->{item}->{barcode} ); is($needsconfirmation->{PREVISSUE}, $_->{result}, $_->{msg}); } @{$CBBI_mappings}; diff --git a/t/db_dependent/Reserves.t b/t/db_dependent/Reserves.t index 0d238162a6..810050efc0 100755 --- a/t/db_dependent/Reserves.t +++ b/t/db_dependent/Reserves.t @@ -37,6 +37,7 @@ use Koha::DateUtils; use Koha::Holds; use Koha::Libraries; use Koha::Notice::Templates; +use Koha::Patrons; use Koha::Patron::Categories; BEGIN { @@ -118,7 +119,7 @@ my %data = ( ); Koha::Patron::Categories->find($category_1)->set({ enrolmentfee => 0})->store; my $borrowernumber = AddMember(%data); -my $borrower = GetMember( borrowernumber => $borrowernumber ); +my $borrower = Koha::Patrons->find( $borrowernumber )->unblessed; my $biblionumber = $bibnum; my $barcode = $testbarcode; diff --git a/t/db_dependent/Utils/Datatables_Members.t b/t/db_dependent/Utils/Datatables_Members.t index 890c6aef4c..949d959364 100644 --- a/t/db_dependent/Utils/Datatables_Members.t +++ b/t/db_dependent/Utils/Datatables_Members.t @@ -44,6 +44,9 @@ my $library = $builder->build({ source => "Branch", }); +my $patron = $builder->build_object({ class => 'Koha::Patrons', value => { flags => 1 } }); +set_logged_in_user( $patron ); + my $branchcode=$library->{branchcode}; my $john_doe = $builder->build({ @@ -461,4 +464,16 @@ subtest 'ExtendedPatronAttributes' => sub { # End $schema->storage->txn_rollback; +sub set_logged_in_user { + my ($patron) = @_; + C4::Context->_new_userenv('xxx'); + C4::Context->set_userenv( + $patron->borrowernumber, $patron->userid, + $patron->cardnumber, 'firstname', + 'surname', $patron->library->branchcode, + 'Midway Public Library', $patron->flags, + '', '' + ); +} + 1; diff --git a/t/db_dependent/rollingloans.t b/t/db_dependent/rollingloans.t index 52748088a8..6be21101c1 100644 --- a/t/db_dependent/rollingloans.t +++ b/t/db_dependent/rollingloans.t @@ -7,6 +7,8 @@ use C4::Circulation; use C4::Members; use C4::Items; use Koha::DateUtils; +use Koha::Patrons; +use t::lib::TestBuilder; use Test::More tests => 8; C4::Context->_new_userenv(1234567); @@ -19,7 +21,8 @@ my $test_item_fic = '502326000402'; my $test_item_24 = '502326000404'; my $test_item_48 = '502326000403'; -my $borrower1 = GetMember(cardnumber => $test_patron); +my $builder = t::lib::TestBuilder->new; +my $borrower1 = $builder->build_object({ class => 'Koha::Patrons', value => { cardnumber => $test_patron } }); my $item1 = GetItem (undef,$test_item_fic); SKIP: { @@ -41,7 +44,7 @@ SKIP: { sub try_issue { my ($cardnumber, $item ) = @_; my $issuedate = '2011-05-16'; - my $borrower = GetMember( cardnumber => $cardnumber ); + my $borrower = Koha::Patrons->find( { cardnumber => $cardnumber } )->unblessed; my ($issuingimpossible,$needsconfirmation) = CanBookBeIssued( $borrower, $item ); my $issue = AddIssue($borrower, $item, undef, 0, $issuedate); return dt_from_string( $issue->due_date() ); diff --git a/tools/batchMod.pl b/tools/batchMod.pl index a1407eb25f..1a216d7c76 100755 --- a/tools/batchMod.pl +++ b/tools/batchMod.pl @@ -39,6 +39,7 @@ use Koha::Biblios; use Koha::DateUtils; use Koha::Items; use Koha::ItemTypes; +use Koha::Patrons; my $input = new CGI; my $dbh = C4::Context->dbh; @@ -74,7 +75,7 @@ my ($template, $loggedinuser, $cookie) }); # Does the user have a restricted item edition permission? -my $uid = $loggedinuser ? GetMember( borrowernumber => $loggedinuser )->{userid} : undef; +my $uid = $loggedinuser ? Koha::Patrons->find( $loggedinuser )->userid : undef; my $restrictededition = $uid ? haspermission($uid, {'tools' => 'items_batchmod_restricted'}) : undef; # In case user is a superlibrarian, edition is not restricted $restrictededition = 0 if ($restrictededition != 0 && C4::Context->IsSuperLibrarian()); diff --git a/tools/import_borrowers.pl b/tools/import_borrowers.pl index 58c2266495..76dc2995bd 100755 --- a/tools/import_borrowers.pl +++ b/tools/import_borrowers.pl @@ -227,12 +227,12 @@ if ( $uploadborrowers && length($uploadborrowers) > 0 ) { my $borrowernumber; my $member; if ( ($matchpoint eq 'cardnumber') && ($borrower{'cardnumber'}) ) { - $member = GetMember( 'cardnumber' => $borrower{'cardnumber'} ); + $member = Koha::Patrons->find( { cardnumber => $borrower{'cardnumber'} } )->unblessed; if ($member) { $borrowernumber = $member->{'borrowernumber'}; } } elsif ( ($matchpoint eq 'userid') && ($borrower{'userid'}) ) { - $member = GetMember( 'userid' => $borrower{'userid'} ); + $member = Koha::Patrons->find( { userid => $borrower{'userid'} } )->unblessed; if ($member) { $borrowernumber = $member->{'borrowernumber'}; } diff --git a/tools/modborrowers.pl b/tools/modborrowers.pl index 8f0a567324..720e2a107e 100755 --- a/tools/modborrowers.pl +++ b/tools/modborrowers.pl @@ -366,8 +366,9 @@ exit; sub GetBorrowerInfos { my ( %info ) = @_; - my $borrower = GetMember( %info ); + my $borrower = Koha::Patrons->find( \%info ); if ( $borrower ) { + $borrower = $borrower->unblessed; for ( qw(dateenrolled dateexpiry) ) { my $userdate = $borrower->{$_}; unless ($userdate && $userdate ne "0000-00-00" and $userdate ne "9999-12-31") { diff --git a/tools/picture-upload.pl b/tools/picture-upload.pl index e74e262480..804bd96b92 100755 --- a/tools/picture-upload.pl +++ b/tools/picture-upload.pl @@ -32,7 +32,6 @@ use C4::Members; use C4::Debug; use Koha::Patrons; -use Koha::Patron::Image; use Koha::Patron::Images; use Koha::Token; diff --git a/tools/viewlog.pl b/tools/viewlog.pl index b7ddb6a787..9af64d5fb6 100755 --- a/tools/viewlog.pl +++ b/tools/viewlog.pl @@ -30,7 +30,7 @@ use C4::Log; use C4::Items; use C4::Debug; use C4::Search; # enabled_staff_search_views -use Koha::Patron::Images; +use Koha::Patrons; use vars qw($debug $cgi_debug); @@ -73,9 +73,9 @@ if ( $src eq 'circ' ) { use C4::Members; use C4::Members::Attributes qw(GetBorrowerAttributes); my $borrowernumber = $object; - my $data = GetMember( 'borrowernumber' => $borrowernumber ); - my $patron_image = Koha::Patron::Images->find($data->{borrowernumber}); - $template->param( picture => 1 ) if $patron_image; + my $patron = Koha::Patrons->find( $borrowernumber ); + $template->param( picture => 1 ) if $patron->image; + my $data = $patron->unblessed; if ( C4::Context->preference('ExtendedPatronAttributes') ) { my $attributes = GetBorrowerAttributes( $data->{'borrowernumber'} ); @@ -90,7 +90,7 @@ if ( $src eq 'circ' ) { $template->param( menu => 1, borrowernumber => $borrowernumber, - categoryname => $data->{'description'}, + categoryname => $patron->category->description, RoutingSerials => C4::Context->preference('RoutingSerials'), ); } @@ -136,20 +136,20 @@ if ($do_it) { #always add firstname and surname for librarian/user if ( $result->{'user'} ) { - my $userdetails = C4::Members::GetMember( borrowernumber => $result->{'user'} ); - if ($userdetails) { - $result->{'userfirstname'} = $userdetails->{'firstname'}; - $result->{'usersurname'} = $userdetails->{'surname'}; + my $patron = Koha::Patrons->find( $result->{'user'} ); + if ($patron) { + $result->{'userfirstname'} = $patron->firstname; + $result->{'usersurname'} = $patron->surname; } } #add firstname and surname for borrower, when using the CIRCULATION, MEMBERS, FINES if ( $result->{module} eq "CIRCULATION" || $result->{module} eq "MEMBERS" || $result->{module} eq "FINES" ) { if ( $result->{'object'} ) { - my $borrowerdetails = C4::Members::GetMember( borrowernumber => $result->{'object'} ); - if ($borrowerdetails) { - $result->{'borrowerfirstname'} = $borrowerdetails->{'firstname'}; - $result->{'borrowersurname'} = $borrowerdetails->{'surname'}; + my $patron = Koha::Patrons->find( $result->{'object'} ); + if ($patron) { + $result->{'borrowerfirstname'} = $patron->firstname; + $result->{'borrowersurname'} = $patron->surname; } } } diff --git a/virtualshelves/shelves.pl b/virtualshelves/shelves.pl index df700839f2..bcd52b7ac8 100755 --- a/virtualshelves/shelves.pl +++ b/virtualshelves/shelves.pl @@ -31,6 +31,7 @@ use Koha::Biblios; use Koha::Biblioitems; use Koha::ItemTypes; use Koha::CsvProfiles; +use Koha::Patrons; use Koha::Virtualshelves; use constant ANYONE => 2; @@ -60,7 +61,7 @@ if ( $op eq 'add_form' ) { if ( $shelf ) { $category = $shelf->category; - my $patron = GetMember( 'borrowernumber' => $shelf->owner ); + my $patron = Koha::Patrons->find( $shelf->owner )->unblessed; $template->param( owner => $patron, ); unless ( $shelf->can_be_managed( $loggedinuser ) ) { push @messages, { type => 'alert', code => 'unauthorized_on_update' }; @@ -228,8 +229,6 @@ if ( $op eq 'view' ) { } ); - my $borrower = GetMember( borrowernumber => $loggedinuser ); - my $xslfile = C4::Context->preference('XSLTListsDisplay'); my $lang = $xslfile ? C4::Languages::getlanguage() : undef; my $sysxml = $xslfile ? C4::XSLT::get_xslt_sysprefs() : undef; -- 2.39.5