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

(-)a/C4/Suggestions.pm (-60 lines)
Lines 34-40 use base qw(Exporter); Link Here
34
our @EXPORT = qw(
34
our @EXPORT = qw(
35
    ConnectSuggestionAndBiblio
35
    ConnectSuggestionAndBiblio
36
    DelSuggestion
36
    DelSuggestion
37
    GetSuggestionByStatus
38
    ModStatus
37
    ModStatus
39
    ModSuggestion
38
    ModSuggestion
40
    DelSuggestionsOlderThan
39
    DelSuggestionsOlderThan
Lines 67-131 Suggestions done by other borrowers can be seen when not "AVAILABLE" Link Here
67
66
68
=head1 FUNCTIONS
67
=head1 FUNCTIONS
69
68
70
=head2 GetSuggestionByStatus
71
72
$aqorders = &GetSuggestionByStatus($status,[$branchcode])
73
74
Get a suggestion from it's status
75
76
return :
77
all the suggestion with C<$status>
78
79
=cut
80
81
sub GetSuggestionByStatus {
82
    my $status     = shift;
83
    my $branchcode = shift;
84
    my $dbh        = C4::Context->dbh;
85
    my @sql_params = ($status);
86
    my $query      = q{
87
        SELECT suggestions.*,
88
            U1.surname          AS surnamesuggestedby,
89
            U1.firstname        AS firstnamesuggestedby,
90
            U1.branchcode       AS branchcodesuggestedby,
91
            B1.branchname       AS branchnamesuggestedby,
92
            U1.borrowernumber   AS borrnumsuggestedby,
93
            U1.categorycode     AS categorycodesuggestedby,
94
            C1.description      AS categorydescriptionsuggestedby,
95
            U2.surname          AS surnamemanagedby,
96
            U2.firstname        AS firstnamemanagedby,
97
            U2.borrowernumber   AS borrnummanagedby
98
        FROM suggestions
99
            LEFT JOIN borrowers     AS U1 ON suggestedby=U1.borrowernumber
100
            LEFT JOIN borrowers     AS U2 ON managedby=U2.borrowernumber
101
            LEFT JOIN categories    AS C1 ON C1.categorycode=U1.categorycode
102
            LEFT JOIN branches      AS B1 on B1.branchcode=U1.branchcode
103
        WHERE status = ?
104
        ORDER BY suggestionid
105
    };
106
107
    # filter on branch
108
    if ( C4::Context->preference("IndependentBranches") || $branchcode ) {
109
        my $userenv = C4::Context->userenv;
110
        if ($userenv) {
111
            unless ( C4::Context->IsSuperLibrarian() ) {
112
                push @sql_params, $userenv->{branch};
113
                $query .= q{ AND (U1.branchcode = ? OR U1.branchcode ='') };
114
            }
115
        }
116
        if ($branchcode) {
117
            push @sql_params, $branchcode;
118
            $query .= q{ AND (U1.branchcode = ? OR U1.branchcode ='') };
119
        }
120
    }
121
122
    my $sth = $dbh->prepare($query);
123
    $sth->execute(@sql_params);
124
    my $results;
125
    $results = $sth->fetchall_arrayref( {} );
126
    return $results;
127
}
128
129
=head2 ModSuggestion
69
=head2 ModSuggestion
130
70
131
&ModSuggestion($suggestion)
71
&ModSuggestion($suggestion)
(-)a/t/db_dependent/Suggestions.t (-47 / +5 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 => 69;
22
use Test::More tests => 55;
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-386 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');
340
my $suggestions = Koha::Suggestions->search( { STATUS => 'CHECKED' } )->as_list;
382
is( @$suggestions,              2,                        'DelSuggestion deletes one suggestion' );
341
is( @$suggestions,                           2,                        'DelSuggestion deletes one suggestion' );
383
is( $suggestions->[1]->{title}, $del_suggestion->{title}, 'DelSuggestion deletes the correct suggestion' );
342
is( $suggestions->[1]->unblessed()->{title}, $del_suggestion->{title}, 'DelSuggestion deletes the correct suggestion' );
384
343
385
# Test budgetid fk
344
# Test budgetid fk
386
$my_suggestion->{budgetid} = '';    # If budgetid == '', NULL should be set in DB
345
$my_suggestion->{budgetid} = '';    # If budgetid == '', NULL should be set in DB
387
- 

Return to bug 39725