From f6ab74d78f4966391f43a93e5d069ab73f44a49e Mon Sep 17 00:00:00 2001
From: Martin Persson <xarragon@gmail.com>
Date: Wed, 16 Dec 2015 15:44:38 +0100
Subject: [PATCH] Bug 15385: News archive
Adds ability to new old, expired news items in an archive.
Test plan:
* Add several news items, some of which should have an expired date.
* Go to Global system preferences, Enable 'NewsArchiveEnabled'.
* Go to the OPAC main page. The non-expired news should be shown.
* A link should be shown in the lower right-hand side of the page,
"Archived news". Click it. ALL news items should be shown.
* Go back to Global system preferences, Disable 'NewsArchiveEnabled'.
* No 'Archived news' link should be shown on the OPAC main page.
* If you manually add '?id=all' to the OPAC main page URL,
the standard page should be shown and the parameter ignored.
Updates:
* Renamed 'id' to 'news_id' (from update in 14272)
* Added breadcrumbs
Sponsored-By: Halland County Library
---
installer/data/mysql/sysprefs.sql | 1 +
.../prog/en/modules/admin/preferences/tools.pref | 8 ++++++++
koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-main.tt | 4 ++++
opac/opac-main.pl | 12 +++++++++---
4 files changed, 22 insertions(+), 3 deletions(-)
diff --git a/installer/data/mysql/sysprefs.sql b/installer/data/mysql/sysprefs.sql
index 96ea9ad..ad13682 100644
--- a/installer/data/mysql/sysprefs.sql
+++ b/installer/data/mysql/sysprefs.sql
@@ -230,6 +230,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `
('minPasswordLength','3',NULL,'Specify the minimum length of a patron/staff password','free'),
('NewItemsDefaultLocation','','','If set, all new items will have a location of the given Location Code ( Authorized Value type LOC )',''),
('NewsAuthorDisplay','none','none|opac|staff|both','Display the author name for news items.','Choice'),
+('NewsArchiveEnabled','0',NULL,'Enables users to view expired news items.','YesNo'),
('noissuescharge','5','','Define maximum amount withstanding before check outs are blocked','Integer'),
('noItemTypeImages','0',NULL,'If ON, disables item-type images','YesNo'),
('NoLoginInstructions', '', '60|10', 'Instructions to display on the OPAC login form when a patron is not logged in', 'Textarea'),
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/tools.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/tools.pref
index 5a3ddce..30d5ad5 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/tools.pref
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/tools.pref
@@ -21,3 +21,11 @@ Tools:
staff: "Staff client only"
both: "Both OPAC and staff client"
-
+ -
+ -
+ - pref: NewsArchiveEnabled
+ choices:
+ yes: "Enable"
+ no: "Disable"
+ - the news archive for expired items.
+ -
diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-main.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-main.tt
index 42908ef..d1c840e 100644
--- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-main.tt
+++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-main.tt
@@ -16,6 +16,7 @@
<li><a href="#">
[% SWITCH news_type %]
[% CASE 'news_item' %]News item
+ [% CASE 'news_archive' %]News archive
[% END %]
</a>
[% END %]
@@ -62,6 +63,9 @@
[% SET branchcode = Branches.GetLoggedInBranchcode() %]
<a href="[% OPACBaseURL %]/cgi-bin/koha/opac-news-rss.pl?branchcode=[% branchcode %]"><img src="[% interface %]/[% theme %]/images/feed-icon-16x16.png"></a>
RSS feed for [% IF ( loggedinusername ) %][% Branches.GetName( branchcode ) %] <i>and</i> [% END %] system-wide library news.
+
+ [% IF ( Koha.Preference( 'NewsArchiveEnabled' ) ) %]
+ <a href="/cgi-bin/koha/opac-main.pl?news_id=all" style="float: right">Archived news</a>[% END %]
</div>
[% END %]
diff --git a/opac/opac-main.pl b/opac/opac-main.pl
index d690b74..11a14e3 100755
--- a/opac/opac-main.pl
+++ b/opac/opac-main.pl
@@ -55,9 +55,15 @@ if (C4::Context->userenv) {
my $news_id = $input->param('news_id');
my ($all_koha_news, $koha_news_count, $news_type);
if (defined $news_id && length $news_id) {
- $all_koha_news = &GetNewsToDisplay($news_lang, $homebranch, undef, $news_id);
- $koha_news_count = 1;
- $news_type = 'news_item';
+ if ($news_id eq 'all' && C4::Context->preference('NewsArchiveEnabled')) {
+ $all_koha_news = get_opac_news(undef, $news_lang, $homebranch);
+ $koha_news_count = scalar @$all_koha_news;
+ $news_type = 'news_archive';
+ } else {
+ $all_koha_news = [ get_opac_new($news_id) ];
+ $koha_news_count = 1;
+ $news_type = 'news_item';
+ }
} else {
$all_koha_news = &GetNewsToDisplay($news_lang, $homebranch);
$koha_news_count = scalar @$all_koha_news;
--
2.1.4