Bug 22544: Move GetNewsToDisplay to Koha namespace
Signed-off-by: David Nind <david@davidnind.com> Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> Bug 22544: fix count call - to squash Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
parent
05798ec1aa
commit
9ca8d08a51
|
|
@ -33,7 +33,6 @@ use C4::Reserves;
|
|||
use C4::Accounts;
|
||||
use C4::Biblio;
|
||||
use C4::Letters;
|
||||
use C4::NewsChannels; #get slip news
|
||||
use DateTime;
|
||||
use Koha::Database;
|
||||
use Koha::DateUtils;
|
||||
|
|
@ -41,6 +40,7 @@ use Koha::AuthUtils qw(hash_password);
|
|||
use Koha::Database;
|
||||
use Koha::Holds;
|
||||
use Koha::List::Patron;
|
||||
use Koha::News;
|
||||
use Koha::Patrons;
|
||||
use Koha::Patron::Categories;
|
||||
|
||||
|
|
@ -588,11 +588,22 @@ sub IssueSlip {
|
|||
issues => $all,
|
||||
};
|
||||
}
|
||||
my $news = GetNewsToDisplay( "slip", $branch );
|
||||
my @news = map {
|
||||
$_->{'timestamp'} = $_->{'newdate'};
|
||||
{ opac_news => $_ }
|
||||
} @$news;
|
||||
my $news = Koha::News->search({
|
||||
lang => [ 'slip', '' ],
|
||||
branchcode => [ $branch, undef ],
|
||||
-or => [ expirationdate => { '>=' => \'NOW()' },
|
||||
expirationdate => undef ]
|
||||
},{
|
||||
order_by => 'number'
|
||||
}
|
||||
);
|
||||
my @news;
|
||||
while ( my $n = $news->next ) {
|
||||
my $all = $n->unblessed_all_relateds;
|
||||
push @news, {
|
||||
opac_news => $all,
|
||||
};
|
||||
}
|
||||
$letter_code = 'ISSUESLIP';
|
||||
%repeat = (
|
||||
checkedout => \@checkouts,
|
||||
|
|
|
|||
|
|
@ -1,94 +0,0 @@
|
|||
package C4::NewsChannels;
|
||||
|
||||
# This file is part of Koha.
|
||||
#
|
||||
# Copyright (C) 2000-2002 Katipo Communications
|
||||
# Copyright (C) 2013 Mark Tompsett
|
||||
#
|
||||
# Koha is free software; you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Koha is distributed in the hope that it will be useful, but
|
||||
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Koha; if not, see <http://www.gnu.org/licenses>.
|
||||
|
||||
use Modern::Perl;
|
||||
use C4::Context;
|
||||
use Koha::DateUtils;
|
||||
use C4::Log qw(logaction);
|
||||
use Koha::News;
|
||||
|
||||
use vars qw(@ISA @EXPORT);
|
||||
|
||||
BEGIN {
|
||||
@ISA = qw(Exporter);
|
||||
@EXPORT = qw(
|
||||
&GetNewsToDisplay
|
||||
);
|
||||
}
|
||||
|
||||
=head1 NAME
|
||||
|
||||
C4::NewsChannels - Functions to manage OPAC and intranet news
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
This module provides the functions needed to mange OPAC and intranet news.
|
||||
|
||||
=head1 FUNCTIONS
|
||||
|
||||
=cut
|
||||
|
||||
=head2 GetNewsToDisplay
|
||||
|
||||
$news = &GetNewsToDisplay($lang,$branch);
|
||||
C<$news> is a ref to an array which contains
|
||||
all news with expirationdate > today or expirationdate is null
|
||||
that is applicable for a given branch.
|
||||
|
||||
=cut
|
||||
|
||||
sub GetNewsToDisplay {
|
||||
my ($lang,$branch) = @_;
|
||||
my $dbh = C4::Context->dbh;
|
||||
my $query = q{
|
||||
SELECT opac_news.*,published_on AS newdate,
|
||||
borrowers.title AS author_title,
|
||||
borrowers.firstname AS author_firstname,
|
||||
borrowers.surname AS author_surname
|
||||
FROM opac_news
|
||||
LEFT JOIN borrowers on borrowers.borrowernumber = opac_news.borrowernumber
|
||||
WHERE (
|
||||
expirationdate >= CURRENT_DATE()
|
||||
OR expirationdate IS NULL
|
||||
)
|
||||
AND published_on <= CURDATE()
|
||||
AND (opac_news.lang = '' OR opac_news.lang = ?)
|
||||
AND (opac_news.branchcode IS NULL OR opac_news.branchcode = ?)
|
||||
ORDER BY number
|
||||
};
|
||||
my $sth = $dbh->prepare($query);
|
||||
$lang = $lang // q{};
|
||||
$sth->execute($lang,$branch);
|
||||
my @results;
|
||||
while ( my $row = $sth->fetchrow_hashref ){
|
||||
$row->{newdate} = output_pref({ dt => dt_from_string( $row->{newdate} ), dateonly => 1 });
|
||||
push @results, $row;
|
||||
}
|
||||
return \@results;
|
||||
}
|
||||
|
||||
1;
|
||||
__END__
|
||||
|
||||
=head1 AUTHOR
|
||||
|
||||
TG
|
||||
|
||||
=cut
|
||||
|
|
@ -26,7 +26,7 @@ use base qw( Template::Plugin );
|
|||
|
||||
use C4::Koha;
|
||||
use C4::Context;
|
||||
use C4::NewsChannels; # GetNewsToDisplay
|
||||
use Koha::News;
|
||||
|
||||
sub get {
|
||||
my ( $self, $params ) = @_;
|
||||
|
|
@ -34,7 +34,7 @@ sub get {
|
|||
my $display_location = $params->{location};
|
||||
my $blocktitle = $params->{blocktitle};
|
||||
my $lang = $params->{lang};
|
||||
my $library = $params->{library} || "";
|
||||
my $library = $params->{library};
|
||||
my $news_lang;
|
||||
|
||||
if( !$display_location ){
|
||||
|
|
@ -43,7 +43,16 @@ sub get {
|
|||
$news_lang = $display_location."_".$lang;
|
||||
}
|
||||
|
||||
my $content = &GetNewsToDisplay( $news_lang, $library );
|
||||
my $search_params;
|
||||
$search_params->{lang} = $news_lang;
|
||||
$search_params->{branchcode} = [ $library, undef ] if $library;
|
||||
$search_params->{-or} = [ expirationdate => { '>=' => \'NOW()' },
|
||||
expirationdate => undef ];
|
||||
my $content = Koha::News->search(
|
||||
$search_params,
|
||||
{
|
||||
order_by => 'number'
|
||||
});
|
||||
|
||||
if( @$content ){
|
||||
return {
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
[% USE Asset %]
|
||||
[% USE Koha %]
|
||||
[% USE Branches %]
|
||||
[% USE KohaDates %]
|
||||
[% SET footerjs = 1 %]
|
||||
[% INCLUDE 'doc-head-open.inc' %]
|
||||
<title>Koha staff interface</title>
|
||||
|
|
@ -23,14 +24,16 @@
|
|||
<div id="container-main" class="container-fluid">
|
||||
<div class="row">
|
||||
<div class="col-sm-3">
|
||||
[% IF ( koha_news_count ) %]
|
||||
[% IF ( koha_news.count ) %]
|
||||
<div id="area-news">
|
||||
<h3><span class="news_title">News</span></h3>
|
||||
[% SET newsdisp = Koha.Preference('NewsAuthorDisplay') %]
|
||||
[% SET show_author =
|
||||
Koha.Preference('NewsAuthorDisplay') == 'staff'
|
||||
|| Koha.Preference('NewsAuthorDisplay') == 'both' %]
|
||||
[% FOREACH koha_new IN koha_news %]
|
||||
<div class="newsitem" id="news[% koha_new.idnew | html %]"><h4>[% koha_new.title | html %]</h4>
|
||||
<div class="newsbody">[% koha_new.content | $raw %]</div>
|
||||
<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 %]
|
||||
<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 %]
|
||||
[% IF ( CAN_user_tools ) %]
|
||||
<a href="/cgi-bin/koha/tools/koha-news.pl?op=add_form&id=[% koha_new.idnew | uri %]">Edit</a>
|
||||
| <a class="news_delete" href="/cgi-bin/koha/tools/koha-news.pl?op=del&ids=[% koha_new.idnew | html %]">Delete</a>
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@
|
|||
[% END %]
|
||||
|
||||
[% BLOCK koha_news_block %]
|
||||
[% IF ( news.content.size > 0 ) %]
|
||||
[% IF ( news.content.count > 0 ) %]
|
||||
<div id="[% news.location | html %]">
|
||||
[% FOREACH n IN news.content %]
|
||||
<div class="[% n.lang | html %]_item">
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@
|
|||
[% END %]
|
||||
[% END %]
|
||||
|
||||
[% IF ( koha_news ) %]
|
||||
[% IF koha_news.count %]
|
||||
|
||||
[% IF single_news_error %]
|
||||
|
||||
|
|
@ -96,7 +96,9 @@
|
|||
[% ELSE %]
|
||||
|
||||
<div id="news" class="newscontainer">
|
||||
[% SET newsdisp = ( Koha.Preference('NewsAuthorDisplay') ) %]
|
||||
[% SET show_author =
|
||||
Koha.Preference('NewsAuthorDisplay') == 'opac'
|
||||
|| Koha.Preference('NewsAuthorDisplay') == 'both' %]
|
||||
[% FOREACH koha_new IN koha_news %]
|
||||
<div class="newsitem">
|
||||
<h4 class="newsheader">
|
||||
|
|
@ -109,21 +111,16 @@
|
|||
<div class="newsbody">[% koha_new.content | $raw %]</div>
|
||||
<div class="newsfooter">
|
||||
Published on [% koha_new.published_on | $KohaDates %]
|
||||
[% IF ( (newsdisp == 'opac' || newsdisp == 'both') && koha_new.borrowernumber ) %]
|
||||
[% IF news_item %]
|
||||
[% SET author = koha_new.author %]
|
||||
by <span class="newsauthor_title">[% author.title | html %] </span>[% author.firstname | html %] [% author.surname | html %]
|
||||
[% ELSE %]
|
||||
by <span class="newsauthor_title">[% koha_new.author_title | html %] </span>[% koha_new.author_firstname | html %] [% koha_new.author_surname | html %]
|
||||
[% END %]
|
||||
[% 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 %]
|
||||
[% IF ( news_item ) %]
|
||||
• <a href="/cgi-bin/koha/opac-main.pl">Show all news</a>
|
||||
[% END %]
|
||||
</div>
|
||||
</div>
|
||||
|
||||
[% END %]
|
||||
|
||||
[% UNLESS news_item %]
|
||||
<div id="rssnews-container">
|
||||
<!-- Logged in users have a branch code or it could be explicitly set -->
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
[% USE raw %]
|
||||
[% USE raw -%]
|
||||
<?xml version="1.0"?>
|
||||
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
|
||||
<channel>
|
||||
|
|
|
|||
16
mainpage.pl
16
mainpage.pl
|
|
@ -24,8 +24,8 @@ use CGI qw ( -utf8 );
|
|||
use C4::Output;
|
||||
use C4::Auth;
|
||||
use C4::Koha;
|
||||
use C4::NewsChannels; # GetNewsToDisplay
|
||||
use C4::Tags qw/get_count_by_tag_status/;
|
||||
use Koha::News;
|
||||
use Koha::Patron::Modifications;
|
||||
use Koha::Patron::Discharge;
|
||||
use Koha::Reviews;
|
||||
|
|
@ -49,13 +49,17 @@ my $homebranch;
|
|||
if (C4::Context->userenv) {
|
||||
$homebranch = C4::Context->userenv->{'branch'};
|
||||
}
|
||||
my $all_koha_news = &GetNewsToDisplay("koha",$homebranch);
|
||||
my $koha_news_count = scalar @$all_koha_news;
|
||||
my $koha_news = Koha::News->search({
|
||||
lang => 'koha',
|
||||
branchcode => [ $homebranch, undef ]
|
||||
},
|
||||
{
|
||||
order_by => 'number'
|
||||
});
|
||||
|
||||
$template->param(
|
||||
koha_news => $all_koha_news,
|
||||
koha_news_count => $koha_news_count,
|
||||
daily_quote => Koha::Quotes->get_daily_quote(),
|
||||
koha_news => $koha_news,
|
||||
daily_quote => Koha::Quotes->get_daily_quote(),
|
||||
);
|
||||
|
||||
my $branch =
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@ use Modern::Perl;
|
|||
use CGI qw ( -utf8 );
|
||||
use C4::Auth; # get_template_and_user
|
||||
use C4::Output;
|
||||
use C4::NewsChannels; # GetNewsToDisplay
|
||||
use C4::Languages qw(getTranslatedLanguages accept_language);
|
||||
use Koha::Quotes;
|
||||
use C4::Members;
|
||||
|
|
@ -61,17 +60,26 @@ elsif (C4::Context->userenv and defined $input->param('branch') and length $inpu
|
|||
}
|
||||
|
||||
my $news_id = $input->param('news_id');
|
||||
my $all_koha_news;
|
||||
my $koha_news;
|
||||
|
||||
if (defined $news_id){
|
||||
$all_koha_news = Koha::News->search({ idnew => $news_id, lang => { '!=', 'koha' } }); # get news that is not staff-only news
|
||||
if( $all_koha_news->count ) { # we only expect one btw
|
||||
$template->param( news_item => $all_koha_news->next );
|
||||
$koha_news = Koha::News->search({ idnew => $news_id, lang => { '!=', 'koha' } }); # get news that is not staff-only news
|
||||
if ( $koha_news->count > 0){
|
||||
$template->param( news_item => $koha_news->next );
|
||||
} else {
|
||||
$template->param( single_news_error => 1 );
|
||||
}
|
||||
} else {
|
||||
$all_koha_news = &GetNewsToDisplay( $template->lang, $homebranch);
|
||||
my $params;
|
||||
$params->{lang} = [ $template->lang, '' ];
|
||||
$params->{branchcode} = [ $homebranch, undef ] if $homebranch;
|
||||
$params->{-or} = [ expirationdate => { '>=' => \'NOW()' },
|
||||
expirationdate => undef ];
|
||||
$koha_news = Koha::News->search(
|
||||
$params,
|
||||
{
|
||||
order_by => 'number'
|
||||
});
|
||||
}
|
||||
|
||||
# For dashboard
|
||||
|
|
@ -104,7 +112,7 @@ if ( $patron ) {
|
|||
}
|
||||
|
||||
$template->param(
|
||||
koha_news => $all_koha_news,
|
||||
koha_news => $koha_news,
|
||||
branchcode => $homebranch,
|
||||
daily_quote => Koha::Quotes->get_daily_quote(),
|
||||
);
|
||||
|
|
|
|||
|
|
@ -22,8 +22,8 @@ use Modern::Perl;
|
|||
use CGI;
|
||||
use C4::Auth; # get_template_and_user
|
||||
use C4::Output;
|
||||
use C4::NewsChannels; # GetNewsToDisplay
|
||||
use C4::Languages qw(getTranslatedLanguages accept_language);
|
||||
use Koha::News;
|
||||
|
||||
my $input = CGI->new;
|
||||
my $dbh = C4::Context->dbh;
|
||||
|
|
@ -43,12 +43,17 @@ my ($theme, $news_lang, $availablethemes) = C4::Templates::themelanguage(C4::Con
|
|||
|
||||
my $branchcode = $input->param('branchcode');
|
||||
|
||||
my $all_koha_news = GetNewsToDisplay( $news_lang, $branchcode );
|
||||
my $koha_news_count = scalar @$all_koha_news;
|
||||
my $params;
|
||||
$params->{lang} = [ $news_lang, '' ];
|
||||
$params->{branchcode} = [ $branchcode, undef ] if $branchcode;
|
||||
$params->{-or} = [ expirationdate => { '>=' => \'NOW()' },
|
||||
expirationdate => undef ];
|
||||
my $koha_news = Koha::News->search(
|
||||
$params,
|
||||
{
|
||||
order_by => 'number'
|
||||
});
|
||||
|
||||
$template->param(
|
||||
koha_news => $all_koha_news,
|
||||
koha_news_count => $koha_news_count,
|
||||
);
|
||||
$template->param( koha_news => $koha_news );
|
||||
|
||||
output_html_with_http_headers $input, $cookie, $template->output;
|
||||
|
|
|
|||
|
|
@ -1,67 +0,0 @@
|
|||
#!/usr/bin/perl
|
||||
|
||||
use Modern::Perl;
|
||||
use Koha::Database;
|
||||
use Koha::DateUtils;
|
||||
use Koha::Libraries;
|
||||
use Koha::News;
|
||||
|
||||
use Test::More tests => 4;
|
||||
|
||||
BEGIN {
|
||||
use_ok('C4::NewsChannels');
|
||||
}
|
||||
|
||||
my $schema = Koha::Database->new->schema;
|
||||
$schema->storage->txn_begin;
|
||||
my $dbh = C4::Context->dbh;
|
||||
|
||||
# Add LIB1, if it doesn't exist.
|
||||
my $addbra = 'LIB1';
|
||||
unless ( Koha::Libraries->find($addbra) ) {
|
||||
$dbh->do( q{ INSERT INTO branches (branchcode,branchname) VALUES (?,?) },
|
||||
undef, ( $addbra, "$addbra branch" ) );
|
||||
}
|
||||
|
||||
# Add CAT1, if it doesn't exist.
|
||||
my $addcat = 'CAT1';
|
||||
{
|
||||
my $sth = $dbh->prepare( q{ SELECT categorycode FROM categories WHERE categorycode = ? } );
|
||||
$sth->execute ( $addcat );
|
||||
if ( not defined $sth->fetchrow () ) {
|
||||
$dbh->do( q{ INSERT INTO categories (categorycode,description) VALUES (?,?) },
|
||||
undef, ( $addcat, "$addcat description") );
|
||||
}
|
||||
}
|
||||
|
||||
# Add a test user if not already present.
|
||||
my $addbrwr = 'BRWR1';
|
||||
my $brwrnmbr;
|
||||
{
|
||||
my $query =
|
||||
q{ SELECT borrowernumber from borrowers WHERE surname = ? AND branchcode = ? AND categorycode = ? };
|
||||
my $sth = $dbh->prepare( $query );
|
||||
$sth->execute( ($addbrwr, $addbra, $addcat) );
|
||||
$brwrnmbr = $sth->fetchrow;
|
||||
|
||||
# Not found, let us insert it.
|
||||
if ( not defined $brwrnmbr ) {
|
||||
$dbh->do( q{ INSERT INTO borrowers (surname, address, city, branchcode, categorycode) VALUES (?, ?, ?, ?, ?) },
|
||||
undef, ($addbrwr, '(test) address', '(test) city', $addbra, $addcat) );
|
||||
|
||||
# Retrieve the njew borrower number.
|
||||
$query =
|
||||
q{ SELECT borrowernumber from borrowers WHERE surname = ? AND branchcode = ? AND categorycode = ? };
|
||||
my $sth = $dbh->prepare( $query );
|
||||
$sth->execute( ($addbrwr, $addbra, $addcat) );
|
||||
$brwrnmbr = $sth->fetchrow;
|
||||
}
|
||||
}
|
||||
|
||||
# Must have valid borrower number, or tests are meaningless.
|
||||
ok ( defined $brwrnmbr );
|
||||
|
||||
# Test GetNewsToDisplay
|
||||
my ( $opac_news_count, $arrayref_opac_news ) = GetNewsToDisplay( q{}, 'LIB1' );
|
||||
ok( $opac_news_count >= 2, 'Successfully tested GetNewsToDisplay for LIB1!' );
|
||||
|
||||
|
|
@ -28,7 +28,6 @@ use C4::Auth;
|
|||
use C4::Koha;
|
||||
use C4::Context;
|
||||
use C4::Output;
|
||||
use C4::NewsChannels;
|
||||
use C4::Languages qw(getTranslatedLanguages);
|
||||
use Date::Calc qw/Date_to_Days Today/;
|
||||
use Koha::DateUtils;
|
||||
|
|
|
|||
Loading…
Reference in New Issue