From 5169a4cb4a9988f25bee99e7af56293c27f0ec3c Mon Sep 17 00:00:00 2001 From: Joe Atzberger Date: Fri, 19 Jun 2009 19:32:42 -0500 Subject: [PATCH] checkoverdues should not require $dbh Passing $dbh around is an ancient style that doesn't know to use C4::Context. C4::Context->dbh is efficient, especially for modules that already use Context, including almost all C4. I also internalized $today into the SQL using NOW() in the query and removed sth->finish. Even though I dislike the return style that gives the count, then the array, I left it becuase I don't have time to fix/test all the callers. However, I did convert it so it doesn't require a $count variable and its own loop. Signed-off-by: Galen Charlton --- C4/Overdues.pm | 33 +++++++++++---------------------- 1 file changed, 11 insertions(+), 22 deletions(-) diff --git a/C4/Overdues.pm b/C4/Overdues.pm index 70ed23e8e4..0815386d7b 100644 --- a/C4/Overdues.pm +++ b/C4/Overdues.pm @@ -155,37 +155,26 @@ LEFT JOIN biblioitems USING (biblioitemnumber) =head2 checkoverdues -( $count, $overdueitems )=checkoverdues( $borrowernumber, $dbh ); +($count, $overdueitems) = checkoverdues($borrowernumber); -Not exported +Returns a count and a list of overdueitems for a given borrowernumber =cut sub checkoverdues { - -# From Main.pm, modified to return a list of overdueitems, in addition to a count -#checks whether a borrower has overdue items - my ( $borrowernumber, $dbh ) = @_; - my @datearr = localtime; - my $today = - ( $datearr[5] + 1900 ) . "-" . ( $datearr[4] + 1 ) . "-" . $datearr[3]; - my @overdueitems; - my $count = 0; - my $sth = $dbh->prepare( + my $borrowernumber = shift or return; + my $sth = C4::Context->dbh->prepare( "SELECT * FROM issues - LEFT JOIN items ON issues.itemnumber = items.itemnumber - LEFT JOIN biblio ON items.biblionumber=biblio.biblionumber + LEFT JOIN items ON issues.itemnumber = items.itemnumber + LEFT JOIN biblio ON items.biblionumber = biblio.biblionumber LEFT JOIN biblioitems ON items.biblioitemnumber = biblioitems.biblioitemnumber WHERE issues.borrowernumber = ? - AND issues.date_due < ?" + AND issues.date_due < NOW()" ); - $sth->execute( $borrowernumber, $today ); - while ( my $data = $sth->fetchrow_hashref ) { - push( @overdueitems, $data ); - $count++; - } - $sth->finish; - return ( $count, \@overdueitems ); + # FIXME: SELECT * across 4 tables? do we really need the marc AND marcxml blobs?? + $sth->execute($borrowernumber); + my $results = $sth->fetchall_arrayref({}); + return ( scalar(@$results), $results); # returning the count and the results is silly } =head2 CalcFine -- 2.39.5