Bug 16699: Remove requirement from borrowernumberQueryParam
[koha.git] / Koha / Patron / Modifications.pm
blob088f7a0c847358b57e3efb2616e81dc0e6c63eec
1 package Koha::Patron::Modifications;
3 # Copyright 2012 ByWater Solutions
4 # This file is part of Koha.
6 # Koha is free software; you can redistribute it and/or modify it
7 # under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
11 # Koha is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with Koha; if not, see <http://www.gnu.org/licenses>.
19 =head1 NAME
21 Koha::Patron::Modifications
23 =cut
25 use Modern::Perl;
27 use C4::Context;
29 use Koha::Patron::Modification;
31 use base qw(Koha::Objects);
33 =head2 pending_count
35 $count = Koha::Patron::Modifications->pending_count();
37 Returns the number of pending modifications for existing patrons.
39 =cut
41 sub pending_count {
42 my ( $self, $branchcode ) = @_;
44 my $dbh = C4::Context->dbh;
45 my $query = "
46 SELECT COUNT(*) AS count
47 FROM borrower_modifications, borrowers
48 WHERE borrower_modifications.borrowernumber > 0
49 AND borrower_modifications.borrowernumber = borrowers.borrowernumber
52 my @params;
53 if ($branchcode) {
54 $query .= " AND borrowers.branchcode = ? ";
55 push( @params, $branchcode );
58 my $sth = $dbh->prepare($query);
59 $sth->execute(@params);
60 my $result = $sth->fetchrow_hashref();
62 return $result->{count};
65 =head2 pending
67 $arrayref = Koha::Patron::Modifications->pending();
69 Returns an arrayref of hashrefs for all pending modifications for existing patrons.
71 =cut
73 sub pending {
74 my ( $self, $branchcode ) = @_;
76 my $dbh = C4::Context->dbh;
77 my $query = "
78 SELECT borrower_modifications.*
79 FROM borrower_modifications, borrowers
80 WHERE borrower_modifications.borrowernumber > 0
81 AND borrower_modifications.borrowernumber = borrowers.borrowernumber
84 my @params;
85 if ($branchcode) {
86 $query .= " AND borrowers.branchcode = ? ";
87 push( @params, $branchcode );
89 $query .= " ORDER BY borrowers.surname, borrowers.firstname";
90 my $sth = $dbh->prepare($query);
91 $sth->execute(@params);
93 my @m;
94 while ( my $row = $sth->fetchrow_hashref() ) {
95 foreach my $key ( keys %$row ) {
96 delete $row->{$key} unless defined $row->{$key};
99 push( @m, $row );
102 return \@m;
105 sub _type {
106 return 'BorrowerModification';
109 =head3 object_class
111 =cut
113 sub object_class {
114 return 'Koha::Patron::Modification';