View | Details | Raw Unified | Return to bug 12623
Collapse All | Expand All

(-)a/Koha/Borrower/Modifications.pm (-37 / +18 lines)
Lines 26-32 use Modern::Perl; Link Here
26
26
27
use C4::Context;
27
use C4::Context;
28
use C4::Debug;
28
use C4::Debug;
29
use C4::SQLHelper qw(InsertInTable UpdateInTable);
30
29
31
sub new {
30
sub new {
32
    my ( $class, %args ) = @_;
31
    my ( $class, %args ) = @_;
Lines 48-89 to be part of the passed in hash. Link Here
48
sub AddModifications {
47
sub AddModifications {
49
    my ( $self, $data ) = @_;
48
    my ( $self, $data ) = @_;
50
49
51
    if ( $self->{'borrowernumber'} ) {
50
    delete $data->{borrowernumber};
52
        delete $data->{'borrowernumber'};
51
    if( $self->{borrowernumber} ) {
53
52
        return if( not keys %$data );
54
        if ( keys %$data ) {
53
        $data->{borrowernumber} = $self->{borrowernumber};
55
            $data->{'borrowernumber'} = $self->{'borrowernumber'};
56
            my $dbh = C4::Context->dbh;
57
58
            my $query = "
59
                SELECT COUNT(*) AS count
60
                FROM borrower_modifications
61
                WHERE borrowernumber = ?
62
            ";
63
64
            my $sth = $dbh->prepare($query);
65
            $sth->execute( $self->{'borrowernumber'} );
66
            my $result = $sth->fetchrow_hashref();
67
68
            if ( $result->{'count'} ) {
69
                $data->{'verification_token'} = q{};
70
                return UpdateInTable( "borrower_modifications", $data );
71
            }
72
            else {
73
                return InsertInTable( "borrower_modifications", $data );
74
            }
75
        }
76
77
    }
54
    }
78
    elsif ( $self->{'verification_token'} ) {
55
    elsif( $self->{verification_token} ) {
79
        delete $data->{'borrowernumber'};
56
        $data->{verification_token} = $self->{verification_token};
80
        $data->{'verification_token'} = $self->{'verification_token'};
81
82
        return InsertInTable( "borrower_modifications", $data );
83
    }
57
    }
84
    else {
58
    else {
85
        return;
59
        return;
86
    }
60
    }
61
62
    my $rs = Koha::Database->new()->schema->resultset('BorrowerModification');
63
    return $rs->update_or_create($data);
87
}
64
}
88
65
89
=head2 Verify
66
=head2 Verify
Lines 120-125 sub Verify { Link Here
120
$count = Koha::Borrower::Modifications->GetPendingModificationsCount();
97
$count = Koha::Borrower::Modifications->GetPendingModificationsCount();
121
98
122
Returns the number of pending modifications for existing borrowers.
99
Returns the number of pending modifications for existing borrowers.
100
123
=cut
101
=cut
124
102
125
sub GetPendingModificationsCount {
103
sub GetPendingModificationsCount {
Lines 203-212 sub ApproveModifications { Link Here
203
181
204
    return unless $borrowernumber;
182
    return unless $borrowernumber;
205
183
206
    my $data = $self->GetModifications({ borrowernumber => $borrowernumber });
184
    my $data = $self->GetModifications( { borrowernumber => $borrowernumber } );
185
    delete $data->{timestamp};
186
    delete $data->{verification_token};
207
187
208
    if ( UpdateInTable( "borrowers", $data ) ) {
188
    my $borrower = Koha::Database->new()->schema->resultset('Borrower')->find($borrowernumber);
209
        $self->DelModifications({ borrowernumber => $borrowernumber });
189
    return unless($borrower);
190
    if( $borrower->update($data) ) {
191
        $self->DelModifications( { borrowernumber => $borrowernumber } );
210
    }
192
    }
211
}
193
}
212
194
Lines 227-233 sub DenyModifications { Link Here
227
209
228
    return unless $borrowernumber;
210
    return unless $borrowernumber;
229
211
230
    return $self->DelModifications({ borrowernumber => $borrowernumber });
212
    return $self->DelModifications( { borrowernumber => $borrowernumber } );
231
}
213
}
232
214
233
=head2 DelModifications
215
=head2 DelModifications
234
- 

Return to bug 12623