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

(-)a/C4/Suggestions.pm (-49 lines)
Lines 26-32 BEGIN { Link Here
26
        ConnectSuggestionAndBiblio
26
        ConnectSuggestionAndBiblio
27
        DelSuggestion
27
        DelSuggestion
28
        GetSuggestion
28
        GetSuggestion
29
        GetSuggestionByStatus
30
        ModStatus
29
        ModStatus
31
        ModSuggestion
30
        ModSuggestion
32
        DelSuggestionsOlderThan
31
        DelSuggestionsOlderThan
Lines 81-134 all the suggestion with C<$status> Link Here
81
80
82
=cut
81
=cut
83
82
84
sub GetSuggestionByStatus {
85
    my $status     = shift;
86
    my $branchcode = shift;
87
    my $dbh        = C4::Context->dbh;
88
    my @sql_params = ($status);
89
    my $query      = q{
90
        SELECT suggestions.*,
91
            U1.surname          AS surnamesuggestedby,
92
            U1.firstname        AS firstnamesuggestedby,
93
            U1.branchcode       AS branchcodesuggestedby,
94
            B1.branchname       AS branchnamesuggestedby,
95
            U1.borrowernumber   AS borrnumsuggestedby,
96
            U1.categorycode     AS categorycodesuggestedby,
97
            C1.description      AS categorydescriptionsuggestedby,
98
            U2.surname          AS surnamemanagedby,
99
            U2.firstname        AS firstnamemanagedby,
100
            U2.borrowernumber   AS borrnummanagedby
101
        FROM suggestions
102
            LEFT JOIN borrowers     AS U1 ON suggestedby=U1.borrowernumber
103
            LEFT JOIN borrowers     AS U2 ON managedby=U2.borrowernumber
104
            LEFT JOIN categories    AS C1 ON C1.categorycode=U1.categorycode
105
            LEFT JOIN branches      AS B1 on B1.branchcode=U1.branchcode
106
        WHERE status = ?
107
        ORDER BY suggestionid
108
    };
109
110
    # filter on branch
111
    if ( C4::Context->preference("IndependentBranches") || $branchcode ) {
112
        my $userenv = C4::Context->userenv;
113
        if ($userenv) {
114
            unless ( C4::Context->IsSuperLibrarian() ) {
115
                push @sql_params, $userenv->{branch};
116
                $query .= q{ AND (U1.branchcode = ? OR U1.branchcode ='') };
117
            }
118
        }
119
        if ($branchcode) {
120
            push @sql_params, $branchcode;
121
            $query .= q{ AND (U1.branchcode = ? OR U1.branchcode ='') };
122
        }
123
    }
124
125
    my $sth = $dbh->prepare($query);
126
    $sth->execute(@sql_params);
127
    my $results;
128
    $results = $sth->fetchall_arrayref( {} );
129
    return $results;
130
}
131
132
=head2 ModSuggestion
83
=head2 ModSuggestion
133
84
134
&ModSuggestion($suggestion)
85
&ModSuggestion($suggestion)
(-)a/t/db_dependent/Suggestions.t (-48 / +2 lines)
Lines 19-25 use Modern::Perl; Link Here
19
19
20
use DateTime::Duration;
20
use DateTime::Duration;
21
use Test::NoWarnings;
21
use Test::NoWarnings;
22
use Test::More tests => 80;
22
use Test::More tests => 53;
23
use Test::Warn;
23
use Test::Warn;
24
24
25
use t::lib::Mocks;
25
use t::lib::Mocks;
Lines 38-44 use Koha::Suggestions; Link Here
38
BEGIN {
38
BEGIN {
39
    use_ok(
39
    use_ok(
40
        'C4::Suggestions',
40
        'C4::Suggestions',
41
        qw( ModSuggestion GetSuggestionByStatus ConnectSuggestionAndBiblio DelSuggestion MarcRecordFromNewSuggestion GetUnprocessedSuggestions DelSuggestionsOlderThan )
41
        qw( ModSuggestion ConnectSuggestionAndBiblio DelSuggestion MarcRecordFromNewSuggestion GetUnprocessedSuggestions DelSuggestionsOlderThan )
42
    );
42
    );
43
}
43
}
44
44
Lines 310-356 $messages = C4::Letters::GetQueuedMessages( { borrowernumber => $borrowernumber2 Link Here
310
310
311
is( scalar(@$messages), 1, 'No new letter should have been generated if the update raised an error' );
311
is( scalar(@$messages), 1, 'No new letter should have been generated if the update raised an error' );
312
312
313
my $suggestions = GetSuggestionByStatus();
314
is( @$suggestions, 0, 'GetSuggestionByStatus without the status returns an empty array' );
315
$suggestions = GetSuggestionByStatus('CHECKED');
316
is( @$suggestions,                     2, 'GetSuggestionByStatus returns the correct number of suggestions' );
317
is( $suggestions->[0]->{suggestionid}, $my_suggestionid, 'GetSuggestionByStatus returns the suggestion id correctly' );
318
is( $suggestions->[0]->{title},  $mod_suggestion1->{title},  'GetSuggestionByStatus returns the title correctly' );
319
is( $suggestions->[0]->{author}, $mod_suggestion1->{author}, 'GetSuggestionByStatus returns the author correctly' );
320
is(
321
    $suggestions->[0]->{publishercode}, $mod_suggestion1->{publishercode},
322
    'GetSuggestionByStatus returns the publisher code correctly'
323
);
324
is(
325
    $suggestions->[0]->{suggestedby}, $my_suggestion->{suggestedby},
326
    'GetSuggestionByStatus returns the borrower number correctly'
327
);
328
is(
329
    $suggestions->[0]->{biblionumber}, $my_suggestion->{biblionumber},
330
    'GetSuggestionByStatus returns the biblio number correctly'
331
);
332
is( $suggestions->[0]->{STATUS}, $mod_suggestion3->{STATUS}, 'GetSuggestionByStatus returns the status correctly' );
333
is(
334
    $suggestions->[0]->{surnamesuggestedby}, $member->{surname},
335
    'GetSuggestionByStatus returns the surname correctly'
336
);
337
is(
338
    $suggestions->[0]->{firstnamesuggestedby}, $member->{firstname},
339
    'GetSuggestionByStatus returns the firstname correctly'
340
);
341
is(
342
    $suggestions->[0]->{branchcodesuggestedby}, $member->{branchcode},
343
    'GetSuggestionByStatus returns the branch code correctly'
344
);
345
is(
346
    $suggestions->[0]->{borrnumsuggestedby}, $my_suggestion->{suggestedby},
347
    'GetSuggestionByStatus returns the borrower number correctly'
348
);
349
is(
350
    $suggestions->[0]->{categorycodesuggestedby}, $member->{categorycode},
351
    'GetSuggestionByStatus returns the category code correctly'
352
);
353
354
is( ConnectSuggestionAndBiblio(), '0E0', 'ConnectSuggestionAndBiblio without arguments returns 0E0' );
313
is( ConnectSuggestionAndBiblio(), '0E0', 'ConnectSuggestionAndBiblio without arguments returns 0E0' );
355
my $biblio_2                      = $builder->build_object( { class => 'Koha::Biblios' } );
314
my $biblio_2                      = $builder->build_object( { class => 'Koha::Biblios' } );
356
my $connect_suggestion_and_biblio = ConnectSuggestionAndBiblio( $my_suggestionid, $biblio_2->biblionumber );
315
my $connect_suggestion_and_biblio = ConnectSuggestionAndBiblio( $my_suggestionid, $biblio_2->biblionumber );
Lines 378-387 is( Link Here
378
$suggestion = DelSuggestion( $borrowernumber, $my_suggestionid );
337
$suggestion = DelSuggestion( $borrowernumber, $my_suggestionid );
379
is( $suggestion, 1, 'DelSuggestion deletes one suggestion' );
338
is( $suggestion, 1, 'DelSuggestion deletes one suggestion' );
380
339
381
$suggestions = GetSuggestionByStatus('CHECKED');
382
is( @$suggestions,              2,                        'DelSuggestion deletes one suggestion' );
383
is( $suggestions->[1]->{title}, $del_suggestion->{title}, 'DelSuggestion deletes the correct suggestion' );
384
385
# Test budgetid fk
340
# Test budgetid fk
386
$my_suggestion->{budgetid} = '';    # If budgetid == '', NULL should be set in DB
341
$my_suggestion->{budgetid} = '';    # If budgetid == '', NULL should be set in DB
387
my $my_suggestionid_test_budget_object = Koha::Suggestion->new($my_suggestion)->store;
342
my $my_suggestionid_test_budget_object = Koha::Suggestion->new($my_suggestion)->store;
388
- 

Return to bug 39725