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

(-)a/C4/Suggestions.pm (-56 lines)
Lines 34-40 use base qw(Exporter); Link Here
34
34
35
our @EXPORT  = qw(
35
our @EXPORT  = qw(
36
  ConnectSuggestionAndBiblio
36
  ConnectSuggestionAndBiblio
37
  CountSuggestion
38
  DelSuggestion
37
  DelSuggestion
39
  GetSuggestion
38
  GetSuggestion
40
  GetSuggestionByStatus
39
  GetSuggestionByStatus
Lines 381-441 sub GetSuggestionByStatus { Link Here
381
    return $results;
380
    return $results;
382
}
381
}
383
382
384
=head2 CountSuggestion
385
386
&CountSuggestion($status)
387
388
Count the number of aqorders with the status given on input argument.
389
the arg status can be :
390
391
=over 2
392
393
=item * ASKED : asked by the user, not dealed by the librarian
394
395
=item * ACCEPTED : accepted by the librarian, but not yet ordered
396
397
=item * REJECTED : rejected by the librarian (definitive status)
398
399
=item * ORDERED : ordered by the librarian (acquisition module)
400
401
=back
402
403
return :
404
the number of suggestion with this status.
405
406
=cut
407
408
sub CountSuggestion {
409
    my ($status) = @_;
410
    my $dbh = C4::Context->dbh;
411
    my $sth;
412
    my $userenv = C4::Context->userenv;
413
    if ( C4::Context->preference("IndependentBranches")
414
        && !C4::Context->IsSuperLibrarian() )
415
    {
416
        my $query = q{
417
            SELECT count(*)
418
            FROM suggestions
419
                LEFT JOIN borrowers ON borrowers.borrowernumber=suggestions.suggestedby
420
            WHERE STATUS=?
421
                AND (suggestions.branchcode='' OR suggestions.branchcode=?)
422
        };
423
        $sth = $dbh->prepare($query);
424
        $sth->execute( $status, $userenv->{branch} );
425
    }
426
    else {
427
        my $query = q{
428
            SELECT count(*)
429
            FROM suggestions
430
            WHERE STATUS=?
431
        };
432
        $sth = $dbh->prepare($query);
433
        $sth->execute($status);
434
    }
435
    my ($result) = $sth->fetchrow;
436
    return $result;
437
}
438
439
=head2 NewSuggestion
383
=head2 NewSuggestion
440
384
441
385
(-)a/t/db_dependent/Suggestions.t (-13 lines)
Lines 146-157 my $my_suggestion_with_budget2 = { Link Here
146
    budgetid      => $budget_id,
146
    budgetid      => $budget_id,
147
};
147
};
148
148
149
is( CountSuggestion(), 0, 'CountSuggestion without the status returns 0' );
150
is( CountSuggestion('ASKED'), 0, 'CountSuggestion returns the correct number of suggestions' );
151
is( CountSuggestion('CHECKED'), 0, 'CountSuggestion returns the correct number of suggestions' );
152
is( CountSuggestion('ACCEPTED'), 0, 'CountSuggestion returns the correct number of suggestions' );
153
is( CountSuggestion('REJECTED'), 0, 'CountSuggestion returns the correct number of suggestions' );
154
155
my $my_suggestionid = NewSuggestion($my_suggestion);
149
my $my_suggestionid = NewSuggestion($my_suggestion);
156
isnt( $my_suggestionid, 0, 'NewSuggestion returns an not null id' );
150
isnt( $my_suggestionid, 0, 'NewSuggestion returns an not null id' );
157
my $my_suggestionid_with_budget = NewSuggestion($my_suggestion_with_budget);
151
my $my_suggestionid_with_budget = NewSuggestion($my_suggestion_with_budget);
Lines 168-176 is( $suggestion->{managedby}, undef, 'NewSuggestion stores empty string as undef Link Here
168
is( $suggestion->{manageddate}, undef, 'NewSuggestion stores empty string as undef for date' );
162
is( $suggestion->{manageddate}, undef, 'NewSuggestion stores empty string as undef for date' );
169
is( $suggestion->{budgetid}, undef, 'NewSuggestion should set budgetid to NULL if not given' );
163
is( $suggestion->{budgetid}, undef, 'NewSuggestion should set budgetid to NULL if not given' );
170
164
171
is( CountSuggestion('ASKED'), 2, 'CountSuggestion returns the correct number of suggestions' );
172
173
174
is( ModSuggestion(), undef, 'ModSuggestion without the suggestion returns undef' );
165
is( ModSuggestion(), undef, 'ModSuggestion without the suggestion returns undef' );
175
my $mod_suggestion1 = {
166
my $mod_suggestion1 = {
176
    title         => 'my modified title',
167
    title         => 'my modified title',
Lines 226-232 $messages = C4::Letters::GetQueuedMessages({ Link Here
226
});
217
});
227
is( @$messages, 1, 'ModSuggestion sends an email if the status is updated' );
218
is( @$messages, 1, 'ModSuggestion sends an email if the status is updated' );
228
is ($messages->[0]->{message_transport_type}, 'email', 'When FallbackToSMSIfNoEmail syspref is disabled the suggestion message_transport_type is always email');
219
is ($messages->[0]->{message_transport_type}, 'email', 'When FallbackToSMSIfNoEmail syspref is disabled the suggestion message_transport_type is always email');
229
is( CountSuggestion('CHECKED'), 1, 'CountSuggestion returns the correct number of suggestions' );
230
220
231
#Check the message_transport_type when the 'FallbackToSMSIfNoEmail' syspref is enabled and the borrower has a smsalertnumber and no email
221
#Check the message_transport_type when the 'FallbackToSMSIfNoEmail' syspref is enabled and the borrower has a smsalertnumber and no email
232
t::lib::Mocks::mock_preference( 'FallbackToSMSIfNoEmail', 1 );
222
t::lib::Mocks::mock_preference( 'FallbackToSMSIfNoEmail', 1 );
Lines 400-407 my $del_suggestion = { Link Here
400
};
390
};
401
my $del_suggestionid = NewSuggestion($del_suggestion);
391
my $del_suggestionid = NewSuggestion($del_suggestion);
402
392
403
is( CountSuggestion('CHECKED'), 3, 'CountSuggestion returns the correct number of suggestions' );
404
405
is( DelSuggestion(), '0E0', 'DelSuggestion without arguments returns 0E0' );
393
is( DelSuggestion(), '0E0', 'DelSuggestion without arguments returns 0E0' );
406
is( DelSuggestion($borrowernumber), '', 'DelSuggestion without the suggestion id returns an empty string' );
394
is( DelSuggestion($borrowernumber), '', 'DelSuggestion without the suggestion id returns an empty string' );
407
is( DelSuggestion(undef, $my_suggestionid), '', 'DelSuggestion with an invalid borrower number returns an empty string' );
395
is( DelSuggestion(undef, $my_suggestionid), '', 'DelSuggestion with an invalid borrower number returns an empty string' );
408
- 

Return to bug 25033