# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
-# You should have received a copy of the GNU General Public License along with
-# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
-# Suite 330, Boston, MA 02111-1307 USA
+# You should have received a copy of the GNU General Public License along
+# with Koha; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
use strict;
+#use warnings; FIXME - Bug 2505
use C4::Context;
use C4::Dates qw(format_date_in_iso);
use Digest::MD5 qw(md5_base64);
$borrower = &GetMember(%information);
-Looks up information about a patron (borrower) by either card number
-,firstname, or borrower number, depending on $type value.
-If C<$type> == 'cardnumber', C<&GetBorrower>
-searches by cardnumber then by firstname if not found in cardnumber;
-otherwise, it searches by borrowernumber.
+Retrieve the first patron record meeting on criteria listed in the
+C<%information> hash, which should contain one or more
+pairs of borrowers column names and values, e.g.,
+
+ $borrower = GetMember(borrowernumber => id);
C<&GetBorrower> returns a reference-to-hash whose keys are the fields of
the C<borrowers> table in the Koha database.
+FIXME: GetMember() is used throughout the code as a lookup
+on a unique key such as the borrowernumber, but this meaning is not
+enforced in the routine itself.
+
=cut
#'
sub GetMember {
my ( %information ) = @_;
+ if (exists $information{borrowernumber} && !defined $information{borrowernumber}) {
+ #passing mysql's kohaadmin?? Makes no sense as a query
+ return;
+ }
my $dbh = C4::Context->dbh;
- my $sth;
- my $select = "
-SELECT borrowers.*, categories.category_type, categories.description
-FROM borrowers
-LEFT JOIN categories on borrowers.categorycode=categories.categorycode
-";
- $select.=" WHERE ".join(" AND ",map {"$_ = ?"}keys %information);
- $select=~s/AND $//;
+ 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;
- $sth = $dbh->prepare("$select");
+ my $sth = $dbh->prepare("$select");
$sth->execute(map{$information{$_}} keys %information);
my $data = $sth->fetchall_arrayref({});
- return undef if (scalar(@$data)==0);
- if (scalar(@$data)==1) {return $$data[0];}
- ($data) and return $data;
+ #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 GetAllIssues
- ($count, $issues) = &GetAllIssues($borrowernumber, $sortkey, $limit);
+ $issues = &GetAllIssues($borrowernumber, $sortkey, $limit);
Looks up what the patron with the given borrowernumber has borrowed,
and sorts the results.
C<$limit> is the maximum number of results to return.
-C<&GetAllIssues> returns a two-element array. C<$issues> is a
-reference-to-array, where each element is a reference-to-hash; the
-keys are the fields from the C<issues>, C<biblio>, C<biblioitems>, and
-C<items> tables of the Koha database. C<$count> is the number of
-elements in C<$issues>
+C<&GetAllIssues> an arrayref, C<$issues>, of hashrefs, the keys of which
+are the fields from the C<issues>, C<biblio>, C<biblioitems>, and
+C<items> tables of the Koha database.
=cut
#FIXME: sanity-check order and limit
my $dbh = C4::Context->dbh;
- my $count = 0;
my $query =
- "SELECT *,issues.renewals AS renewals,items.renewals AS totalrenewals,items.timestamp AS itemstimestamp
+ "SELECT *, issues.timestamp as issuestimestamp, issues.renewals AS renewals,items.renewals AS totalrenewals,items.timestamp AS itemstimestamp
FROM issues
LEFT JOIN items on items.itemnumber=issues.itemnumber
LEFT JOIN biblio ON items.biblionumber=biblio.biblionumber
LEFT JOIN biblioitems ON items.biblioitemnumber=biblioitems.biblioitemnumber
WHERE borrowernumber=?
UNION ALL
- SELECT *,old_issues.renewals AS renewals,items.renewals AS totalrenewals,items.timestamp AS itemstimestamp
+ SELECT *, old_issues.timestamp as issuestimestamp, old_issues.renewals AS renewals,items.renewals AS totalrenewals,items.timestamp AS itemstimestamp
FROM old_issues
LEFT JOIN items on items.itemnumber=old_issues.itemnumber
LEFT JOIN biblio ON items.biblionumber=biblio.biblionumber
$query .= " limit $limit";
}
- #print $query;
my $sth = $dbh->prepare($query);
$sth->execute($borrowernumber, $borrowernumber);
my @result;
my $i = 0;
while ( my $data = $sth->fetchrow_hashref ) {
- $result[$i] = $data;
- $i++;
- $count++;
- }
-
- # get all issued items for borrowernumber from oldissues table
- # large chunk of older issues data put into table oldissues
- # to speed up db calls for issuing items
- if ( C4::Context->preference("ReadingHistory") ) {
- # FIXME oldissues (not to be confused with old_issues) is
- # apparently specific to HLT. Not sure if the ReadingHistory
- # syspref is still required, as old_issues by design
- # is no longer checked with each loan.
- my $query2 = "SELECT * FROM oldissues
- LEFT JOIN items ON items.itemnumber=oldissues.itemnumber
- LEFT JOIN biblio ON items.biblionumber=biblio.biblionumber
- LEFT JOIN biblioitems ON items.biblioitemnumber=biblioitems.biblioitemnumber
- WHERE borrowernumber=?
- ORDER BY $order";
- if ( $limit != 0 ) {
- $limit = $limit - $count;
- $query2 .= " limit $limit";
- }
-
- my $sth2 = $dbh->prepare($query2);
- $sth2->execute($borrowernumber);
-
- while ( my $data2 = $sth2->fetchrow_hashref ) {
- $result[$i] = $data2;
- $i++;
- }
+ push @result, $data;
}
- return ( $i, \@result );
+ return \@result;
}
} # sub add_member_orgs
-=head2 GetCities (OUEST-PROVENCE)
+=head2 GetCities
- ($id_cityarrayref, $city_hashref) = &GetCities();
+ $cityarrayref = GetCities();
-Looks up the different city and zip in the database. Returns two
-elements: a reference-to-array, which lists the zip city
-codes, and a reference-to-hash, which maps the name of the city.
-WHERE =>OUEST PROVENCE OR EXTERIEUR
+ Returns an array_ref of the entries in the cities table
+ If there are entries in the table an empty row is returned
+ This is currently only used to populate a popup in memberentry
=cut
sub GetCities {
- #my ($type_city) = @_;
my $dbh = C4::Context->dbh;
- my $query = qq|SELECT cityid,city_zipcode,city_name
- FROM cities
- ORDER BY city_name|;
- my $sth = $dbh->prepare($query);
-
- #$sth->execute($type_city);
- $sth->execute();
- my %city;
- my @id;
- # insert empty value to create a empty choice in cgi popup
- push @id, " ";
- $city{""} = "";
- while ( my $data = $sth->fetchrow_hashref ) {
- push @id, $data->{'city_zipcode'}."|".$data->{'city_name'};
- $city{ $data->{'city_zipcode'}."|".$data->{'city_name'} } = $data->{'city_name'};
- }
-
-#test to know if the table contain some records if no the function return nothing
- my $id = @id;
- if ( $id == 1 ) {
- # all we have is the one blank row
- return ();
- }
- else {
- unshift( @id, "" );
- return ( \@id, \%city );
- }
+ my $city_arr = $dbh->selectall_arrayref(
+ q|SELECT cityid,city_zipcode,city_name FROM cities ORDER BY city_name|,
+ { Slice => {} });
+ if ( @{$city_arr} ) {
+ unshift @{$city_arr}, {
+ city_zipcode => q{},
+ city_name => q{},
+ cityid => q{},
+ };
+ }
+
+ return $city_arr;
}
=head2 GetSortDetails (OUEST-PROVENCE)