|
Lines 24-49
use CGI qw ( -utf8 );
Link Here
|
| 24 |
use C4::Context; |
24 |
use C4::Context; |
| 25 |
use C4::Output; |
25 |
use C4::Output; |
| 26 |
use C4::Letters; |
26 |
use C4::Letters; |
| 27 |
use C4::Biblio qw( GetMarcFromKohaField ); |
27 |
use C4::Biblio qw( GetMarcFromKohaField ); |
| 28 |
use Koha::DateUtils qw( dt_from_string ); |
28 |
use Koha::DateUtils qw( dt_from_string ); |
| 29 |
use Koha::Suggestions; |
29 |
use Koha::Suggestions; |
| 30 |
use C4::Log qw(logaction); |
30 |
use C4::Log qw(logaction); |
| 31 |
|
31 |
|
| 32 |
use base qw(Exporter); |
32 |
use base qw(Exporter); |
| 33 |
|
33 |
|
| 34 |
our @EXPORT = qw( |
34 |
our @EXPORT = qw( |
| 35 |
ConnectSuggestionAndBiblio |
35 |
ConnectSuggestionAndBiblio |
| 36 |
DelSuggestion |
36 |
DelSuggestion |
| 37 |
GetSuggestion |
37 |
GetSuggestion |
| 38 |
GetSuggestionByStatus |
38 |
GetSuggestionByStatus |
| 39 |
GetSuggestionFromBiblionumber |
39 |
GetSuggestionFromBiblionumber |
| 40 |
GetSuggestionInfoFromBiblionumber |
40 |
GetSuggestionInfoFromBiblionumber |
| 41 |
GetSuggestionInfo |
41 |
GetSuggestionInfo |
| 42 |
ModStatus |
42 |
ModStatus |
| 43 |
ModSuggestion |
43 |
ModSuggestion |
| 44 |
DelSuggestionsOlderThan |
44 |
DelSuggestionsOlderThan |
| 45 |
GetUnprocessedSuggestions |
45 |
GetUnprocessedSuggestions |
| 46 |
MarcRecordFromNewSuggestion |
46 |
MarcRecordFromNewSuggestion |
| 47 |
); |
47 |
); |
| 48 |
|
48 |
|
| 49 |
=head1 NAME |
49 |
=head1 NAME |
|
Lines 84-91
return :
Link Here
|
| 84 |
|
84 |
|
| 85 |
sub GetSuggestion { |
85 |
sub GetSuggestion { |
| 86 |
my ($suggestionid) = @_; |
86 |
my ($suggestionid) = @_; |
| 87 |
my $dbh = C4::Context->dbh; |
87 |
my $dbh = C4::Context->dbh; |
| 88 |
my $query = q{ |
88 |
my $query = q{ |
| 89 |
SELECT * |
89 |
SELECT * |
| 90 |
FROM suggestions |
90 |
FROM suggestions |
| 91 |
WHERE suggestionid=? |
91 |
WHERE suggestionid=? |
|
Lines 248-257
Note that there is no function to modify a suggestion.
Link Here
|
| 248 |
|
248 |
|
| 249 |
sub ModSuggestion { |
249 |
sub ModSuggestion { |
| 250 |
my ($suggestion) = @_; |
250 |
my ($suggestion) = @_; |
| 251 |
return unless( $suggestion and defined($suggestion->{suggestionid}) ); |
251 |
return unless ( $suggestion and defined( $suggestion->{suggestionid} ) ); |
| 252 |
|
252 |
|
| 253 |
my $suggestion_object = Koha::Suggestions->find( $suggestion->{suggestionid} ); |
253 |
my $suggestion_object = Koha::Suggestions->find( $suggestion->{suggestionid} ); |
| 254 |
eval { # FIXME Must raise an exception instead |
254 |
eval { # FIXME Must raise an exception instead |
| 255 |
$suggestion_object->set($suggestion)->store; |
255 |
$suggestion_object->set($suggestion)->store; |
| 256 |
}; |
256 |
}; |
| 257 |
return 0 if $@; |
257 |
return 0 if $@; |
|
Lines 263-269
sub ModSuggestion {
Link Here
|
| 263 |
|
263 |
|
| 264 |
my $patron = Koha::Patrons->find( $full_suggestion->{suggestedby} ); |
264 |
my $patron = Koha::Patrons->find( $full_suggestion->{suggestedby} ); |
| 265 |
|
265 |
|
| 266 |
my $transport = (C4::Context->preference("FallbackToSMSIfNoEmail")) && ($patron->smsalertnumber) && (!$patron->email) ? 'sms' : 'email'; |
266 |
my $transport = |
|
|
267 |
( C4::Context->preference("FallbackToSMSIfNoEmail") ) |
| 268 |
&& ( $patron->smsalertnumber ) |
| 269 |
&& ( !$patron->email ) ? 'sms' : 'email'; |
| 267 |
|
270 |
|
| 268 |
if ( |
271 |
if ( |
| 269 |
my $letter = C4::Letters::GetPreparedLetter( |
272 |
my $letter = C4::Letters::GetPreparedLetter( |
|
Lines 278-300
sub ModSuggestion {
Link Here
|
| 278 |
'biblio' => $full_suggestion->{biblionumber}, |
281 |
'biblio' => $full_suggestion->{biblionumber}, |
| 279 |
}, |
282 |
}, |
| 280 |
) |
283 |
) |
| 281 |
) |
284 |
) |
| 282 |
{ |
285 |
{ |
| 283 |
C4::Letters::EnqueueLetter( |
286 |
C4::Letters::EnqueueLetter( |
| 284 |
{ |
287 |
{ |
| 285 |
letter => $letter, |
288 |
letter => $letter, |
| 286 |
borrowernumber => $full_suggestion->{suggestedby}, |
289 |
borrowernumber => $full_suggestion->{suggestedby}, |
| 287 |
suggestionid => $full_suggestion->{suggestionid}, |
290 |
suggestionid => $full_suggestion->{suggestionid}, |
| 288 |
LibraryName => C4::Context->preference("LibraryName"), |
291 |
LibraryName => C4::Context->preference("LibraryName"), |
| 289 |
message_transport_type => $transport, |
292 |
message_transport_type => $transport, |
| 290 |
} |
293 |
} |
| 291 |
) or warn "can't enqueue letter $letter"; |
294 |
) or warn "can't enqueue letter $letter"; |
| 292 |
} |
295 |
} |
| 293 |
} |
296 |
} |
| 294 |
if (C4::Context->preference("SuggestionsLog")) { |
297 |
if ( C4::Context->preference("SuggestionsLog") ) { |
| 295 |
logaction('SUGGESTION', 'MODIFY', $suggestion->{suggestionid}, $suggestion_object ); |
298 |
logaction( 'SUGGESTION', 'MODIFY', $suggestion->{suggestionid}, $suggestion_object ); |
| 296 |
} |
299 |
} |
| 297 |
return 1; # No useful if the exception is raised earlier |
300 |
return 1; # No useful if the exception is raised earlier |
| 298 |
} |
301 |
} |
| 299 |
|
302 |
|
| 300 |
=head2 ConnectSuggestionAndBiblio |
303 |
=head2 ConnectSuggestionAndBiblio |
|
Lines 338-345
sub DelSuggestion {
Link Here
|
| 338 |
my $sth = $dbh->prepare($query); |
341 |
my $sth = $dbh->prepare($query); |
| 339 |
$sth->execute($suggestionid); |
342 |
$sth->execute($suggestionid); |
| 340 |
my ($suggestedby) = $sth->fetchrow; |
343 |
my ($suggestedby) = $sth->fetchrow; |
| 341 |
$suggestedby //= ''; |
344 |
$suggestedby //= ''; |
| 342 |
$borrowernumber //= ''; |
345 |
$borrowernumber //= ''; |
|
|
346 |
|
| 343 |
if ( defined $type && $type eq 'intranet' || $suggestedby eq $borrowernumber ) { |
347 |
if ( defined $type && $type eq 'intranet' || $suggestedby eq $borrowernumber ) { |
| 344 |
my $queryDelete = q{ |
348 |
my $queryDelete = q{ |
| 345 |
DELETE FROM suggestions |
349 |
DELETE FROM suggestions |
|
Lines 347-354
sub DelSuggestion {
Link Here
|
| 347 |
}; |
351 |
}; |
| 348 |
$sth = $dbh->prepare($queryDelete); |
352 |
$sth = $dbh->prepare($queryDelete); |
| 349 |
my $suggestiondeleted = $sth->execute($suggestionid); |
353 |
my $suggestiondeleted = $sth->execute($suggestionid); |
| 350 |
if (C4::Context->preference("SuggestionsLog")) { |
354 |
if ( C4::Context->preference("SuggestionsLog") ) { |
| 351 |
logaction('SUGGESTION', 'DELETE', $suggestionid, '' ); |
355 |
logaction( 'SUGGESTION', 'DELETE', $suggestionid, '' ); |
| 352 |
} |
356 |
} |
| 353 |
return $suggestiondeleted; |
357 |
return $suggestiondeleted; |
| 354 |
} |
358 |
} |
|
Lines 377-395
sub DelSuggestionsOlderThan {
Link Here
|
| 377 |
} |
381 |
} |
| 378 |
|
382 |
|
| 379 |
sub GetUnprocessedSuggestions { |
383 |
sub GetUnprocessedSuggestions { |
| 380 |
my ( $number_of_days_since_the_last_modification ) = @_; |
384 |
my ($number_of_days_since_the_last_modification) = @_; |
| 381 |
|
385 |
|
| 382 |
$number_of_days_since_the_last_modification ||= 0; |
386 |
$number_of_days_since_the_last_modification ||= 0; |
| 383 |
|
387 |
|
| 384 |
my $dbh = C4::Context->dbh; |
388 |
my $dbh = C4::Context->dbh; |
| 385 |
|
389 |
|
| 386 |
my $s = $dbh->selectall_arrayref(q| |
390 |
my $s = $dbh->selectall_arrayref( |
|
|
391 |
q| |
| 387 |
SELECT * |
392 |
SELECT * |
| 388 |
FROM suggestions |
393 |
FROM suggestions |
| 389 |
WHERE STATUS = 'ASKED' |
394 |
WHERE STATUS = 'ASKED' |
| 390 |
AND budgetid IS NOT NULL |
395 |
AND budgetid IS NOT NULL |
| 391 |
AND CAST(NOW() AS DATE) - INTERVAL ? DAY = CAST(suggesteddate AS DATE) |
396 |
AND CAST(NOW() AS DATE) - INTERVAL ? DAY = CAST(suggesteddate AS DATE) |
| 392 |
|, { Slice => {} }, $number_of_days_since_the_last_modification ); |
397 |
|, { Slice => {} }, $number_of_days_since_the_last_modification |
|
|
398 |
); |
| 393 |
return $s; |
399 |
return $s; |
| 394 |
} |
400 |
} |
| 395 |
|
401 |
|
|
Lines 405-443
sub MarcRecordFromNewSuggestion {
Link Here
|
| 405 |
my ($suggestion) = @_; |
411 |
my ($suggestion) = @_; |
| 406 |
my $record = MARC::Record->new(); |
412 |
my $record = MARC::Record->new(); |
| 407 |
|
413 |
|
| 408 |
if (my $isbn = $suggestion->{isbn}) { |
414 |
if ( my $isbn = $suggestion->{isbn} ) { |
| 409 |
for my $field (qw(biblioitems.isbn biblioitems.issn)) { |
415 |
for my $field (qw(biblioitems.isbn biblioitems.issn)) { |
| 410 |
my ($tag, $subfield) = GetMarcFromKohaField($field); |
416 |
my ( $tag, $subfield ) = GetMarcFromKohaField($field); |
| 411 |
$record->append_fields( |
417 |
$record->append_fields( MARC::Field->new( $tag, ' ', ' ', $subfield => $isbn ) ); |
| 412 |
MARC::Field->new($tag, ' ', ' ', $subfield => $isbn) |
|
|
| 413 |
); |
| 414 |
} |
418 |
} |
| 415 |
} |
419 |
} else { |
| 416 |
else { |
420 |
my ( $title_tag, $title_subfield ) = GetMarcFromKohaField('biblio.title'); |
| 417 |
my ($title_tag, $title_subfield) = GetMarcFromKohaField('biblio.title'); |
421 |
$record->append_fields( MARC::Field->new( $title_tag, ' ', ' ', $title_subfield => $suggestion->{title} ) ); |
| 418 |
$record->append_fields( |
422 |
|
| 419 |
MARC::Field->new($title_tag, ' ', ' ', $title_subfield => $suggestion->{title}) |
423 |
my ( $author_tag, $author_subfield ) = GetMarcFromKohaField('biblio.author'); |
| 420 |
); |
424 |
if ( $record->field($author_tag) ) { |
| 421 |
|
425 |
$record->field($author_tag)->add_subfields( $author_subfield => $suggestion->{author} ); |
| 422 |
my ($author_tag, $author_subfield) = GetMarcFromKohaField('biblio.author'); |
426 |
} else { |
| 423 |
if ($record->field( $author_tag )) { |
|
|
| 424 |
$record->field( $author_tag )->add_subfields( $author_subfield => $suggestion->{author} ); |
| 425 |
} |
| 426 |
else { |
| 427 |
$record->append_fields( |
427 |
$record->append_fields( |
| 428 |
MARC::Field->new($author_tag, ' ', ' ', $author_subfield => $suggestion->{author}) |
428 |
MARC::Field->new( $author_tag, ' ', ' ', $author_subfield => $suggestion->{author} ) ); |
| 429 |
); |
|
|
| 430 |
} |
429 |
} |
| 431 |
} |
430 |
} |
| 432 |
|
431 |
|
| 433 |
my ($it_tag, $it_subfield) = GetMarcFromKohaField('biblioitems.itemtype'); |
432 |
my ( $it_tag, $it_subfield ) = GetMarcFromKohaField('biblioitems.itemtype'); |
| 434 |
if ($record->field( $it_tag )) { |
433 |
if ( $record->field($it_tag) ) { |
| 435 |
$record->field( $it_tag )->add_subfields( $it_subfield => $suggestion->{itemtype} ); |
434 |
$record->field($it_tag)->add_subfields( $it_subfield => $suggestion->{itemtype} ); |
| 436 |
} |
435 |
} else { |
| 437 |
else { |
436 |
$record->append_fields( MARC::Field->new( $it_tag, ' ', ' ', $it_subfield => $suggestion->{itemtype} ) ); |
| 438 |
$record->append_fields( |
|
|
| 439 |
MARC::Field->new($it_tag, ' ', ' ', $it_subfield => $suggestion->{itemtype}) |
| 440 |
); |
| 441 |
} |
437 |
} |
| 442 |
|
438 |
|
| 443 |
return $record; |
439 |
return $record; |
| 444 |
- |
|
|