Bug 17260: updatedatabase.pl fails on invalid entries in ENUM and BOOLEAN columns
[koha.git] / Koha / Patron / Modifications.pm
blob3ecef11117ece23f9ad8b38fed87e36c5c59e33b
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 JSON;
33 use base qw(Koha::Objects);
35 =head2 pending_count
37 $count = Koha::Patron::Modifications->pending_count();
39 Returns the number of pending modifications for existing patrons.
41 =cut
43 sub pending_count {
44 my ( $self, $branchcode ) = @_;
46 my $dbh = C4::Context->dbh;
47 my $query = "
48 SELECT COUNT(*) AS count
49 FROM borrower_modifications, borrowers
50 WHERE borrower_modifications.borrowernumber > 0
51 AND borrower_modifications.borrowernumber = borrowers.borrowernumber
54 my @params;
55 if ($branchcode) {
56 $query .= " AND borrowers.branchcode = ? ";
57 push( @params, $branchcode );
60 my $sth = $dbh->prepare($query);
61 $sth->execute(@params);
62 my $result = $sth->fetchrow_hashref();
64 return $result->{count};
67 =head2 pending
69 $arrayref = Koha::Patron::Modifications->pending();
71 Returns an arrayref of hashrefs for all pending modifications for existing patrons.
73 =cut
75 sub pending {
76 my ( $self, $branchcode ) = @_;
78 my $dbh = C4::Context->dbh;
79 my $query = "
80 SELECT borrower_modifications.*
81 FROM borrower_modifications, borrowers
82 WHERE borrower_modifications.borrowernumber > 0
83 AND borrower_modifications.borrowernumber = borrowers.borrowernumber
86 my @params;
87 if ($branchcode) {
88 $query .= " AND borrowers.branchcode = ? ";
89 push( @params, $branchcode );
91 $query .= " ORDER BY borrowers.surname, borrowers.firstname";
92 my $sth = $dbh->prepare($query);
93 $sth->execute(@params);
95 my @m;
96 while ( my $row = $sth->fetchrow_hashref() ) {
97 foreach my $key ( keys %$row ) {
98 if ( defined $row->{$key} && $key eq 'extended_attributes' ) {
99 $row->{$key} = from_json($row->{$key});
101 delete $row->{$key} unless defined $row->{$key};
104 push( @m, $row );
107 return \@m;
110 sub _type {
111 return 'BorrowerModification';
114 =head3 object_class
116 =cut
118 sub object_class {
119 return 'Koha::Patron::Modification';