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

(-)a/C4/Members.pm (-6 / +17 lines)
Lines 35-41 use C4::Accounts; Link Here
35
use C4::Biblio;
35
use C4::Biblio;
36
use C4::Letters;
36
use C4::Letters;
37
use C4::Members::Attributes qw(SearchIdMatchingAttribute UpdateBorrowerAttribute);
37
use C4::Members::Attributes qw(SearchIdMatchingAttribute UpdateBorrowerAttribute);
38
use C4::NewsChannels; #get slip news
39
use DateTime;
38
use DateTime;
40
use Koha::Database;
39
use Koha::Database;
41
use Koha::DateUtils;
40
use Koha::DateUtils;
Lines 43-48 use Koha::AuthUtils qw(hash_password); Link Here
43
use Koha::Database;
42
use Koha::Database;
44
use Koha::Holds;
43
use Koha::Holds;
45
use Koha::List::Patron;
44
use Koha::List::Patron;
45
use Koha::News;
46
use Koha::Patrons;
46
use Koha::Patrons;
47
use Koha::Patron::Categories;
47
use Koha::Patron::Categories;
48
48
Lines 580-590 sub IssueSlip { Link Here
580
                issues      => $all,
580
                issues      => $all,
581
            };
581
            };
582
        }
582
        }
583
        my $news = GetNewsToDisplay( "slip", $branch );
583
        my $news = Koha::News->search({
584
        my @news = map {
584
                lang => [ 'slip', '' ],
585
            $_->{'timestamp'} = $_->{'newdate'};
585
                branchcode => [ $branch, undef ],
586
            { opac_news => $_ }
586
                -or => [ expirationdate => { '>=' => \'NOW()' },
587
        } @$news;
587
                         expirationdate => undef ]
588
            },{
589
                order_by => 'number'
590
            }
591
        );
592
        my @news;
593
        while ( my $n = $news->next ) {
594
            my $all = $n->unblessed_all_relateds;
595
            push @news, {
596
                opac_news => $all,
597
            };
598
        }
588
        $letter_code = 'ISSUESLIP';
599
        $letter_code = 'ISSUESLIP';
589
        %repeat      = (
600
        %repeat      = (
590
            checkedout => \@checkouts,
601
            checkedout => \@checkouts,
(-)a/C4/NewsChannels.pm (-96 lines)
Lines 1-96 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
    # SELECT *,DATE_FORMAT(timestamp, '%d/%m/%Y') AS newdate
59
    my $query = q{
60
     SELECT opac_news.*,timestamp AS newdate,
61
     borrowers.title AS author_title,
62
     borrowers.firstname AS author_firstname,
63
     borrowers.surname AS author_surname
64
     FROM   opac_news
65
     LEFT JOIN borrowers on borrowers.borrowernumber = opac_news.borrowernumber
66
     WHERE   (
67
        expirationdate >= CURRENT_DATE()
68
        OR    expirationdate IS NULL
69
        OR    expirationdate = '00-00-0000'
70
     )
71
     AND   DATE(timestamp) < DATE_ADD(CURDATE(), INTERVAL 1 DAY)
72
     AND   (opac_news.lang = '' OR opac_news.lang = ?)
73
     AND   (opac_news.branchcode IS NULL OR opac_news.branchcode = ?)
74
     ORDER BY number
75
    }; # expirationdate field is NOT in ISO format?
76
       # timestamp has HH:mm:ss, CURRENT_DATE generates 00:00:00
77
       #           by adding 1, that captures today correctly.
78
    my $sth = $dbh->prepare($query);
79
    $lang = $lang // q{};
80
    $sth->execute($lang,$branch);
81
    my @results;
82
    while ( my $row = $sth->fetchrow_hashref ){
83
        $row->{newdate} = output_pref({ dt => dt_from_string( $row->{newdate} ), dateonly => 1 });
84
        push @results, $row;
85
    }
86
    return \@results;
87
}
88
89
1;
90
__END__
91
92
=head1 AUTHOR
93
94
TG
95
96
=cut
(-)a/Koha/Template/Plugin/KohaNews.pm (-5 / +13 lines)
Lines 26-39 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 ) = @_;
33
33
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
    my $news_lang;
38
38
39
    if( !$display_location ){
39
    if( !$display_location ){
Lines 42-49 sub get { Link Here
42
        $news_lang = $display_location."_".$lang;
42
        $news_lang = $display_location."_".$lang;
43
    }
43
    }
44
44
45
    my $content = &GetNewsToDisplay( $news_lang, $library );
45
    my $search_params;
46
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
        });
47
    return $content;
55
    return $content;
48
}
56
}
49
57
Lines 70-73 the following TT code: [% KohaNews.get() %] Link Here
70
78
71
Owen Leonard <oleonard@myacpl.org>
79
Owen Leonard <oleonard@myacpl.org>
72
80
73
=cut
81
=cut
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/intranet-main.tt (-3 / +6 lines)
Lines 1-6 Link Here
1
[% USE raw %]
1
[% USE raw %]
2
[% USE Asset %]
2
[% USE Asset %]
3
[% USE Koha %]
3
[% USE Koha %]
4
[% USE KohaDates %]
4
[% SET footerjs = 1 %]
5
[% SET footerjs = 1 %]
5
[% INCLUDE 'doc-head-open.inc' %]
6
[% INCLUDE 'doc-head-open.inc' %]
6
<title>Koha staff client</title>
7
<title>Koha staff client</title>
Lines 16-29 Link Here
16
    <div id="container-main" class="container-fluid">
17
    <div id="container-main" class="container-fluid">
17
        <div class="row">
18
        <div class="row">
18
            <div class="col-sm-3">
19
            <div class="col-sm-3">
19
                [% IF ( koha_news_count ) %]
20
                [% IF ( koha_news.count ) %]
20
                    <div id="area-news">
21
                    <div id="area-news">
21
                        <h3><span class="news_title">News</span></h3>
22
                        <h3><span class="news_title">News</span></h3>
22
                        [% SET newsdisp = Koha.Preference('NewsAuthorDisplay') %]
23
                        [% SET show_author =
24
                            Koha.Preference('NewsAuthorDisplay') == 'staff'
25
                            || Koha.Preference('NewsAuthorDisplay') == 'both' %]
23
                        [% FOREACH koha_new IN koha_news %]
26
                        [% FOREACH koha_new IN koha_news %]
24
                            <div class="newsitem" id="news[% koha_new.idnew | html %]"><h4>[% koha_new.title | html %]</h4>
27
                            <div class="newsitem" id="news[% koha_new.idnew | html %]"><h4>[% koha_new.title | html %]</h4>
25
                                <div class="newsbody">[% koha_new.content | $raw %]</div>
28
                                <div class="newsbody">[% koha_new.content | $raw %]</div>
26
                                <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 %]
29
                                <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 %]
27
                                    [% IF ( CAN_user_tools ) %]
30
                                    [% IF ( CAN_user_tools ) %]
28
                                        <a href="/cgi-bin/koha/tools/koha-news.pl?op=add_form&amp;id=[% koha_new.idnew | uri %]">Edit</a>
31
                                        <a href="/cgi-bin/koha/tools/koha-news.pl?op=add_form&amp;id=[% koha_new.idnew | uri %]">Edit</a>
29
                                         | <a class="news_delete" href="/cgi-bin/koha/tools/koha-news.pl?op=del&amp;ids=[% koha_new.idnew | html %]">Delete</a>
32
                                         | <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.size > 0 ) %]
12
    [% IF ( news.count > 0 ) %]
13
        [% FOREACH n IN news %]
13
        [% FOREACH n IN news %]
14
            <div class="[% n.lang | html %]_item">
14
            <div class="[% n.lang | html %]_item">
15
                [% IF ( n.title ) %]
15
                [% IF ( n.title ) %]
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-main.tt (-2 / +4 lines)
Lines 75-86 Link Here
75
            [% ELSE %]
75
            [% ELSE %]
76
76
77
            <div id="news" class="newscontainer">
77
            <div id="news" class="newscontainer">
78
                [% SET newsdisp = ( Koha.Preference('NewsAuthorDisplay') ) %]
78
                [% SET show_author =
79
                    Koha.Preference('NewsAuthorDisplay') == 'opac'
80
                    || Koha.Preference('NewsAuthorDisplay') == 'both' %]
79
                [% FOREACH koha_new IN koha_news %]
81
                [% FOREACH koha_new IN koha_news %]
80
                    <div class="newsitem">
82
                    <div class="newsitem">
81
                        <a name="newsitem[% koha_new.idnew | html %]" href="/cgi-bin/koha/opac-main.pl?news_id=[% koha_new.idnew | uri %]"><h4 class="newsheader">[% koha_new.title | html %]</h4></a>
83
                        <a name="newsitem[% koha_new.idnew | html %]" href="/cgi-bin/koha/opac-main.pl?news_id=[% koha_new.idnew | uri %]"><h4 class="newsheader">[% koha_new.title | html %]</h4></a>
82
                        <div class="newsbody">[% koha_new.content | $raw %]</div>
84
                        <div class="newsbody">[% koha_new.content | $raw %]</div>
83
                        <div class="newsfooter">(published on [% koha_new.timestamp | $KohaDates with_hours = 1 %][% IF ( (newsdisp == 'opac' || 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 %][% END %])</div>
85
                        <div class="newsfooter">(published on [% koha_new.timestamp | $KohaDates with_hours = 1 %][% 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 %][% END %])</div>
84
                    </div>
86
                    </div>
85
                [% END %]
87
                [% END %]
86
            </div>
88
            </div>
(-)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 (-7 / +9 lines)
Lines 24-32 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::Suggestions qw/CountSuggestion/;
27
use C4::Suggestions qw/CountSuggestion/;
29
use C4::Tags qw/get_count_by_tag_status/;
28
use C4::Tags qw/get_count_by_tag_status/;
29
use Koha::News;
30
use Koha::Patron::Modifications;
30
use Koha::Patron::Modifications;
31
use Koha::Patron::Discharge;
31
use Koha::Patron::Discharge;
32
use Koha::Reviews;
32
use Koha::Reviews;
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 $all_koha_news   = &GetNewsToDisplay("koha",$homebranch);
51
my $koha_news = Koha::News->search({
52
my $koha_news_count = scalar @$all_koha_news;
52
    lang => 'koha',
53
    branchcode => [ $homebranch, undef ]
54
},
55
{
56
    order_by => 'number'
57
});
53
58
54
$template->param(
59
$template->param( koha_news => $koha_news );
55
    koha_news       => $all_koha_news,
56
    koha_news_count => $koha_news_count
57
);
58
60
59
my $branch =
61
my $branch =
60
  (      C4::Context->preference("IndependentBranchesPatronModifications")
62
  (      C4::Context->preference("IndependentBranchesPatronModifications")
(-)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 C4::Koha qw( GetDailyQuote );
26
use C4::Koha qw( GetDailyQuote );
28
use C4::Members;
27
use C4::Members;
Lines 64-80 elsif (C4::Context->userenv and defined $input->param('branch') and length $inpu Link Here
64
}
63
}
65
64
66
my $news_id = $input->param('news_id');
65
my $news_id = $input->param('news_id');
67
my @all_koha_news;
66
my $koha_news;
68
67
69
if (defined $news_id){
68
if (defined $news_id){
70
    @all_koha_news = Koha::News->search({ idnew => $news_id, lang => { '!=', 'koha' } }); # get news that is not staff-only news
69
    $koha_news = Koha::News->search({ idnew => $news_id, lang => { '!=', 'koha' } }); # get news that is not staff-only news
71
    if (scalar @all_koha_news > 0){
70
    if ( $koha_news->count > 0){
72
        $template->param( news_item => @all_koha_news );
71
        $template->param( news_item => $koha_news->next );
73
    } else {
72
    } else {
74
        $template->param( single_news_error => 1 );
73
        $template->param( single_news_error => 1 );
75
    }
74
    }
76
} else {
75
} else {
77
    @all_koha_news   = &GetNewsToDisplay($news_lang,$homebranch);
76
    my $params;
77
    $params->{lang} = [ $news_lang, '' ];
78
    $params->{branchcode} = [ $homebranch, undef ] if $homebranch;
79
    $params->{-or} = [ expirationdate => { '>=' => \'NOW()' },
80
                       expirationdate => undef ];
81
    $koha_news = Koha::News->search(
82
        $params,
83
        {
84
            order_by => 'number'
85
        });
78
}
86
}
79
87
80
my $quote = GetDailyQuote();   # other options are to pass in an exact quote id or select a random quote each pass... see perldoc C4::Koha
88
my $quote = GetDailyQuote();   # other options are to pass in an exact quote id or select a random quote each pass... see perldoc C4::Koha
Lines 103-109 if ( $patron ) { Link Here
103
}
111
}
104
112
105
$template->param(
113
$template->param(
106
    koha_news           => @all_koha_news,
114
    koha_news           => $koha_news,
107
    news_lang           => $news_lang,
115
    news_lang           => $news_lang,
108
    branchcode          => $homebranch,
116
    branchcode          => $homebranch,
109
    display_daily_quote => C4::Context->preference('QuoteOfTheDay'),
117
    display_daily_quote => C4::Context->preference('QuoteOfTheDay'),
(-)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 = new CGI;
28
my $input = new CGI;
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