Browse Source

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 <galen.charlton@liblime.com>
3.2.x
Joe Atzberger 15 years ago
committed by Galen Charlton
parent
commit
5169a4cb4a
  1. 33
      C4/Overdues.pm

33
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

Loading…
Cancel
Save