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

(-)a/C4/Members.pm (-9 / +4 lines)
Lines 580-594 sub IssueSlip { Link Here
580
                issues      => $all,
580
                issues      => $all,
581
            };
581
            };
582
        }
582
        }
583
        my $news = Koha::News->search({
583
        my $news = Koha::News->search_for_display({
584
                lang => [ 'slip', '' ],
584
                type => 'slip',
585
                branchcode => [ $branch, undef ],
585
                library_id => $branch,
586
                -or => [ expirationdate => { '>=' => \'NOW()' },
586
            });
587
                         expirationdate => undef ]
588
            },{
589
                order_by => 'number'
590
            }
591
        );
592
        my @news;
587
        my @news;
593
        while ( my $n = $news->next ) {
588
        while ( my $n = $news->next ) {
594
            my $all = $n->unblessed_all_relateds;
589
            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 / +6 lines)
Lines 34-57 sub get { Link Here
34
    my $display_location = $params->{location};
34
    my $display_location = $params->{location};
35
    my $lang = $params->{lang};
35
    my $lang = $params->{lang};
36
    my $library = $params->{library};
36
    my $library = $params->{library};
37
    my $news_lang;
37
38
38
    my $content = Koha::News->search_for_display({
39
    if( !$display_location ){
39
            type => $display_location,
40
        $news_lang = $lang;
40
            lang => $lang,
41
    } else {
41
            library_id => $library,
42
        $news_lang = $display_location."_".$lang;
42
       });
43
    }
44
45
    my $search_params;
46
    $search_params->{lang} = $news_lang;
47
    $search_params->{branchcode} = [ $library, undef ] if $library;
48
    $search_params->{-or} = [ expirationdate => { '>=' => \'NOW()' },
49
                              expirationdate => undef ];
50
    my $content = Koha::News->search(
51
        $search_params,
52
        {
53
            order_by => 'number'
54
        });
55
    return $content;
43
    return $content;
56
}
44
}
57
45
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/intranet-main.tt (-3 / +1 lines)
Lines 20-28 Link Here
20
                [% IF ( koha_news.count ) %]
20
                [% IF ( koha_news.count ) %]
21
                    <div id="area-news">
21
                    <div id="area-news">
22
                        <h3><span class="news_title">News</span></h3>
22
                        <h3><span class="news_title">News</span></h3>
23
                        [% SET show_author =
23
                        [% SET show_author = Koha.Preference('NewsAuthorDisplay') == 'staff' || Koha.Preference('NewsAuthorDisplay') == 'both' %]
24
                            Koha.Preference('NewsAuthorDisplay') == 'staff'
25
                            || Koha.Preference('NewsAuthorDisplay') == 'both' %]
26
                        [% FOREACH koha_new IN koha_news %]
24
                        [% FOREACH koha_new IN koha_news %]
27
                            <div class="newsitem" id="news[% koha_new.idnew | html %]"><h4>[% koha_new.title | html %]</h4>
25
                            <div class="newsitem" id="news[% koha_new.idnew | html %]"><h4>[% koha_new.title | html %]</h4>
28
                                <div class="newsbody">[% koha_new.content | $raw %]</div>
26
                                <div class="newsbody">[% koha_new.content | $raw %]</div>
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-main.tt (-3 / +1 lines)
Lines 80-88 Link Here
80
            [% ELSE %]
80
            [% ELSE %]
81
81
82
                <div id="news" class="newscontainer">
82
                <div id="news" class="newscontainer">
83
                    [% SET show_author =
83
                    [% SET show_author = Koha.Preference('NewsAuthorDisplay') == 'opac' || Koha.Preference('NewsAuthorDisplay') == 'both' %]
84
                        Koha.Preference('NewsAuthorDisplay') == 'opac'
85
                        || Koha.Preference('NewsAuthorDisplay') == 'both' %]
86
                    [% FOREACH koha_new IN koha_news %]
84
                    [% FOREACH koha_new IN koha_news %]
87
                        <div class="newsitem">
85
                        <div class="newsitem">
88
                            <h4 class="newsheader">
86
                            <h4 class="newsheader">
(-)a/mainpage.pl (-7 / +4 lines)
Lines 48-60 my $homebranch; Link Here
48
if (C4::Context->userenv) {
48
if (C4::Context->userenv) {
49
    $homebranch = C4::Context->userenv->{'branch'};
49
    $homebranch = C4::Context->userenv->{'branch'};
50
}
50
}
51
my $koha_news = Koha::News->search({
51
my $koha_news = Koha::News->search_for_display({
52
    lang => 'koha',
52
        type => 'koha',
53
    branchcode => [ $homebranch, undef ]
53
        library_id => $homebranch
54
},
54
    });
55
{
56
    order_by => 'number'
57
});
58
55
59
$template->param( koha_news => $koha_news );
56
$template->param( koha_news => $koha_news );
60
57
(-)a/opac/opac-main.pl (-9 / +4 lines)
Lines 73-87 if (defined $news_id){ Link Here
73
        $template->param( single_news_error => 1 );
73
        $template->param( single_news_error => 1 );
74
    }
74
    }
75
} else {
75
} else {
76
    my $params;
76
    $koha_news = Koha::News->search_for_display({
77
    $params->{lang} = [ $news_lang, '' ];
77
            type => 'opac',
78
    $params->{branchcode} = [ $homebranch, undef ] if $homebranch;
78
            lang => $news_lang,
79
    $params->{-or} = [ expirationdate => { '>=' => \'NOW()' },
79
            library_id => $homebranch,
80
                       expirationdate => undef ];
81
    $koha_news = Koha::News->search(
82
        $params,
83
        {
84
            order_by => 'number'
85
        });
80
        });
86
}
81
}
87
82
(-)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