@@ -, +, @@
---------
correctly? Have you entered a news item which should not
display for this branch of logged in user?
- News which is labelled 'All Branches' or for the same branch
as the one printing the slip should display on the slip.
- THIS DOES NOT AFFECT QUICK SLIPS
- Can you edit a news item?
- Does the change save correctly?
- Can you filter based on location and branch correctly?
- Can you add a new entry correctly?
- Can you delete an entry correctly?
- Does only the news for all branches display?
- Does the news for all branches and the specific branch display?
- Does it run and all succeed?
- Does the code seem to catch the required cases?
are the license changes missing anything?
---
C4/Members.pm | 2 +-
C4/NewsChannels.pm | 33 ++++++++++----
.../prog/en/modules/tools/koha-news.tt | 46 ++++++++++++++++++--
koha-tmpl/opac-tmpl/prog/en/modules/opac-main.tt | 4 +-
mainpage.pl | 36 ++++++++-------
opac/opac-main.pl | 33 ++++++++------
t/db_dependent/NewsChannels.t | 19 ++++++--
tools/koha-news.pl | 17 ++++++--
8 files changed, 139 insertions(+), 51 deletions(-)
--- a/C4/Members.pm
+++ a/C4/Members.pm
@@ -2345,7 +2345,7 @@ sub IssueSlip {
'news' => [ map {
$_->{'timestamp'} = $_->{'newdate'};
{ opac_news => $_ }
- } @{ GetNewsToDisplay("slip") } ],
+ } @{ GetNewsToDisplay("slip",$branch) } ],
);
}
--- a/C4/NewsChannels.pm
+++ a/C4/NewsChannels.pm
@@ -125,7 +125,12 @@ sub del_opac_new {
sub get_opac_new {
my ($idnew) = @_;
my $dbh = C4::Context->dbh;
- my $query = q{ SELECT * FROM opac_news WHERE idnew = ? };
+ my $query = q{
+ SELECT opac_news.*,branches.branchname
+ FROM opac_news LEFT JOIN branches
+ ON opac_news.branchcode=branches.branchcode
+ WHERE opac_news.idnew = ?;
+ };
my $sth = $dbh->prepare($query);
$sth->execute($idnew);
my $data = $sth->fetchrow_hashref;
@@ -136,14 +141,24 @@ sub get_opac_new {
}
sub get_opac_news {
- my ($limit, $lang) = @_;
+ my ($limit, $lang, $branchcode) = @_;
my @values;
my $dbh = C4::Context->dbh;
- my $query = q{ SELECT *, timestamp AS newdate FROM opac_news };
+ my $query = q{
+ SELECT opac_news.*, branches.branchname,
+ timestamp AS newdate
+ FROM opac_news LEFT JOIN branches
+ ON opac_news.branchcode=branches.branchcode
+ };
+ $query = ' WHERE 1';
if ($lang) {
- $query.= " WHERE (lang='' OR lang=?)";
+ $query .= " AND (opac_news.lang='' OR opac_news.lang=?)";
push @values,$lang;
}
+ if ($branchcode) {
+ $query .= ' AND (opac_news.branchcode IS NULL OR opac_news.branchcode=?)';
+ push @values,$branchcode;
+ }
$query.= ' ORDER BY timestamp DESC ';
#if ($limit) {
# $query.= 'LIMIT 0, ' . $limit;
@@ -163,14 +178,15 @@ sub get_opac_news {
=head2 GetNewsToDisplay
- $news = &GetNewsToDisplay($lang);
+ $news = &GetNewsToDisplay($lang,$branch);
C<$news> is a ref to an array which containts
- all news with expirationdate > today or expirationdate is null.
+ all news with expirationdate > today or expirationdate is null
+ that is applicable for a given branch.
=cut
sub GetNewsToDisplay {
- my ($lang) = @_;
+ my ($lang,$branch) = @_;
my $dbh = C4::Context->dbh;
# SELECT *,DATE_FORMAT(timestamp, '%d/%m/%Y') AS newdate
my $query = q{
@@ -183,13 +199,14 @@ sub GetNewsToDisplay {
)
AND `timestamp` < CURRENT_DATE()+1
AND (lang = '' OR lang = ?)
+ AND (branchcode IS NULL OR branchcode = ?)
ORDER BY number
}; # expirationdate field is NOT in ISO format?
# timestamp has HH:mm:ss, CURRENT_DATE generates 00:00:00
# by adding 1, that captures today correctly.
my $sth = $dbh->prepare($query);
$lang = $lang // q{};
- $sth->execute($lang);
+ $sth->execute($lang,$branch);
my @results;
while ( my $row = $sth->fetchrow_hashref ){
$row->{newdate} = format_date($row->{newdate});
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/koha-news.tt
+++ a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/koha-news.tt
@@ -76,7 +76,7 @@ Edit news item[% ELSE %]Add news item[% END %][% ELSE %]News[% END %]