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

(-)a/C4/Members.pm (-1 / +1 lines)
Lines 589-595 sub IssueSlip { Link Here
589
            };
589
            };
590
        }
590
        }
591
        my $news = Koha::News->search_for_display({
591
        my $news = Koha::News->search_for_display({
592
                type => 'slip',
592
                location => 'slip',
593
                library_id => $branch,
593
                library_id => $branch,
594
            });
594
            });
595
        my @news;
595
        my @news;
(-)a/Koha/News.pm (-9 / +9 lines)
Lines 40-53 Koha::News - Koha News object set class Link Here
40
=head3 search_for_display
40
=head3 search_for_display
41
41
42
my $news = Koha::News->search_for_display({
42
my $news = Koha::News->search_for_display({
43
    type => 'slip',
43
    location => 'slip',
44
    lang => 'en',
44
    lang => 'en',
45
    library_id => $branchcode
45
    library_id => $branchcode
46
})
46
})
47
47
48
Return Koha::News set for display to user
48
Return Koha::News set for display to user
49
49
50
You can limit the results by type(lang) and library by optional params
50
You can limit the results by location, language and library by optional params
51
51
52
library_id should be valid branchcode of defined library
52
library_id should be valid branchcode of defined library
53
53
Lines 62-68 type is one of this: Link Here
62
- opacheader
62
- opacheader
63
- opaccredits
63
- opaccredits
64
64
65
lang is language code - it is used only when type is opac or OpacNavRight
65
lang is language code - it is used only when type is opac or any of OPAC locations
66
66
67
=cut
67
=cut
68
68
Lines 70-84 sub search_for_display { Link Here
70
    my ( $self, $params ) = @_;
70
    my ( $self, $params ) = @_;
71
71
72
    my $search_params;
72
    my $search_params;
73
    if ($params->{type} ) {
73
    if ($params->{location} ) {
74
        if ( $params->{type} eq 'slip' || $params->{type} eq 'koha') {
74
        if ( $params->{location} eq 'slip' || $params->{location} eq 'koha') {
75
            $search_params->{lang} = [ $params->{type}, '' ];
75
            $search_params->{lang} = [ $params->{location}, '' ];
76
        } elsif ( $params->{type} eq 'opac' && $params->{lang} ) {
76
        } elsif ( $params->{location} eq 'opac' && $params->{lang} ) {
77
            $search_params->{lang} = [ $params->{lang}, '' ];
77
            $search_params->{lang} = [ $params->{lang}, '' ];
78
        } elsif ( $params->{lang} ) {
78
        } elsif ( $params->{lang} ) {
79
            $search_params->{lang} = $params->{type} . '_' . $params->{lang};
79
            $search_params->{lang} = $params->{location} . '_' . $params->{lang};
80
        } else {
80
        } else {
81
            Koha::Exceptions::BadParameter->throw("The type and lang parameters combination is not valid");
81
            Koha::Exceptions::BadParameter->throw("The location and lang parameters combination is not valid");
82
        }
82
        }
83
    }
83
    }
84
84
(-)a/Koha/Template/Plugin/KohaNews.pm (-1 / +1 lines)
Lines 37-43 sub get { Link Here
37
    my $library = $params->{library};
37
    my $library = $params->{library};
38
38
39
    my $content = Koha::News->search_for_display({
39
    my $content = Koha::News->search_for_display({
40
            type => $display_location,
40
            location => $display_location,
41
            lang => $lang,
41
            lang => $lang,
42
            library_id => $library,
42
            library_id => $library,
43
    });
43
    });
(-)a/mainpage.pl (-1 / +1 lines)
Lines 50-56 if (C4::Context->userenv) { Link Here
50
    $homebranch = C4::Context->userenv->{'branch'};
50
    $homebranch = C4::Context->userenv->{'branch'};
51
}
51
}
52
my $koha_news = Koha::News->search_for_display({
52
my $koha_news = Koha::News->search_for_display({
53
        type => 'koha',
53
        location => 'koha',
54
        library_id => $homebranch
54
        library_id => $homebranch
55
    });
55
    });
56
56
(-)a/opac/opac-main.pl (-1 / +1 lines)
Lines 71-77 if (defined $news_id){ Link Here
71
    }
71
    }
72
} else {
72
} else {
73
    $koha_news = Koha::News->search_for_display({
73
    $koha_news = Koha::News->search_for_display({
74
            type => 'opac',
74
            location => 'opac',
75
            lang => $template->lang,
75
            lang => $template->lang,
76
            library_id => $homebranch,
76
            library_id => $homebranch,
77
        });
77
        });
(-)a/opac/opac-news-rss.pl (-1 / +1 lines)
Lines 44-50 my ($theme, $news_lang, $availablethemes) = C4::Templates::themelanguage(C4::Con Link Here
44
my $branchcode = $input->param('branchcode');
44
my $branchcode = $input->param('branchcode');
45
45
46
my $koha_news = Koha::News->search_for_display({
46
my $koha_news = Koha::News->search_for_display({
47
        type => 'opac',
47
        location => 'opac',
48
        lang => $news_lang,
48
        lang => $news_lang,
49
        library_id => $branchcode,
49
        library_id => $branchcode,
50
    });
50
    });
(-)a/t/db_dependent/Koha/News.t (-13 / +12 lines)
Lines 220-241 subtest '->search_for_display' => sub { Link Here
220
    is($news->count, 4, 'Active and not expired news');
220
    is($news->count, 4, 'Active and not expired news');
221
    is($news->next->number, 2, 'News items are returned in correct order');
221
    is($news->next->number, 2, 'News items are returned in correct order');
222
222
223
    $news = Koha::News->search_for_display({ type => 'slip'});
223
    $news = Koha::News->search_for_display({ location => 'slip'});
224
    is($news->count, 2, 'Slip and all type returned');
224
    is($news->count, 2, 'Slip and "all" locations returned');
225
225
226
    $news = Koha::News->search_for_display({ type => 'koha'});
226
    $news = Koha::News->search_for_display({ location => 'koha'});
227
    is($news->count, 3, 'Intranet and all');
227
    is($news->count, 3, 'Intranet and "all"');
228
228
229
    $new_not_expired->lang('OpacNavRight_en')->store;
229
    $new_not_expired->lang('OpacNavRight_en')->store;
230
    $news = Koha::News->search_for_display({ type => 'OpacNavRight', lang => 'en'});
230
    $news = Koha::News->search_for_display({ location => 'OpacNavRight', lang => 'en'});
231
    is($news->count, 1, 'OpacNavRight');
231
    is($news->count, 1, 'OpacNavRight');
232
    is($news->next->idnew, $new_not_expired->idnew, 'Returned the right new item');
232
    is($news->next->idnew, $new_not_expired->idnew, 'Returned the right new item');
233
233
234
    $new_intra->lang('')->store;
234
    $new_intra->lang('')->store;
235
    $news = Koha::News->search_for_display({ type => 'opac', lang => 'en'});
235
    $news = Koha::News->search_for_display({ location => 'opac', lang => 'en'});
236
    is($news->count, 1, 'Only all type is returned');
236
    is($news->count, 1, 'Only opac news are returned');
237
    $new_not_expired->lang('en')->store;
237
    $new_not_expired->lang('en')->store;
238
    $news = Koha::News->search_for_display({ type => 'opac', lang => 'en'});
238
    $news = Koha::News->search_for_display({ location => 'opac', lang => 'en'});
239
    is($news->count, 2, 'Opac en and all is returned');
239
    is($news->count, 2, 'Opac en and all is returned');
240
240
241
    $news = Koha::News->search_for_display({ library_id => $library1->branchcode });
241
    $news = Koha::News->search_for_display({ library_id => $library1->branchcode });
Lines 248-258 subtest '->search_for_display' => sub { Link Here
248
    $news = Koha::News->search_for_display({ library_id => $library2->branchcode});
248
    $news = Koha::News->search_for_display({ library_id => $library2->branchcode});
249
    is($news->count, 2, 'Filtering by library returns right number of news items');
249
    is($news->count, 2, 'Filtering by library returns right number of news items');
250
250
251
    $news = Koha::News->search_for_display({ type => 'NonExistantType', lang => 'en'});
251
    $news = Koha::News->search_for_display({ location => 'NonExistantType', lang => 'en'});
252
    is($news->count, 0, 'Non-existant type is searched, but should not find any item');
252
    is($news->count, 0, 'Non-existant location is searched, but should not find any item');
253
253
254
    throws_ok { Koha::News->search_for_display({type => 'opac'}) } 'Koha::Exceptions::BadParameter',
254
    throws_ok { Koha::News->search_for_display({ location => 'opac'}) } 'Koha::Exceptions::BadParameter',
255
        'Exception raised when type is opac and no language given';
255
        'Exception raised when location is opac and no language given';
256
256
257
    $schema->storage->txn_rollback;
257
    $schema->storage->txn_rollback;
258
};
258
};
259
- 

Return to bug 22544