From f1b9cec6c6f888a473b8a0c9be6cf9050a56fc97 Mon Sep 17 00:00:00 2001 From: Martin Persson Date: Fri, 22 May 2015 14:45:47 +0200 Subject: [PATCH 3/3] Bug 14248: Optionally display the author for news Based on the changes in bugs 14246 and 14247, this final patch enables the display of the user's title, first- and surname for individual news items, making Koha suitable as a simple blog. Depends on patch for bug 14247. Sponsored-by: Halland County Library --- C4/NewsChannels.pm | 14 +++++++++++--- .../intranet-tmpl/prog/en/modules/help/tools/koha-news.tt | 2 ++ koha-tmpl/intranet-tmpl/prog/en/modules/intranet-main.tt | 2 +- koha-tmpl/intranet-tmpl/prog/en/modules/tools/koha-news.tt | 2 ++ koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-main.tt | 2 +- mainpage.pl | 7 +++++-- opac/opac-main.pl | 2 ++ 7 files changed, 24 insertions(+), 7 deletions(-) diff --git a/C4/NewsChannels.pm b/C4/NewsChannels.pm index 8694c1b..ddf2d34 100644 --- a/C4/NewsChannels.pm +++ b/C4/NewsChannels.pm @@ -146,9 +146,13 @@ sub get_opac_news { my $dbh = C4::Context->dbh; my $query = q{ SELECT opac_news.*, branches.branchname, - timestamp AS newdate + timestamp AS newdate, + borrowers.title AS author_title, + borrowers.firstname AS author_firstname, + borrowers.surname AS author_surname FROM opac_news LEFT JOIN branches ON opac_news.branchcode=branches.branchcode + LEFT JOIN borrowers on borrowers.borrowernumber = opac_news.borrowernumber }; $query .= ' WHERE 1'; if ($lang) { @@ -190,8 +194,12 @@ sub GetNewsToDisplay { my $dbh = C4::Context->dbh; # SELECT *,DATE_FORMAT(timestamp, '%d/%m/%Y') AS newdate my $query = q{ - SELECT *,timestamp AS newdate + SELECT opac_news.*,timestamp 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 @@ -199,7 +207,7 @@ sub GetNewsToDisplay { ) AND DATE(timestamp) < DATE_ADD(CURDATE(), INTERVAL 1 DAY) AND (lang = '' OR lang = ?) - AND (branchcode IS NULL OR branchcode = ?) + AND (opac_news.branchcode IS NULL OR opac_news.branchcode = ?) ORDER BY number }; # expirationdate field is NOT in ISO format? # timestamp has HH:mm:ss, CURRENT_DATE generates 00:00:00 diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/help/tools/koha-news.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/help/tools/koha-news.tt index fca0286..56121d9 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/help/tools/koha-news.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/help/tools/koha-news.tt @@ -20,6 +20,8 @@
  • News in the OPAC will appear above the OpacMainUserBlock
  • News in the Staff Client will appear on the far left of the screen
  • News on the circulation receipts will appear below the items that are checked out
  • +
  • The news item's author will be set to the currently logged in user.
  • +
  • The system preference 'NewsAuthorDisplay' can be used to hide or show the author for news item.
  • See the full documentation for News in the manual (online).

    diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/intranet-main.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/intranet-main.tt index 8440526..73abbb6 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/intranet-main.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/intranet-main.tt @@ -173,7 +173,7 @@ [% FOREACH koha_new IN koha_news %]

    [% koha_new.title %]

    [% koha_new.new %]

    -

    Posted on [% koha_new.newdate %] +

    Posted on [% koha_new.newdate %][% IF( display_news_author && koha_new.borrowernumber ) %] by [% koha_new.author_title %] [% koha_new.author_firstname %] [% koha_new.author_surname %]
    [% END %] [% IF ( CAN_user_tools ) %] Edit | Delete diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/koha-news.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/koha-news.tt index af28ee8..073d9db 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/koha-news.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/koha-news.tt @@ -213,6 +213,7 @@ Edit news item[% ELSE %]Add news item[% END %][% ELSE %]News[% END %]

    Publication date Expiration date Title + Author News   @@ -244,6 +245,7 @@ Edit news item[% ELSE %]Add news item[% END %][% ELSE %]News[% END %] [% opac_new.newdate | $KohaDates %] [% opac_new.expirationdate | $KohaDates %] [% IF ( opac_new.expired ) %](expired)[% END %] [% opac_new.title %] + [% opac_new.author_title %] [% opac_new.author_firstname %] [% opac_new.author_surname %] [% opac_new.new %] 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 e977d27..cb61e7b 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-main.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-main.tt @@ -44,7 +44,7 @@

    [% koha_new.title %]

    [% koha_new.new %]
    -
    (published on [% koha_new.newdate %])
    +
    (published on [% koha_new.newdate %][% IF ( display_news_author && koha_new.borrowernumber ) %] by [% koha_new.author_title %] [% koha_new.author_firstname %] [% koha_new.author_surname %][% END %])
    [% END %] diff --git a/mainpage.pl b/mainpage.pl index 1ccffad..e38548a 100755 --- a/mainpage.pl +++ b/mainpage.pl @@ -49,10 +49,13 @@ if (C4::Context->userenv) { } my $all_koha_news = &GetNewsToDisplay("koha",$homebranch); my $koha_news_count = scalar @$all_koha_news; +my $news_author = C4::Context->preference('NewsAuthorDisplay'); $template->param( - koha_news => $all_koha_news, - koha_news_count => $koha_news_count + koha_news => $all_koha_news, + display_news_author => ($news_author eq 'staff') + || ($news_author eq 'both'), + koha_news_count => $koha_news_count ); my $branch = diff --git a/opac/opac-main.pl b/opac/opac-main.pl index 9db64cb..091e79a 100755 --- a/opac/opac-main.pl +++ b/opac/opac-main.pl @@ -54,6 +54,7 @@ if (C4::Context->userenv) { } my $all_koha_news = &GetNewsToDisplay($news_lang,$homebranch); my $koha_news_count = scalar @$all_koha_news; +my $news_author = C4::Context->preference('NewsAuthorDisplay'); my $quote = GetDailyQuote(); # other options are to pass in an exact quote id or select a random quote each pass... see perldoc C4::Koha @@ -61,6 +62,7 @@ $template->param( koha_news => $all_koha_news, koha_news_count => $koha_news_count, display_daily_quote => C4::Context->preference('QuoteOfTheDay'), + display_news_author => ($news_author eq 'opac') || ($news_author eq 'both'), daily_quote => $quote, ); -- 2.1.4