Bug 16371: Quote of the Day (QOTD) - Display in different interfaces
authorOlli-Antti Kivilahti <olli-antti.kivilahti@jns.fi>
Mon, 25 Apr 2016 08:22:04 +0000 (11:22 +0300)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Thu, 13 Aug 2020 08:15:33 +0000 (10:15 +0200)
Set 'QuoteOfTheDay'-syspref to 'opac intranet' to allow displaying news in the
opac and the staff client.

Add 'commandline' to allow news in the commandline (where applicable)

Accepts all values accepted by the C4::Context->interface()

Test plan:
1. Set 'QuoteOfTheDay' syspref as 'intranet' or 'opac' or both
2. Check that quote is visible on both mainpages

Prove t/db_dependent/Koha/Quotes.t

Sponsored-by: Koha-Suomi Oy

Signed-off-by: David Nind <david@davidnind.com>

Signed-off-by: David Nind <david@davidnind.com>

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

Koha/Quote.pm
koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref
koha-tmpl/intranet-tmpl/prog/en/modules/intranet-main.tt
koha-tmpl/intranet-tmpl/prog/en/modules/tools/quotes.tt
koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-main.tt
mainpage.pl
opac/opac-main.pl
t/db_dependent/Koha/Quotes.t

index ecfc086..f79cf79 100644 (file)
@@ -22,6 +22,7 @@ use DBI qw(:sql_types);
 
 use Koha::Database;
 use Koha::DateUtils qw(dt_from_string);
+use Koha::Exceptions::UnknownProgramState;
 
 use base qw(Koha::Object);
 
@@ -106,6 +107,31 @@ sub get_daily_quote {
     return $quote;
 }
 
+=head2 get_daily_quote_for_interface
+
+    my $quote = Koha::Quote->get_daily_quote_for_interface();
+
+Is a wrapper for get_daily_quote(), with an extra check for using the correct
+interface defined in the syspref 'QuoteOfTheDay'.
+If the current interface is not allowed to display quotes, then returns undef.
+
+=cut
+
+sub get_daily_quote_for_interface {
+    my ($self, %opts) = @_;
+    my $qotdPref = C4::Context->preference('QuoteOfTheDay');
+    my $interface = C4::Context->interface();
+    unless ($interface) {
+        my @cc = caller(3);
+        Koha::Exceptions::UnknownProgramState->throw(error => $cc[3]."()> C4::Context->interface() is not set! Don't know are you in OPAC or staff client?");
+    }
+    unless ($qotdPref =~ /$interface/) {
+        return undef;
+    }
+
+    return $self->get_daily_quote(%opts);
+}
+
 =head3 _type
 
 =cut
index 6805e6f..c47e7cd 100644 (file)
@@ -492,11 +492,12 @@ OPAC:
             - browsing and paging search results from the OPAC detail page.
         -
             - pref: QuoteOfTheDay
-              default: 0
-              choices:
-                  yes: Enable
-                  no: Disable
-            - Quote of the Day display on OPAC home page
+              default:
+              class: short
+            - Quote of the Day display in Koha.
+            - Add 'opac' to show in OPAC home page.
+            - Add 'intranet' to show in the staff client main page.
+            - Example 'opac intranet', displays QOTD in OPAC and the staff client.
         -
             - pref: OPACPopupAuthorsSearch
               default: 0
index 569af7a..24d8aa4 100644 (file)
                         [% END %]
                     </div><!-- /koha-news -->
                 [% END %]
+                [% IF ( daily_quote ) %]
+                    <div id="area-news">
+                        <h3>Quote of the Day</h3>
+                        <div class="newsitem">
+                            <span id="daily-quote-text">[% daily_quote.text %]</span><span id="daily-quote-sep"> ~ </span><span id="daily-quote-source">[% daily_quote.source %]</span>
+                        </div>
+                    </div>
+                [% END %]
             </div> <!-- /.col-sm-2 -->
             <div class="col-sm-9">
                 <div class="row">
index bf910d2..6b3e9c1 100644 (file)
                                                   "action"        : "edit",
                                               };
                                           },
-                        "height"        : "14px",
                         "placeholder"   : "Saving data...",
                     });
                },
             var aRow = oTable.fnAddData(
                 [
                     'NA', // this is hackish to fool the datatable sort routine into placing this row at the end of the list...
-                    '<input id="quoteSource" type="text" style="height:14px; width:99%" onkeydown="fnClickAddQuote(event,this.parentNode.parentNode)"/>',
-                    '<input id="quoteText" type="text" style="height:14px; width:99%" onkeydown="fnClickAddQuote(event,this.parentNode.parentNode)"/>',
+                    '<input id="quoteSource" type="text" style="width:99%" onkeydown="fnClickAddQuote(event,this.parentNode.parentNode)"/>',
+                    '<input id="quoteText" type="text" style="width:99%" onkeydown="fnClickAddQuote(event,this.parentNode.parentNode)"/>',
                     '0000-00-00 00:00:00',
                 ],
                 false
index af3e8e4..2288fc6 100644 (file)
         [% END # IF koha_news %]
 
         [% UNLESS news_item # Don't show under single news item %]
-            [% IF ( display_daily_quote && daily_quote ) %]
+            [% IF ( daily_quote ) %]
                 <div id="daily-quote">
                     <h3>Quote of the day</h3>
                     <div>
index ff234f6..090d431 100755 (executable)
@@ -32,6 +32,7 @@ use Koha::Patron::Discharge;
 use Koha::Reviews;
 use Koha::ArticleRequests;
 use Koha::ProblemReports;
+use Koha::Quote;
 
 my $query = new CGI;
 
@@ -54,7 +55,8 @@ my $koha_news_count = scalar @$all_koha_news;
 
 $template->param(
     koha_news       => $all_koha_news,
-    koha_news_count => $koha_news_count
+    koha_news_count => $koha_news_count,
+    daily_quote     => Koha::Quote->get_daily_quote_for_interface(),
 );
 
 my $branch =
index 6104d60..feaf327 100755 (executable)
@@ -73,8 +73,6 @@ if (defined $news_id){
     @all_koha_news   = &GetNewsToDisplay( $template->lang, $homebranch);
 }
 
-my $quote = Koha::Quote->get_daily_quote();   # other options are to pass in an exact quote id or select a random quote each pass... see perldoc C4::Koha
-
 # For dashboard
 my $patron = Koha::Patrons->find( $borrowernumber );
 
@@ -101,8 +99,7 @@ if ( $patron ) {
 $template->param(
     koha_news           => @all_koha_news,
     branchcode          => $homebranch,
-    display_daily_quote => C4::Context->preference('QuoteOfTheDay'),
-    daily_quote         => $quote,
+    daily_quote         => Koha::Quote->get_daily_quote_for_interface(),
 );
 
 output_html_with_http_headers $input, $cookie, $template->output;
index d4c979b..dd1477e 100644 (file)
 
 use Modern::Perl;
 use DateTime::Format::MySQL;
-use Test::More tests => 12;
+use Test::More tests => 13;
 
 use Koha::Database;
 use Koha::DateUtils qw(dt_from_string);
 use Koha::Quote;
 use Koha::Quotes;
 
+use t::lib::TestBuilder;
+use t::lib::Mocks;
+
 BEGIN {
     use_ok('Koha::Quote');
 }
@@ -76,3 +79,41 @@ my $quote_6 = Koha::Quote->new({ id => 6, source => 'George Washington', text =>
 
 $quote = Koha::Quote->get_daily_quote();
 is( $quote->{id}, 6, ' get_daily_quote returns the only existing quote' );
+
+$schema->storage->txn_rollback;
+
+subtest "get_daily_quote_for_interface" => sub {
+
+    plan tests => 3;
+
+    $schema->storage->txn_begin;
+
+    my ($quote);
+    my $quote_1 = Koha::Quote->new({ id => 10, source => 'Dusk And Her Embrace', text => 'Unfurl thy limbs breathless succubus<br/>How the full embosomed fog<br/>Imparts the night to us....', timestamp =>  dt_from_string })->store;
+
+    my $expected_quote = {
+        id          => 10,
+        source      => 'Dusk And Her Embrace',
+        text        => 'Unfurl thy limbs breathless succubus<br/>How the full embosomed fog<br/>Imparts the night to us....',
+        timestamp   => DateTime::Format::MySQL->format_datetime(dt_from_string),
+    };
+
+    t::lib::Mocks::mock_preference('QuoteOfTheDay', '');
+
+    ##Set interface and get nothing because syspref is not set.
+    C4::Context->interface('opac');
+    $quote = Koha::Quote->get_daily_quote_for_interface(id => $quote_1->id);
+    ok(not($quote), "'QuoteOfTheDay'-syspref not set so nothing returned");
+
+    ##Set 'QuoteOfTheDay'-syspref to not include current interface 'opac'
+    t::lib::Mocks::mock_preference('QuoteOfTheDay', 'intra commandline sip2 api yo-mama');
+    $quote = Koha::Quote->get_daily_quote_for_interface(id => $quote_1->id);
+    ok(not($quote), "'QuoteOfTheDay'-syspref doesn't include 'opac'");
+
+    ##Set 'QuoteOfTheDay'-syspref to include current interface 'opac'
+    t::lib::Mocks::mock_preference('QuoteOfTheDay', 'intraopaccommandline');
+    $quote = Koha::Quote->get_daily_quote_for_interface(id => $quote_1->id);
+    is_deeply($quote, $expected_quote, "Got the expected quote");
+
+    $schema->storage->txn_rollback;
+};