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

(-)a/C4/Members.pm (-9 / +4 lines)
Lines 588-602 sub IssueSlip { Link Here
588
                issues      => $all,
588
                issues      => $all,
589
            };
589
            };
590
        }
590
        }
591
        my $news = Koha::News->search({
591
        my $news = Koha::News->search_for_display({
592
                lang => [ 'slip', '' ],
592
                type => 'slip',
593
                branchcode => [ $branch, undef ],
593
                library_id => $branch,
594
                -or => [ expirationdate => { '>=' => \'NOW()' },
594
            });
595
                         expirationdate => undef ]
596
            },{
597
                order_by => 'number'
598
            }
599
        );
600
        my @news;
595
        my @news;
601
        while ( my $n = $news->next ) {
596
        while ( my $n = $news->next ) {
602
            my $all = $n->unblessed_all_relateds;
597
            my $all = $n->unblessed_all_relateds;
(-)a/Koha/News.pm (-1 / +49 lines)
Lines 22-28 use Modern::Perl; Link Here
22
use Carp;
22
use Carp;
23
23
24
use Koha::Database;
24
use Koha::Database;
25
25
use Koha::Exceptions;
26
use Koha::NewsItem;
26
use Koha::NewsItem;
27
27
28
use base qw(Koha::Objects);
28
use base qw(Koha::Objects);
Lines 37-42 Koha::News - Koha News object set class Link Here
37
37
38
=cut
38
=cut
39
39
40
=head3 search_for_display
41
42
my $news = Koha::News->search_for_display({
43
    type => 'slip',
44
    lang => 'en',
45
    library_id => $branchcode
46
})
47
48
Return Koha::News set for display to user
49
50
You can limit the results by type(lang) and library by optional params
51
52
library_id should be valid branchcode of defined library
53
54
type is one of this:
55
- slip - for ISSUESLIP notice
56
- koha - for intranet
57
- opac - for online catalogue
58
- OpanNavRight - Right column in the online catalogue
59
60
lang is language code - it is used only when type is opac or OpacNavRight
61
62
=cut
63
64
sub search_for_display {
65
    my ( $self, $params ) = @_;
66
67
    my $search_params;
68
    if ($params->{type} ) {
69
        if ( $params->{type} eq 'slip' || $params->{type} eq 'koha') {
70
            $search_params->{lang} = [ $params->{type}, '' ];
71
        } elsif ( $params->{type} eq 'opac' && $params->{lang} ) {
72
            $search_params->{lang} = [ $params->{lang}, '' ];
73
        } elsif ( $params->{type} eq 'OpacNavRight' && $params->{lang} ) {
74
            $search_params->{lang} = $params->{type} . '_' . $params->{lang};
75
        } else {
76
            Koha::Exceptions::BadParameter->throw("The type and lang parameters combination is not valid");
77
        }
78
    }
79
80
    $search_params->{branchcode} = [ $params->{library_id}, undef ] if $params->{library_id};
81
    $search_params->{timestamp} = { '<=' => \'NOW()' };
82
    $search_params->{-or} = [ expirationdate => { '>=' => \'NOW()' },
83
                              expirationdate => undef ];
84
85
    return $self->SUPER::search($search_params, { order_by => 'number' });
86
}
87
40
=head3 type
88
=head3 type
41
89
42
=cut
90
=cut
(-)a/Koha/Template/Plugin/KohaNews.pm (-18 / +7 lines)
Lines 35-60 sub get { Link Here
35
    my $blocktitle = $params->{blocktitle};
35
    my $blocktitle = $params->{blocktitle};
36
    my $lang = $params->{lang};
36
    my $lang = $params->{lang};
37
    my $library = $params->{library};
37
    my $library = $params->{library};
38
    my $news_lang;
39
38
40
    if( !$display_location ){
39
    my $content = Koha::News->search_for_display({
41
        $news_lang = $lang;
40
            type => $display_location,
42
    } else {
41
            lang => $lang,
43
        $news_lang = $display_location."_".$lang;
42
            library_id => $library,
44
    }
43
    });
44
45
45
46
    my $search_params;
46
    if( $content ){
47
    $search_params->{lang} = $news_lang;
48
    $search_params->{branchcode} = [ $library, undef ] if $library;
49
    $search_params->{-or} = [ expirationdate => { '>=' => \'NOW()' },
50
                              expirationdate => undef ];
51
    my $content = Koha::News->search(
52
        $search_params,
53
        {
54
            order_by => 'number'
55
        });
56
57
    if( @$content ){
58
        return {
47
        return {
59
            content => $content,
48
            content => $content,
60
            location => $display_location,
49
            location => $display_location,
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/intranet-main.tt (-3 / +1 lines)
Lines 27-35 Link Here
27
                [% IF ( koha_news.count ) %]
27
                [% IF ( koha_news.count ) %]
28
                    <div id="area-news">
28
                    <div id="area-news">
29
                        <h3><span class="news_title">News</span></h3>
29
                        <h3><span class="news_title">News</span></h3>
30
                        [% SET show_author =
30
                        [% SET show_author = Koha.Preference('NewsAuthorDisplay') == 'staff' || Koha.Preference('NewsAuthorDisplay') == 'both' %]
31
                            Koha.Preference('NewsAuthorDisplay') == 'staff'
32
                            || Koha.Preference('NewsAuthorDisplay') == 'both' %]
33
                        [% FOREACH koha_new IN koha_news %]
31
                        [% FOREACH koha_new IN koha_news %]
34
                            <div class="newsitem" id="news[% koha_new.idnew | html %]"><h4>[% koha_new.title | html %]</h4>
32
                            <div class="newsitem" id="news[% koha_new.idnew | html %]"><h4>[% koha_new.title | html %]</h4>
35
                                <div class="newsbody">[% koha_new.content | $raw %]</div>
33
                                <div class="newsbody">[% koha_new.content | $raw %]</div>
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-main.tt (-3 / +1 lines)
Lines 96-104 Link Here
96
            [% ELSE %]
96
            [% ELSE %]
97
97
98
                <div id="news" class="newscontainer">
98
                <div id="news" class="newscontainer">
99
                    [% SET show_author =
99
                    [% SET show_author = Koha.Preference('NewsAuthorDisplay') == 'opac' || Koha.Preference('NewsAuthorDisplay') == 'both' %]
100
                        Koha.Preference('NewsAuthorDisplay') == 'opac'
101
                        || Koha.Preference('NewsAuthorDisplay') == 'both' %]
102
                    [% FOREACH koha_new IN koha_news %]
100
                    [% FOREACH koha_new IN koha_news %]
103
                        <div class="newsitem">
101
                        <div class="newsitem">
104
                            <h4 class="newsheader">
102
                            <h4 class="newsheader">
(-)a/mainpage.pl (-7 / +4 lines)
Lines 49-61 my $homebranch; Link Here
49
if (C4::Context->userenv) {
49
if (C4::Context->userenv) {
50
    $homebranch = C4::Context->userenv->{'branch'};
50
    $homebranch = C4::Context->userenv->{'branch'};
51
}
51
}
52
my $koha_news = Koha::News->search({
52
my $koha_news = Koha::News->search_for_display({
53
    lang => 'koha',
53
        type => 'koha',
54
    branchcode => [ $homebranch, undef ]
54
        library_id => $homebranch
55
},
55
    });
56
{
57
    order_by => 'number'
58
});
59
56
60
$template->param(
57
$template->param(
61
    koha_news   => $koha_news,
58
    koha_news   => $koha_news,
(-)a/opac/opac-main.pl (-9 / +4 lines)
Lines 70-84 if (defined $news_id){ Link Here
70
        $template->param( single_news_error => 1 );
70
        $template->param( single_news_error => 1 );
71
    }
71
    }
72
} else {
72
} else {
73
    my $params;
73
    $koha_news = Koha::News->search_for_display({
74
    $params->{lang} = [ $template->lang, '' ];
74
            type => 'opac',
75
    $params->{branchcode} = [ $homebranch, undef ] if $homebranch;
75
            lang => $template->lang,
76
    $params->{-or} = [ expirationdate => { '>=' => \'NOW()' },
76
            library_id => $homebranch,
77
                       expirationdate => undef ];
78
    $koha_news = Koha::News->search(
79
        $params,
80
        {
81
            order_by => 'number'
82
        });
77
        });
83
}
78
}
84
79
(-)a/opac/opac-news-rss.pl (-10 / +4 lines)
Lines 43-57 my ($theme, $news_lang, $availablethemes) = C4::Templates::themelanguage(C4::Con Link Here
43
43
44
my $branchcode = $input->param('branchcode');
44
my $branchcode = $input->param('branchcode');
45
45
46
my $params;
46
my $koha_news = Koha::News->search_for_display({
47
$params->{lang} = [ $news_lang, '' ];
47
        type => 'opac',
48
$params->{branchcode} = [ $branchcode, undef ] if $branchcode;
48
        lang => $news_lang,
49
$params->{-or} = [ expirationdate => { '>=' => \'NOW()' },
49
        library_id => $branchcode,
50
                   expirationdate => undef ];
51
my $koha_news = Koha::News->search(
52
    $params,
53
    {
54
        order_by => 'number'
55
    });
50
    });
56
51
57
$template->param( koha_news => $koha_news );
52
$template->param( koha_news => $koha_news );
58
- 

Return to bug 22544