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>.
21 Koha::Patron::Modifications
29 use Koha
::Patron
::Attribute
;
30 use Koha
::Patron
::Modification
;
34 use base
qw(Koha::Objects);
38 $count = Koha::Patron::Modifications->pending_count();
40 Returns the number of pending modifications for existing patrons.
45 my ( $self, $branchcode ) = @_;
47 my $dbh = C4
::Context
->dbh;
49 SELECT COUNT(*) AS count
50 FROM borrower_modifications, borrowers
51 WHERE borrower_modifications.borrowernumber > 0
52 AND borrower_modifications.borrowernumber = borrowers.borrowernumber
57 $query .= " AND borrowers.branchcode = ? ";
58 push( @params, $branchcode );
61 my $sth = $dbh->prepare($query);
62 $sth->execute(@params);
63 my $result = $sth->fetchrow_hashref();
65 return $result->{count
};
70 $arrayref = Koha::Patron::Modifications->pending();
72 Returns an arrayref of hashrefs for all pending modifications for existing patrons.
77 my ( $self, $branchcode ) = @_;
79 my $dbh = C4
::Context
->dbh;
81 SELECT borrower_modifications.*
82 FROM borrower_modifications, borrowers
83 WHERE borrower_modifications.borrowernumber > 0
84 AND borrower_modifications.borrowernumber = borrowers.borrowernumber
89 $query .= " AND borrowers.branchcode = ? ";
90 push( @params, $branchcode );
92 $query .= " ORDER BY borrowers.surname, borrowers.firstname";
93 my $sth = $dbh->prepare($query);
94 $sth->execute(@params);
97 while ( my $row = $sth->fetchrow_hashref() ) {
98 foreach my $key ( keys %$row ) {
99 if ( defined $row->{$key} && $key eq 'extended_attributes' ) {
100 my $attributes = from_json
( $row->{$key} );
101 my @pending_attributes;
102 foreach my $attr ( @
{$attributes} ) {
103 push @pending_attributes,
104 Koha
::Patron
::Attribute
->new(
105 { borrowernumber
=> $row->{borrowernumber
},
106 code
=> $attr->{code
},
107 attribute
=> $attr->{value
}
112 $row->{$key} = \
@pending_attributes;
114 delete $row->{$key} unless defined $row->{$key};
124 return 'BorrowerModification';
132 return 'Koha::Patron::Modification';