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

(-)a/C4/Members.pm (-1 / +1 lines)
Lines 586-592 sub IssueSlip { Link Here
586
            };
586
            };
587
        }
587
        }
588
        my $news = Koha::News->search_for_display({
588
        my $news = Koha::News->search_for_display({
589
                type => 'slip',
589
                location => 'slip',
590
                library_id => $branch,
590
                library_id => $branch,
591
            });
591
            });
592
        my @news;
592
        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 235-256 subtest '->search_for_display' => sub { Link Here
235
    is($news->count, 4, 'Active and not expired news');
235
    is($news->count, 4, 'Active and not expired news');
236
    is($news->next->number, 2, 'News items are returned in correct order');
236
    is($news->next->number, 2, 'News items are returned in correct order');
237
237
238
    $news = Koha::News->search_for_display({ type => 'slip'});
238
    $news = Koha::News->search_for_display({ location => 'slip'});
239
    is($news->count, 2, 'Slip and all type returned');
239
    is($news->count, 2, 'Slip and "all" locations returned');
240
240
241
    $news = Koha::News->search_for_display({ type => 'koha'});
241
    $news = Koha::News->search_for_display({ location => 'koha'});
242
    is($news->count, 3, 'Intranet and all');
242
    is($news->count, 3, 'Intranet and "all"');
243
243
244
    $new_not_expired->lang('OpacNavRight_en')->store;
244
    $new_not_expired->lang('OpacNavRight_en')->store;
245
    $news = Koha::News->search_for_display({ type => 'OpacNavRight', lang => 'en'});
245
    $news = Koha::News->search_for_display({ location => 'OpacNavRight', lang => 'en'});
246
    is($news->count, 1, 'OpacNavRight');
246
    is($news->count, 1, 'OpacNavRight');
247
    is($news->next->idnew, $new_not_expired->idnew, 'Returned the right new item');
247
    is($news->next->idnew, $new_not_expired->idnew, 'Returned the right new item');
248
248
249
    $new_intra->lang('')->store;
249
    $new_intra->lang('')->store;
250
    $news = Koha::News->search_for_display({ type => 'opac', lang => 'en'});
250
    $news = Koha::News->search_for_display({ location => 'opac', lang => 'en'});
251
    is($news->count, 1, 'Only all type is returned');
251
    is($news->count, 1, 'Only opac news are returned');
252
    $new_not_expired->lang('en')->store;
252
    $new_not_expired->lang('en')->store;
253
    $news = Koha::News->search_for_display({ type => 'opac', lang => 'en'});
253
    $news = Koha::News->search_for_display({ location => 'opac', lang => 'en'});
254
    is($news->count, 2, 'Opac en and all is returned');
254
    is($news->count, 2, 'Opac en and all is returned');
255
255
256
    $news = Koha::News->search_for_display({ library_id => $library1->branchcode });
256
    $news = Koha::News->search_for_display({ library_id => $library1->branchcode });
Lines 263-273 subtest '->search_for_display' => sub { Link Here
263
    $news = Koha::News->search_for_display({ library_id => $library2->branchcode});
263
    $news = Koha::News->search_for_display({ library_id => $library2->branchcode});
264
    is($news->count, 2, 'Filtering by library returns right number of news items');
264
    is($news->count, 2, 'Filtering by library returns right number of news items');
265
265
266
    $news = Koha::News->search_for_display({ type => 'NonExistantType', lang => 'en'});
266
    $news = Koha::News->search_for_display({ location => 'NonExistantType', lang => 'en'});
267
    is($news->count, 0, 'Non-existant type is searched, but should not find any item');
267
    is($news->count, 0, 'Non-existant location is searched, but should not find any item');
268
268
269
    throws_ok { Koha::News->search_for_display({type => 'opac'}) } 'Koha::Exceptions::BadParameter',
269
    throws_ok { Koha::News->search_for_display({ location => 'opac'}) } 'Koha::Exceptions::BadParameter',
270
        'Exception raised when type is opac and no language given';
270
        'Exception raised when location is opac and no language given';
271
271
272
    $schema->storage->txn_rollback;
272
    $schema->storage->txn_rollback;
273
};
273
};
274
- 

Return to bug 22544