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
55 my $userenv = C4::Context->userenv;
58 my $logged_in_user = Koha::Patrons->find( $userenv->{number} );
60 return 0 unless $logged_in_user->can_see_patrons_from($branchcode);
61 @branchcodes = ( $branchcode );
64 @branchcodes = $logged_in_user->libraries_where_can_see_patrons;
69 $query .= ' AND borrowers.branchcode IN ( ' . join( ',', ('?') x @branchcodes ) . ' )';
70 push( @sql_params, @branchcodes );
73 my ( $count ) = $dbh->selectrow_array( $query, undef, @sql_params );
79 $arrayref = Koha::Patron::Modifications->pending();
81 Returns an arrayref of hashrefs for all pending modifications for existing patrons.
86 my ( $self, $branchcode ) = @_;
88 my $dbh = C4::Context->dbh;
90 SELECT borrower_modifications.*
91 FROM borrower_modifications, borrowers
92 WHERE borrower_modifications.borrowernumber > 0
93 AND borrower_modifications.borrowernumber = borrowers.borrowernumber
96 my $userenv = C4::Context->userenv;
99 my $logged_in_user = Koha::Patrons->find( $userenv->{number} );
101 return 0 unless $logged_in_user->can_see_patrons_from($branchcode);
102 @branchcodes = ( $branchcode );
105 @branchcodes = $logged_in_user->libraries_where_can_see_patrons;
109 if ( @branchcodes ) {
110 $query .= ' AND borrowers.branchcode IN ( ' . join( ',', ('?') x @branchcodes ) . ' )';
111 push( @sql_params, @branchcodes );
113 $query .= " ORDER BY borrowers.surname, borrowers.firstname";
114 my $sth = $dbh->prepare($query);
115 $sth->execute(@sql_params);
118 while ( my $row = $sth->fetchrow_hashref() ) {
119 foreach my $key ( keys %$row ) {
120 if ( defined $row->{$key} && $key eq 'extended_attributes' ) {
121 my $attributes = from_json( $row->{$key} );
122 my @pending_attributes;
123 foreach my $attr ( @{$attributes} ) {
124 push @pending_attributes,
125 Koha::Patron::Attribute->new(
126 { borrowernumber => $row->{borrowernumber},
127 code => $attr->{code},
128 attribute => $attr->{value}
133 $row->{$key} = \@pending_attributes;
135 delete $row->{$key} unless defined $row->{$key};
145 return 'BorrowerModification';
153 return 'Koha::Patron::Modification';