Lines 28-61
use C4::Context;
Link Here
|
28 |
use C4::Debug; |
28 |
use C4::Debug; |
29 |
use C4::SQLHelper qw(InsertInTable UpdateInTable); |
29 |
use C4::SQLHelper qw(InsertInTable UpdateInTable); |
30 |
|
30 |
|
31 |
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); |
|
|
32 |
|
33 |
BEGIN { |
34 |
|
35 |
# set the version for version checking |
36 |
$VERSION = 0.01; |
37 |
require Exporter; |
38 |
@ISA = qw(Exporter); |
39 |
@EXPORT = qw( |
40 |
|
41 |
); |
42 |
|
43 |
my $debug = C4::Context->preference("DebugLevel"); |
44 |
} |
45 |
|
46 |
sub new { |
31 |
sub new { |
47 |
my ( $class, %args ) = @_; |
32 |
my ( $class, %args ) = @_; |
48 |
my $self = bless( {}, $class ); |
|
|
49 |
|
50 |
$self->{'verification_token'} = $args{'verification_token'}; |
51 |
$self->{'borrowernumber'} = $args{'borrowernumber'}; |
52 |
|
33 |
|
53 |
return $self; |
34 |
return bless( \%args, $class ); |
54 |
} |
35 |
} |
55 |
|
36 |
|
56 |
=head2 AddModifications |
37 |
=head2 AddModifications |
57 |
|
38 |
|
58 |
Koha::Borrower::Modifications->AddModifications( %data ); |
39 |
Koha::Borrower::Modifications->AddModifications( $data ); |
59 |
|
40 |
|
60 |
Adds or updates modifications for a borrower. |
41 |
Adds or updates modifications for a borrower. |
61 |
|
42 |
|
Lines 65-77
to be part of the passed in hash.
Link Here
|
65 |
=cut |
46 |
=cut |
66 |
|
47 |
|
67 |
sub AddModifications { |
48 |
sub AddModifications { |
68 |
my ( $self, %data ) = @_; |
49 |
my ( $self, $data ) = @_; |
69 |
|
50 |
|
70 |
if ( $self->{'borrowernumber'} ) { |
51 |
if ( $self->{'borrowernumber'} ) { |
71 |
delete $data{'borrowernumber'}; |
52 |
delete $data->{'borrowernumber'}; |
72 |
|
53 |
|
73 |
if ( keys %data ) { |
54 |
if ( keys %$data ) { |
74 |
$data{'borrowernumber'} = $self->{'borrowernumber'}; |
55 |
$data->{'borrowernumber'} = $self->{'borrowernumber'}; |
75 |
my $dbh = C4::Context->dbh; |
56 |
my $dbh = C4::Context->dbh; |
76 |
|
57 |
|
77 |
my $query = " |
58 |
my $query = " |
Lines 85-104
sub AddModifications {
Link Here
|
85 |
my $result = $sth->fetchrow_hashref(); |
66 |
my $result = $sth->fetchrow_hashref(); |
86 |
|
67 |
|
87 |
if ( $result->{'count'} ) { |
68 |
if ( $result->{'count'} ) { |
88 |
$data{'verification_token'} = q{}; |
69 |
$data->{'verification_token'} = q{}; |
89 |
return UpdateInTable( "borrower_modifications", \%data ); |
70 |
return UpdateInTable( "borrower_modifications", $data ); |
90 |
} |
71 |
} |
91 |
else { |
72 |
else { |
92 |
return InsertInTable( "borrower_modifications", \%data ); |
73 |
return InsertInTable( "borrower_modifications", $data ); |
93 |
} |
74 |
} |
94 |
} |
75 |
} |
95 |
|
76 |
|
96 |
} |
77 |
} |
97 |
elsif ( $self->{'verification_token'} ) { |
78 |
elsif ( $self->{'verification_token'} ) { |
98 |
delete $data{'borrowernumber'}; |
79 |
delete $data->{'borrowernumber'}; |
99 |
$data{'verification_token'} = $self->{'verification_token'}; |
80 |
$data->{'verification_token'} = $self->{'verification_token'}; |
100 |
|
81 |
|
101 |
return InsertInTable( "borrower_modifications", \%data ); |
82 |
return InsertInTable( "borrower_modifications", $data ); |
102 |
} |
83 |
} |
103 |
else { |
84 |
else { |
104 |
return; |
85 |
return; |
Lines 116-127
Returns true if the passed in token is valid.
Link Here
|
116 |
sub Verify { |
97 |
sub Verify { |
117 |
my ( $self, $verification_token ) = @_; |
98 |
my ( $self, $verification_token ) = @_; |
118 |
|
99 |
|
119 |
if ( ref($self) ) { |
100 |
$verification_token = |
120 |
$verification_token = |
101 |
($verification_token) |
121 |
($verification_token) |
102 |
? $verification_token |
122 |
? $verification_token |
103 |
: $self->{'verification_token'}; |
123 |
: $self->{'verification_token'}; |
|
|
124 |
} |
125 |
|
104 |
|
126 |
my $dbh = C4::Context->dbh; |
105 |
my $dbh = C4::Context->dbh; |
127 |
my $query = " |
106 |
my $query = " |
Lines 219-235
them from the modifications table.
Link Here
|
219 |
sub ApproveModifications { |
198 |
sub ApproveModifications { |
220 |
my ( $self, $borrowernumber ) = @_; |
199 |
my ( $self, $borrowernumber ) = @_; |
221 |
|
200 |
|
222 |
if ( ref($self) ) { |
201 |
$borrowernumber = |
223 |
$borrowernumber = |
202 |
($borrowernumber) ? $borrowernumber : $self->{'borrowernumber'}; |
224 |
($borrowernumber) ? $borrowernumber : $self->{'borrowernumber'}; |
|
|
225 |
} |
226 |
|
203 |
|
227 |
return unless $borrowernumber; |
204 |
return unless $borrowernumber; |
228 |
|
205 |
|
229 |
my $data = $self->GetModifications( borrowernumber => $borrowernumber ); |
206 |
my $data = $self->GetModifications({ borrowernumber => $borrowernumber }); |
230 |
|
207 |
|
231 |
if ( UpdateInTable( "borrowers", $data ) ) { |
208 |
if ( UpdateInTable( "borrowers", $data ) ) { |
232 |
$self->DelModifications( borrowernumber => $borrowernumber ); |
209 |
$self->DelModifications({ borrowernumber => $borrowernumber }); |
233 |
} |
210 |
} |
234 |
} |
211 |
} |
235 |
|
212 |
|
Lines 245-294
without commiting the changes to the borrower record.
Link Here
|
245 |
sub DenyModifications { |
222 |
sub DenyModifications { |
246 |
my ( $self, $borrowernumber ) = @_; |
223 |
my ( $self, $borrowernumber ) = @_; |
247 |
|
224 |
|
248 |
if ( ref($self) ) { |
225 |
$borrowernumber = |
249 |
$borrowernumber = |
226 |
($borrowernumber) ? $borrowernumber : $self->{'borrowernumber'}; |
250 |
($borrowernumber) ? $borrowernumber : $self->{'borrowernumber'}; |
|
|
251 |
} |
252 |
|
227 |
|
253 |
return unless $borrowernumber; |
228 |
return unless $borrowernumber; |
254 |
|
229 |
|
255 |
return $self->DelModifications( borrowernumber => $borrowernumber ); |
230 |
return $self->DelModifications({ borrowernumber => $borrowernumber }); |
256 |
} |
231 |
} |
257 |
|
232 |
|
258 |
=head2 DelModifications |
233 |
=head2 DelModifications |
259 |
|
234 |
|
260 |
Koha::Borrower::Modifications->DelModifications( |
235 |
Koha::Borrower::Modifications->DelModifications({ |
261 |
[ borrowernumber => $borrowernumber ], |
236 |
[ borrowernumber => $borrowernumber ], |
262 |
[ verification_token => $verification_token ] |
237 |
[ verification_token => $verification_token ] |
263 |
); |
238 |
}); |
264 |
|
239 |
|
265 |
Deletes the modifications for the given borrowernumber or verification token. |
240 |
Deletes the modifications for the given borrowernumber or verification token. |
266 |
|
241 |
|
267 |
=cut |
242 |
=cut |
268 |
|
243 |
|
269 |
sub DelModifications { |
244 |
sub DelModifications { |
270 |
my ( $self, %params ) = @_; |
245 |
my ( $self, $params ) = @_; |
271 |
|
246 |
|
272 |
my ( $field, $value ); |
247 |
my ( $field, $value ); |
273 |
|
248 |
|
274 |
if ( $params{'borrowernumber'} ) { |
249 |
if ( $params->{'borrowernumber'} ) { |
275 |
$field = 'borrowernumber'; |
250 |
$field = 'borrowernumber'; |
276 |
$value = $params{'borrowernumber'}; |
251 |
$value = $params->{'borrowernumber'}; |
277 |
} |
252 |
} |
278 |
elsif ( $params{'verification_token'} ) { |
253 |
elsif ( $params->{'verification_token'} ) { |
279 |
$field = 'verification_token'; |
254 |
$field = 'verification_token'; |
280 |
$value = $params{'verification_token'}; |
255 |
$value = $params->{'verification_token'}; |
281 |
} |
|
|
282 |
|
283 |
if ( ref($self) && !$value ) { |
284 |
if ( $self->{'borrowernumber'} ) { |
285 |
$field = 'borrowernumber'; |
286 |
$value = $self->{'borrowernumber'}; |
287 |
} |
288 |
elsif ( $self->{'verification_token'} ) { |
289 |
$field = 'verification_token'; |
290 |
$value = $self->{'verification_token'}; |
291 |
} |
292 |
} |
256 |
} |
293 |
|
257 |
|
294 |
return unless $value; |
258 |
return unless $value; |
Lines 309-346
sub DelModifications {
Link Here
|
309 |
|
273 |
|
310 |
=head2 GetModifications |
274 |
=head2 GetModifications |
311 |
|
275 |
|
312 |
$hashref = Koha::Borrower::Modifications->GetModifications( |
276 |
$hashref = Koha::Borrower::Modifications->GetModifications({ |
313 |
[ borrowernumber => $borrowernumber ], |
277 |
[ borrowernumber => $borrowernumber ], |
314 |
[ verification_token => $verification_token ] |
278 |
[ verification_token => $verification_token ] |
315 |
); |
279 |
}); |
316 |
|
280 |
|
317 |
Gets the modifications for the given borrowernumber or verification token. |
281 |
Gets the modifications for the given borrowernumber or verification token. |
318 |
|
282 |
|
319 |
=cut |
283 |
=cut |
320 |
|
284 |
|
321 |
sub GetModifications { |
285 |
sub GetModifications { |
322 |
my ( $self, %params ) = @_; |
286 |
my ( $self, $params ) = @_; |
323 |
|
287 |
|
324 |
my ( $field, $value ); |
288 |
my ( $field, $value ); |
325 |
|
289 |
|
326 |
if ( $params{'borrowernumber'} ) { |
290 |
if ( defined( $params->{'borrowernumber'} ) ) { |
327 |
$field = 'borrowernumber'; |
291 |
$field = 'borrowernumber'; |
328 |
$value = $params{'borrowernumber'}; |
292 |
$value = $params->{'borrowernumber'}; |
329 |
} |
293 |
} |
330 |
elsif ( $params{'verification_token'} ) { |
294 |
elsif ( defined( $params->{'verification_token'} ) ) { |
331 |
$field = 'verification_token'; |
295 |
$field = 'verification_token'; |
332 |
$value = $params{'verification_token'}; |
296 |
$value = $params->{'verification_token'}; |
333 |
} |
|
|
334 |
|
335 |
if ( ref($self) && !$value ) { |
336 |
if ( $self->{'borrowernumber'} ) { |
337 |
$field = 'borrowernumber'; |
338 |
$value = $self->{'borrowernumber'}; |
339 |
} |
340 |
elsif ( $self->{'verification_token'} ) { |
341 |
$field = 'verification_token'; |
342 |
$value = $self->{'verification_token'}; |
343 |
} |
344 |
} |
297 |
} |
345 |
|
298 |
|
346 |
return unless $value; |
299 |
return unless $value; |