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

(-)a/C4/Members.pm (-6 / +17 lines)
Lines 33-39 use C4::Reserves; Link Here
33
use C4::Accounts;
33
use C4::Accounts;
34
use C4::Biblio;
34
use C4::Biblio;
35
use C4::Letters;
35
use C4::Letters;
36
use C4::NewsChannels; #get slip news
37
use DateTime;
36
use DateTime;
38
use Koha::Database;
37
use Koha::Database;
39
use Koha::DateUtils;
38
use Koha::DateUtils;
Lines 41-46 use Koha::AuthUtils qw(hash_password); Link Here
41
use Koha::Database;
40
use Koha::Database;
42
use Koha::Holds;
41
use Koha::Holds;
43
use Koha::List::Patron;
42
use Koha::List::Patron;
43
use Koha::News;
44
use Koha::Patrons;
44
use Koha::Patrons;
45
use Koha::Patron::Categories;
45
use Koha::Patron::Categories;
46
46
Lines 588-598 sub IssueSlip { Link Here
588
                issues      => $all,
588
                issues      => $all,
589
            };
589
            };
590
        }
590
        }
591
        my $news = GetNewsToDisplay( "slip", $branch );
591
        my $news = Koha::News->search({
592
        my @news = map {
592
                lang => [ 'slip', '' ],
593
            $_->{'timestamp'} = $_->{'newdate'};
593
                branchcode => [ $branch, undef ],
594
            { opac_news => $_ }
594
                -or => [ expirationdate => { '>=' => \'NOW()' },
595
        } @$news;
595
                         expirationdate => undef ]
596
            },{
597
                order_by => 'number'
598
            }
599
        );
600
        my @news;
601
        while ( my $n = $news->next ) {
602
            my $all = $n->unblessed_all_relateds;
603
            push @news, {
604
                opac_news => $all,
605
            };
606
        }
596
        $letter_code = 'ISSUESLIP';
607
        $letter_code = 'ISSUESLIP';
597
        %repeat      = (
608
        %repeat      = (
598
            checkedout => \@checkouts,
609
            checkedout => \@checkouts,
(-)a/C4/NewsChannels.pm (-92 lines)
Lines 1-92 Link Here
1
package C4::NewsChannels;
2
3
# This file is part of Koha.
4
#
5
# Copyright (C) 2000-2002  Katipo Communications
6
# Copyright (C) 2013       Mark Tompsett
7
#
8
# Koha is free software; you can redistribute it and/or modify it
9
# under the terms of the GNU General Public License as published by
10
# the Free Software Foundation; either version 3 of the License, or
11
# (at your option) any later version.
12
#
13
# Koha is distributed in the hope that it will be useful, but
14
# WITHOUT ANY WARRANTY; without even the implied warranty of
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
# GNU General Public License for more details.
17
#
18
# You should have received a copy of the GNU General Public License
19
# along with Koha; if not, see <http://www.gnu.org/licenses>.
20
21
use Modern::Perl;
22
use C4::Context;
23
use Koha::DateUtils;
24
25
use vars qw(@ISA @EXPORT);
26
27
BEGIN { 
28
    @ISA = qw(Exporter);
29
    @EXPORT = qw(
30
        &GetNewsToDisplay
31
    );
32
}
33
34
=head1 NAME
35
36
C4::NewsChannels - Functions to manage OPAC and intranet news
37
38
=head1 DESCRIPTION
39
40
This module provides the functions needed to mange OPAC and intranet news.
41
42
=head1 FUNCTIONS
43
44
=cut
45
46
=head2 GetNewsToDisplay
47
48
    $news = &GetNewsToDisplay($lang,$branch);
49
    C<$news> is a ref to an array which contains
50
    all news with expirationdate > today or expirationdate is null
51
    that is applicable for a given branch.
52
53
=cut
54
55
sub GetNewsToDisplay {
56
    my ($lang,$branch) = @_;
57
    my $dbh = C4::Context->dbh;
58
    my $query = q{
59
     SELECT opac_news.*,published_on AS newdate,
60
     borrowers.title AS author_title,
61
     borrowers.firstname AS author_firstname,
62
     borrowers.surname AS author_surname
63
     FROM   opac_news
64
     LEFT JOIN borrowers on borrowers.borrowernumber = opac_news.borrowernumber
65
     WHERE   (
66
        expirationdate >= CURRENT_DATE()
67
        OR    expirationdate IS NULL
68
     )
69
     AND   published_on <= CURDATE()
70
     AND   (opac_news.lang = '' OR opac_news.lang = ?)
71
     AND   (opac_news.branchcode IS NULL OR opac_news.branchcode = ?)
72
     ORDER BY number
73
    };
74
    my $sth = $dbh->prepare($query);
75
    $lang = $lang // q{};
76
    $sth->execute($lang,$branch);
77
    my @results;
78
    while ( my $row = $sth->fetchrow_hashref ){
79
        $row->{newdate} = output_pref({ dt => dt_from_string( $row->{newdate} ), dateonly => 1 });
80
        push @results, $row;
81
    }
82
    return \@results;
83
}
84
85
1;
86
__END__
87
88
=head1 AUTHOR
89
90
TG
91
92
=cut
(-)a/Koha/Template/Plugin/KohaNews.pm (-3 / +12 lines)
Lines 26-32 use base qw( Template::Plugin ); Link Here
26
26
27
use C4::Koha;
27
use C4::Koha;
28
use C4::Context;
28
use C4::Context;
29
use C4::NewsChannels; # GetNewsToDisplay
29
use Koha::News;
30
30
31
sub get {
31
sub get {
32
    my ( $self, $params ) = @_;
32
    my ( $self, $params ) = @_;
Lines 34-40 sub get { Link Here
34
    my $display_location = $params->{location};
34
    my $display_location = $params->{location};
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;
38
    my $news_lang;
39
39
40
    if( !$display_location ){
40
    if( !$display_location ){
Lines 43-49 sub get { Link Here
43
        $news_lang = $display_location."_".$lang;
43
        $news_lang = $display_location."_".$lang;
44
    }
44
    }
45
45
46
    my $content = &GetNewsToDisplay( $news_lang, $library );
46
    my $search_params;
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
        });
47
56
48
    if( @$content ){
57
    if( @$content ){
49
        return {
58
        return {
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/intranet-main.tt (-3 / +6 lines)
Lines 2-7 Link Here
2
[% USE Asset %]
2
[% USE Asset %]
3
[% USE Koha %]
3
[% USE Koha %]
4
[% USE Branches %]
4
[% USE Branches %]
5
[% USE KohaDates %]
5
[% SET footerjs = 1 %]
6
[% SET footerjs = 1 %]
6
[% INCLUDE 'doc-head-open.inc' %]
7
[% INCLUDE 'doc-head-open.inc' %]
7
<title>Koha staff interface</title>
8
<title>Koha staff interface</title>
Lines 17-30 Link Here
17
    <div id="container-main" class="container-fluid">
18
    <div id="container-main" class="container-fluid">
18
        <div class="row">
19
        <div class="row">
19
            <div class="col-sm-3">
20
            <div class="col-sm-3">
20
                [% IF ( koha_news_count ) %]
21
                [% IF ( koha_news.count ) %]
21
                    <div id="area-news">
22
                    <div id="area-news">
22
                        <h3><span class="news_title">News</span></h3>
23
                        <h3><span class="news_title">News</span></h3>
23
                        [% SET newsdisp = Koha.Preference('NewsAuthorDisplay') %]
24
                        [% SET show_author =
25
                            Koha.Preference('NewsAuthorDisplay') == 'staff'
26
                            || Koha.Preference('NewsAuthorDisplay') == 'both' %]
24
                        [% FOREACH koha_new IN koha_news %]
27
                        [% FOREACH koha_new IN koha_news %]
25
                            <div class="newsitem" id="news[% koha_new.idnew | html %]"><h4>[% koha_new.title | html %]</h4>
28
                            <div class="newsitem" id="news[% koha_new.idnew | html %]"><h4>[% koha_new.title | html %]</h4>
26
                                <div class="newsbody">[% koha_new.content | $raw %]</div>
29
                                <div class="newsbody">[% koha_new.content | $raw %]</div>
27
                                <p class="newsfooter"> Posted on [% koha_new.newdate | html %][% IF( ( newsdisp == 'staff' || newsdisp == 'both' ) && koha_new.borrowernumber ) %] by <span class="newsauthor_title">[% koha_new.author_title | html %] </span>[% koha_new.author_firstname | html %] [% koha_new.author_surname | html %]<br />[% END %]
30
                                <p class="newsfooter"> Posted on [% koha_new.timestamp | $KohaDates %][% IF( show_author && koha_new.borrowernumber ) %] by <span class="newsauthor_title">[% koha_new.author.title | html %] </span>[% koha_new.author.firstname | html %] [% koha_new.author.surname | html %]<br />[% END %]
28
                                    [% IF ( CAN_user_tools ) %]
31
                                    [% IF ( CAN_user_tools ) %]
29
                                        <a href="/cgi-bin/koha/tools/koha-news.pl?op=add_form&amp;id=[% koha_new.idnew | uri %]">Edit</a>
32
                                        <a href="/cgi-bin/koha/tools/koha-news.pl?op=add_form&amp;id=[% koha_new.idnew | uri %]">Edit</a>
30
                                         | <a class="news_delete" href="/cgi-bin/koha/tools/koha-news.pl?op=del&amp;ids=[% koha_new.idnew | html %]">Delete</a>
33
                                         | <a class="news_delete" href="/cgi-bin/koha/tools/koha-news.pl?op=del&amp;ids=[% koha_new.idnew | html %]">Delete</a>
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/includes/html_helpers.inc (-1 / +1 lines)
Lines 9-15 Link Here
9
[% END %]
9
[% END %]
10
10
11
[% BLOCK koha_news_block %]
11
[% BLOCK koha_news_block %]
12
    [% IF ( news.content.size > 0 ) %]
12
    [% IF ( news.content.count > 0 ) %]
13
        <div id="[% news.location | html %]">
13
        <div id="[% news.location | html %]">
14
            [% FOREACH n IN news.content %]
14
            [% FOREACH n IN news.content %]
15
                <div class="[% n.lang | html %]_item">
15
                <div class="[% n.lang | html %]_item">
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-main.tt (-9 / +6 lines)
Lines 93-99 Link Here
93
            [% ELSE %]
93
            [% ELSE %]
94
94
95
                <div id="news" class="newscontainer">
95
                <div id="news" class="newscontainer">
96
                    [% SET newsdisp = ( Koha.Preference('NewsAuthorDisplay') ) %]
96
                    [% SET show_author =
97
                        Koha.Preference('NewsAuthorDisplay') == 'opac'
98
                        || Koha.Preference('NewsAuthorDisplay') == 'both' %]
97
                    [% FOREACH koha_new IN koha_news %]
99
                    [% FOREACH koha_new IN koha_news %]
98
                        <div class="newsitem">
100
                        <div class="newsitem">
99
                            <h4 class="newsheader">
101
                            <h4 class="newsheader">
Lines 106-126 Link Here
106
                            <div class="newsbody">[% koha_new.content | $raw %]</div>
108
                            <div class="newsbody">[% koha_new.content | $raw %]</div>
107
                            <div class="newsfooter">
109
                            <div class="newsfooter">
108
                                Published on [% koha_new.published_on | $KohaDates %]
110
                                Published on [% koha_new.published_on | $KohaDates %]
109
                                [% IF ( (newsdisp == 'opac' || newsdisp == 'both') && koha_new.borrowernumber ) %]
111
                                [% IF ( show_author && koha_new.borrowernumber ) %]
110
                                    [% IF news_item %]
112
                                    by <span class="newsauthor_title">[% koha_new.author.title | html %] </span>[% koha_new.author.firstname | html %] [% koha_new.author.surname | html %]
111
                                        [% SET author = koha_new.author %]
112
                                        by <span class="newsauthor_title">[% author.title | html %] </span>[% author.firstname | html %] [% author.surname | html %]
113
                                    [% ELSE %]
114
                                        by <span class="newsauthor_title">[% koha_new.author_title | html %] </span>[% koha_new.author_firstname | html %] [% koha_new.author_surname | html %]
115
                                    [% END %]
116
                                [% END %]
113
                                [% END %]
117
                                [% IF ( news_item ) %]
114
                                [% IF ( news_item ) %]
118
                                    &bull; <a href="/cgi-bin/koha/opac-main.pl">Show all news</a>
115
                                    &bull; <a href="/cgi-bin/koha/opac-main.pl">Show all news</a>
119
                                [% END %]
116
                                [% END %]
120
                            </div>
117
                            </div>
121
                        </div>
118
                        </div>
122
123
                    [% END %]
119
                    [% END %]
120
124
                    [% UNLESS news_item %]
121
                    [% UNLESS news_item %]
125
                        <div id="rssnews-container">
122
                        <div id="rssnews-container">
126
                            <!-- Logged in users have a branch code or it could be explicitly set -->
123
                            <!-- Logged in users have a branch code or it could be explicitly set -->
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-news-rss.tt (-1 / +1 lines)
Lines 1-4 Link Here
1
[% USE raw %]
1
[% USE raw -%]
2
<?xml version="1.0"?>
2
<?xml version="1.0"?>
3
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
3
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
4
   <channel>
4
   <channel>
(-)a/mainpage.pl (-6 / +10 lines)
Lines 24-31 use CGI qw ( -utf8 ); Link Here
24
use C4::Output;
24
use C4::Output;
25
use C4::Auth;
25
use C4::Auth;
26
use C4::Koha;
26
use C4::Koha;
27
use C4::NewsChannels; # GetNewsToDisplay
28
use C4::Tags qw/get_count_by_tag_status/;
27
use C4::Tags qw/get_count_by_tag_status/;
28
use Koha::News;
29
use Koha::Patron::Modifications;
29
use Koha::Patron::Modifications;
30
use Koha::Patron::Discharge;
30
use Koha::Patron::Discharge;
31
use Koha::Reviews;
31
use Koha::Reviews;
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 $all_koha_news   = &GetNewsToDisplay("koha",$homebranch);
52
my $koha_news = Koha::News->search({
53
my $koha_news_count = scalar @$all_koha_news;
53
    lang => 'koha',
54
    branchcode => [ $homebranch, undef ]
55
},
56
{
57
    order_by => 'number'
58
});
54
59
55
$template->param(
60
$template->param(
56
    koha_news       => $all_koha_news,
61
    koha_news   => $koha_news,
57
    koha_news_count => $koha_news_count,
62
    daily_quote => Koha::Quotes->get_daily_quote(),
58
    daily_quote     => Koha::Quotes->get_daily_quote(),
59
);
63
);
60
64
61
my $branch =
65
my $branch =
(-)a/opac/opac-main.pl (-7 / +15 lines)
Lines 22-28 use Modern::Perl; Link Here
22
use CGI qw ( -utf8 );
22
use CGI qw ( -utf8 );
23
use C4::Auth;    # get_template_and_user
23
use C4::Auth;    # get_template_and_user
24
use C4::Output;
24
use C4::Output;
25
use C4::NewsChannels;    # GetNewsToDisplay
26
use C4::Languages qw(getTranslatedLanguages accept_language);
25
use C4::Languages qw(getTranslatedLanguages accept_language);
27
use Koha::Quotes;
26
use Koha::Quotes;
28
use C4::Members;
27
use C4::Members;
Lines 61-77 elsif (C4::Context->userenv and defined $input->param('branch') and length $inpu Link Here
61
}
60
}
62
61
63
my $news_id = $input->param('news_id');
62
my $news_id = $input->param('news_id');
64
my $all_koha_news;
63
my $koha_news;
65
64
66
if (defined $news_id){
65
if (defined $news_id){
67
    $all_koha_news = Koha::News->search({ idnew => $news_id, lang => { '!=', 'koha' } }); # get news that is not staff-only news
66
    $koha_news = Koha::News->search({ idnew => $news_id, lang => { '!=', 'koha' } }); # get news that is not staff-only news
68
    if( $all_koha_news->count ) { # we only expect one btw
67
    if ( $koha_news->count > 0){
69
        $template->param( news_item => $all_koha_news->next );
68
        $template->param( news_item => $koha_news->next );
70
    } else {
69
    } else {
71
        $template->param( single_news_error => 1 );
70
        $template->param( single_news_error => 1 );
72
    }
71
    }
73
} else {
72
} else {
74
    $all_koha_news   = &GetNewsToDisplay( $template->lang, $homebranch);
73
    my $params;
74
    $params->{lang} = [ $template->lang, '' ];
75
    $params->{branchcode} = [ $homebranch, undef ] if $homebranch;
76
    $params->{-or} = [ expirationdate => { '>=' => \'NOW()' },
77
                       expirationdate => undef ];
78
    $koha_news = Koha::News->search(
79
        $params,
80
        {
81
            order_by => 'number'
82
        });
75
}
83
}
76
84
77
# For dashboard
85
# For dashboard
Lines 104-110 if ( $patron ) { Link Here
104
}
112
}
105
113
106
$template->param(
114
$template->param(
107
    koha_news           => $all_koha_news,
115
    koha_news           => $koha_news,
108
    branchcode          => $homebranch,
116
    branchcode          => $homebranch,
109
    daily_quote         => Koha::Quotes->get_daily_quote(),
117
    daily_quote         => Koha::Quotes->get_daily_quote(),
110
);
118
);
(-)a/opac/opac-news-rss.pl (-7 / +12 lines)
Lines 22-29 use Modern::Perl; Link Here
22
use CGI;
22
use CGI;
23
use C4::Auth;    # get_template_and_user
23
use C4::Auth;    # get_template_and_user
24
use C4::Output;
24
use C4::Output;
25
use C4::NewsChannels;    # GetNewsToDisplay
26
use C4::Languages qw(getTranslatedLanguages accept_language);
25
use C4::Languages qw(getTranslatedLanguages accept_language);
26
use Koha::News;
27
27
28
my $input = CGI->new;
28
my $input = CGI->new;
29
my $dbh   = C4::Context->dbh;
29
my $dbh   = C4::Context->dbh;
Lines 43-54 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 $all_koha_news   = GetNewsToDisplay( $news_lang, $branchcode );
46
my $params;
47
my $koha_news_count = scalar @$all_koha_news;
47
$params->{lang} = [ $news_lang, '' ];
48
$params->{branchcode} = [ $branchcode, undef ] if $branchcode;
49
$params->{-or} = [ expirationdate => { '>=' => \'NOW()' },
50
                   expirationdate => undef ];
51
my $koha_news = Koha::News->search(
52
    $params,
53
    {
54
        order_by => 'number'
55
    });
48
56
49
$template->param(
57
$template->param( koha_news => $koha_news );
50
    koha_news           => $all_koha_news,
51
    koha_news_count     => $koha_news_count,
52
);
53
58
54
output_html_with_http_headers $input, $cookie, $template->output;
59
output_html_with_http_headers $input, $cookie, $template->output;
(-)a/t/db_dependent/NewsChannels.t (-67 lines)
Lines 1-67 Link Here
1
#!/usr/bin/perl
2
3
use Modern::Perl;
4
use Koha::Database;
5
use Koha::DateUtils;
6
use Koha::Libraries;
7
use Koha::News;
8
9
use Test::More tests => 4;
10
11
BEGIN {
12
    use_ok('C4::NewsChannels');
13
}
14
15
my $schema = Koha::Database->new->schema;
16
$schema->storage->txn_begin;
17
my $dbh = C4::Context->dbh;
18
19
# Add LIB1, if it doesn't exist.
20
my $addbra = 'LIB1';
21
unless ( Koha::Libraries->find($addbra) ) {
22
    $dbh->do( q{ INSERT INTO branches (branchcode,branchname) VALUES (?,?) },
23
        undef, ( $addbra, "$addbra branch" ) );
24
}
25
26
# Add CAT1, if it doesn't exist.
27
my $addcat = 'CAT1';
28
{
29
    my $sth = $dbh->prepare( q{ SELECT categorycode FROM categories WHERE categorycode = ? } );
30
    $sth->execute ( $addcat );
31
    if ( not defined $sth->fetchrow () ) {
32
        $dbh->do( q{ INSERT INTO categories (categorycode,description) VALUES (?,?) },
33
            undef, ( $addcat, "$addcat description") );
34
    }
35
}
36
37
# Add a test user if not already present.
38
my $addbrwr = 'BRWR1';
39
my $brwrnmbr;
40
{
41
    my $query =
42
        q{ SELECT borrowernumber from borrowers WHERE surname = ? AND branchcode = ? AND categorycode = ? };
43
    my $sth = $dbh->prepare( $query );
44
    $sth->execute( ($addbrwr, $addbra, $addcat) );
45
    $brwrnmbr = $sth->fetchrow;
46
47
    # Not found, let us insert it.
48
    if ( not defined $brwrnmbr ) {
49
        $dbh->do( q{ INSERT INTO borrowers (surname, address, city, branchcode, categorycode) VALUES (?, ?, ?, ?, ?) },
50
            undef, ($addbrwr, '(test) address', '(test) city', $addbra, $addcat) );
51
52
        # Retrieve the njew borrower number.
53
        $query =
54
            q{ SELECT borrowernumber from borrowers WHERE surname = ? AND branchcode = ? AND categorycode = ? };
55
        my $sth = $dbh->prepare( $query );
56
        $sth->execute( ($addbrwr, $addbra, $addcat) );
57
        $brwrnmbr = $sth->fetchrow;
58
    }
59
}
60
61
# Must have valid borrower number, or tests are meaningless.
62
ok ( defined $brwrnmbr );
63
64
# Test GetNewsToDisplay
65
my ( $opac_news_count, $arrayref_opac_news ) = GetNewsToDisplay( q{}, 'LIB1' );
66
ok( $opac_news_count >= 2, 'Successfully tested GetNewsToDisplay for LIB1!' );
67
(-)a/tools/koha-news.pl (-2 lines)
Lines 28-34 use C4::Auth; Link Here
28
use C4::Koha;
28
use C4::Koha;
29
use C4::Context;
29
use C4::Context;
30
use C4::Output;
30
use C4::Output;
31
use C4::NewsChannels;
32
use C4::Languages qw(getTranslatedLanguages);
31
use C4::Languages qw(getTranslatedLanguages);
33
use Date::Calc qw/Date_to_Days Today/;
32
use Date::Calc qw/Date_to_Days Today/;
34
use Koha::DateUtils;
33
use Koha::DateUtils;
35
- 

Return to bug 22544