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

(-)a/Koha/Template/Plugin/AdditionalContents.pm (-2 / +36 lines)
Lines 55-60 sub get { Link Here
55
    }
55
    }
56
}
56
}
57
57
58
sub get_opac_news_by_id {
59
    my ( $self, $params ) = @_;
60
61
    my $news_id   = $params->{news_id};
62
63
    my $content = Koha::AdditionalContents->search(
64
        {
65
            location   => ['opac_only', 'staff_and_opac'],
66
            idnew => $news_id,
67
            category => 'news',
68
        }
69
    );
70
71
    if ( $content->count ) {
72
        return {
73
            content    => $content,
74
        };
75
    }
76
}
77
58
1;
78
1;
59
79
60
=head1 NAME
80
=head1 NAME
Lines 71-78 Koha::Template::Plugin::AdditionalContents - TT Plugin for displaying additional Link Here
71
91
72
=head2 get
92
=head2 get
73
93
74
In a template, you can get the all categories with
94
In a template, you can get the news categories with
75
the following TT code: [% AdditionalContents.get() %]
95
the following TT code: [% AdditionalContents.get( category => 'news', location => ['opac_only', 'staff_and_opac'], lang => lang, library => branchcode ) %]
96
97
The function returns a hashref with keys:
98
 contents: a Koha::AdditionalContents object
99
 location: the passed in location param returned
100
 blocktitle: the passed in blocktitle param returned
101
102
=head2 get_opac_news_by_id
103
104
In a template, you can get a specific news item by passing
105
the news id. E.g.:
106
107
[% SET news_item = AdditionalContents.get_news_by_id( news_id => news_id ) %]
108
109
The function returns a hashref with a Koha::AdditionalContents object in the 'contents' key
76
110
77
=head1 AUTHOR
111
=head1 AUTHOR
78
112
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-main.tt (-57 / +52 lines)
Lines 72-78 Link Here
72
        <h1 class="sr-only">Koha home</h1>
72
        <h1 class="sr-only">Koha home</h1>
73
73
74
        [% IF Koha.Preference( 'OpacNewsLibrarySelect' ) %]
74
        [% IF Koha.Preference( 'OpacNewsLibrarySelect' ) %]
75
            [% UNLESS news_item %]
75
            [% UNLESS news_id %]
76
                <form id="news-branch-select" class="form-inline" name="news-branch-select" method="get" action="/cgi-bin/koha/opac-main.pl">
76
                <form id="news-branch-select" class="form-inline" name="news-branch-select" method="get" action="/cgi-bin/koha/opac-main.pl">
77
                    <legend class="sr-only">News</legend>
77
                    <legend class="sr-only">News</legend>
78
                    <label for="news-branch">Display news for: </label>
78
                    <label for="news-branch">Display news for: </label>
Lines 88-154 Link Here
88
            [% END %]
88
            [% END %]
89
        [% END %]
89
        [% END %]
90
90
91
        [% IF koha_news.count %]
91
        [% IF news_id %]
92
92
            [% SET koha_news = AdditionalContents.get_opac_news_by_id( news_id => news_id ) %]
93
            [% IF single_news_error %]
93
        [% ELSE %]
94
94
            [% SET koha_news = AdditionalContents.get( category => 'news', location => ['opac_only', 'staff_and_opac'], lang => lang, library => branchcode ) %]
95
                <div class="alert alert-error">
95
        [% END %]
96
                    This news item does not exist.
96
        [% IF koha_news.content.count %]
97
                </div>
97
            <div id="news" class="newscontainer">
98
98
                [% SET show_author = Koha.Preference('NewsAuthorDisplay') == 'opac' || Koha.Preference('NewsAuthorDisplay') == 'both' %]
99
            [% ELSE %]
99
                [% FOREACH koha_new IN koha_news.content %]
100
                    <div class="newsitem">
101
                        <h4 class="newsheader">
102
                            [% IF ( news_item ) %]
103
                                [% koha_new.title | html %]
104
                            [% ELSE %]
105
                                <a name="newsitem[% koha_new.idnew | html %]" href="/cgi-bin/koha/opac-main.pl?news_id=[% koha_new.idnew | uri %]">[% koha_new.title | html %]</a>
106
                            [% END %]
107
                        </h4>
108
                        <div class="newsbody">[% koha_new.content | $raw %]</div>
109
                        <div class="newsfooter">
110
                            Published on [% koha_new.published_on | $KohaDates %]
111
                            [% IF ( show_author && koha_new.author ) %]
112
                                by <span class="newsauthor">[% INCLUDE 'patron-title.inc' patron=koha_new.author %]</span>
113
                            [% END %]
114
                            [% IF ( news_id ) %]
115
                                &bull; <a href="/cgi-bin/koha/opac-main.pl">Show all news</a>
116
                            [% END %]
117
                        </div>
118
                    </div>
119
                [% END %]
100
120
101
                <div id="news" class="newscontainer">
121
                [% UNLESS news_id %]
102
                    [% SET show_author = Koha.Preference('NewsAuthorDisplay') == 'opac' || Koha.Preference('NewsAuthorDisplay') == 'both' %]
122
                    <div id="rssnews-container">
103
                    [% FOREACH koha_new IN koha_news %]
123
                        <!-- Logged in users have a branch code or it could be explicitly set -->
104
                    [% IF koha_new.category == 'news' %]
124
                        <a href="[% OPACBaseURL | url %]/cgi-bin/koha/opac-news-rss.pl?branchcode=[% branchcode | uri %]">
105
                        <div class="newsitem">
125
                            <i class="fa fa-rss" aria-hidden="true"></i>
106
                            <h4 class="newsheader">
126
                            [% IF Branches.all.size == 1 %]
107
                                [% IF ( news_item ) %]
127
                                [% IF branchcode %]
108
                                    [% koha_new.title | html %]
128
                                    <span>RSS feed for [% Branches.GetName( branchcode ) | html %] library news</span>
109
                                [% ELSE %]
129
                                [% ELSE %]
110
                                    <a name="newsitem[% koha_new.idnew | html %]" href="/cgi-bin/koha/opac-main.pl?news_id=[% koha_new.idnew | uri %]">[% koha_new.title | html %]</a>
130
                                    <span>RSS feed for library news</span>
111
                                [% END %]
112
                            </h4>
113
                            <div class="newsbody">[% koha_new.content | $raw %]</div>
114
                            <div class="newsfooter">
115
                                Published on [% koha_new.published_on | $KohaDates %]
116
                                [% IF ( show_author && koha_new.author ) %]
117
                                    by <span class="newsauthor">[% INCLUDE 'patron-title.inc' patron=koha_new.author %]</span>
118
                                [% END %]
119
                                [% IF ( news_item ) %]
120
                                    &bull; <a href="/cgi-bin/koha/opac-main.pl">Show all news</a>
121
                                [% END %]
131
                                [% END %]
122
                            </div>
132
                            [% ELSE %]
123
                        </div>
133
                                [% IF branchcode %]
124
                    [% END %]
134
                                    <span>RSS feed for [% Branches.GetName( branchcode ) | html %] and system-wide library news</span>
125
                    [% END %]
126
127
                    [% UNLESS news_item %]
128
                        <div id="rssnews-container">
129
                            <!-- Logged in users have a branch code or it could be explicitly set -->
130
                            <a href="[% OPACBaseURL | url %]/cgi-bin/koha/opac-news-rss.pl?branchcode=[% branchcode | uri %]">
131
                                <i class="fa fa-rss" aria-hidden="true"></i>
132
                                [% IF Branches.all.size == 1 %]
133
                                    [% IF branchcode %]
134
                                        <span>RSS feed for [% Branches.GetName( branchcode ) | html %] library news</span>
135
                                    [% ELSE %]
136
                                        <span>RSS feed for library news</span>
137
                                    [% END %]
138
                                [% ELSE %]
135
                                [% ELSE %]
139
                                    [% IF branchcode %]
136
                                    <span>RSS feed for system-wide library news</span>
140
                                        <span>RSS feed for [% Branches.GetName( branchcode ) | html %] and system-wide library news</span>
141
                                    [% ELSE %]
142
                                        <span>RSS feed for system-wide library news</span>
143
                                    [% END %]
144
                                [% END %]
137
                                [% END %]
145
                            </a>
138
                            [% END %]
146
                        </div>
139
                        </a>
147
                    [% END %]
140
                    </div>
148
                </div>
141
                [% END %]
149
142
            </div>
150
            [% END # /IF single_news_error %]
143
        [% ELSIF news_id %] <!-- news_id but no koha_news.content -->
151
144
            <div class="alert alert-error">
145
                This news item does not exist.
146
            </div>
152
        [% ELSE %] <!-- koha news -->
147
        [% ELSE %] <!-- koha news -->
153
            [% IF Koha.Preference( 'OpacNewsLibrarySelect' ) %]
148
            [% IF Koha.Preference( 'OpacNewsLibrarySelect' ) %]
154
                <div id="news" class="newscontainer">
149
                <div id="news" class="newscontainer">
(-)a/opac/opac-main.pl (-22 / +3 lines)
Lines 58-83 elsif (C4::Context->userenv and defined $input->param('branch') and length $inpu Link Here
58
   $homebranch = "";
58
   $homebranch = "";
59
}
59
}
60
60
61
my $news_id = $input->param('news_id');
62
my $koha_news;
63
61
64
if (defined $news_id){
62
my $news_id = $input->param('news_id');
65
    $koha_news = Koha::AdditionalContents->search({ idnew => $news_id, location => ['opac_only', 'staff_and_opac'] }); # get news that is not staff-only news
63
$template->param( news_id => $news_id );
66
    if ( $koha_news->count > 0){
67
        $template->param( news_item => $koha_news->next );
68
    } else {
69
        $template->param( single_news_error => 1 );
70
    }
71
} else {
72
    $koha_news = Koha::AdditionalContents->search_for_display(
73
        {
74
            category   => 'news',
75
            location   => ['opac_only', 'staff_and_opac'],
76
            lang       => $template->lang,
77
            library_id => $homebranch,
78
        }
79
    );
80
}
81
64
82
# For dashboard
65
# For dashboard
83
my $patron = Koha::Patrons->find( $borrowernumber );
66
my $patron = Koha::Patrons->find( $borrowernumber );
Lines 114-122 if ( $patron ) { Link Here
114
    }
97
    }
115
}
98
}
116
99
100
$template->param( branchcode => $homebranch ) if $homebranch;
117
$template->param(
101
$template->param(
118
    koha_news           => $koha_news,
119
    branchcode          => $homebranch,
120
    daily_quote         => Koha::Quotes->get_daily_quote(),
102
    daily_quote         => Koha::Quotes->get_daily_quote(),
121
);
103
);
122
104
123
- 

Return to bug 29691