View | Details | Raw Unified | Return to bug 16371
Collapse All | Expand All

(-)a/Koha/Quote.pm (+26 lines)
Lines 22-27 use DBI qw(:sql_types); Link Here
22
22
23
use Koha::Database;
23
use Koha::Database;
24
use Koha::DateUtils qw(dt_from_string);
24
use Koha::DateUtils qw(dt_from_string);
25
use Koha::Exceptions::UnknownProgramState;
25
26
26
use base qw(Koha::Object);
27
use base qw(Koha::Object);
27
28
Lines 106-111 sub get_daily_quote { Link Here
106
    return $quote;
107
    return $quote;
107
}
108
}
108
109
110
=head2 get_daily_quote_for_interface
111
112
    my $quote = Koha::Quote->get_daily_quote_for_interface();
113
114
Is a wrapper for get_daily_quote(), with an extra check for using the correct
115
interface defined in the syspref 'QuoteOfTheDay'.
116
If the current interface is not allowed to display quotes, then returns undef.
117
118
=cut
119
120
sub get_daily_quote_for_interface {
121
    my ($self, %opts) = @_;
122
    my $qotdPref = C4::Context->preference('QuoteOfTheDay');
123
    my $interface = C4::Context->interface();
124
    unless ($interface) {
125
        my @cc = caller(3);
126
        Koha::Exceptions::UnknownProgramState->throw(error => $cc[3]."()> C4::Context->interface() is not set! Don't know are you in OPAC or staff client?");
127
    }
128
    unless ($qotdPref =~ /$interface/) {
129
        return undef;
130
    }
131
132
    return $self->get_daily_quote(%opts);
133
}
134
109
=head3 _type
135
=head3 _type
110
136
111
=cut
137
=cut
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref (-5 / +6 lines)
Lines 529-539 OPAC: Link Here
529
            - browsing and paging search results from the OPAC detail page.
529
            - browsing and paging search results from the OPAC detail page.
530
        -
530
        -
531
            - pref: QuoteOfTheDay
531
            - pref: QuoteOfTheDay
532
              default: 0
532
              default:
533
              choices:
533
              class: short
534
                  yes: Enable
534
            - Quote of the Day display in Koha.
535
                  no: Disable
535
            - Add 'opac' to show in OPAC home page.
536
            - Quote of the Day display on OPAC home page
536
            - Add 'intranet' to show in the staff client main page.
537
            - Example 'opac intranet', displays QOTD in OPAC and the staff client.
537
        -
538
        -
538
            - pref: OPACPopupAuthorsSearch
539
            - pref: OPACPopupAuthorsSearch
539
              default: 0
540
              default: 0
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/intranet-main.tt (+8 lines)
Lines 34-39 Link Here
34
                        [% END %]
34
                        [% END %]
35
                    </div><!-- /koha-news -->
35
                    </div><!-- /koha-news -->
36
                [% END %]
36
                [% END %]
37
                [% IF ( daily_quote ) %]
38
                    <div id="area-news">
39
                        <h3>Quote of the Day</h3>
40
                        <div class="newsitem">
41
                            <span id="daily-quote-text">[% daily_quote.text %]</span><span id="daily-quote-sep"> ~ </span><span id="daily-quote-source">[% daily_quote.source %]</span>
42
                        </div>
43
                    </div>
44
                [% END %]
37
            </div> <!-- /.col-sm-2 -->
45
            </div> <!-- /.col-sm-2 -->
38
            <div class="col-sm-9">
46
            <div class="col-sm-9">
39
                <div class="row">
47
                <div class="row">
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/quotes.tt (-3 / +2 lines)
Lines 122-128 Link Here
122
                                                  "action"        : "edit",
122
                                                  "action"        : "edit",
123
                                              };
123
                                              };
124
                                          },
124
                                          },
125
                        "height"        : "14px",
126
                        "placeholder"   : "Saving data...",
125
                        "placeholder"   : "Saving data...",
127
                    });
126
                    });
128
               },
127
               },
Lines 190-197 Link Here
190
            var aRow = oTable.fnAddData(
189
            var aRow = oTable.fnAddData(
191
                [
190
                [
192
                    'NA', // this is hackish to fool the datatable sort routine into placing this row at the end of the list...
191
                    'NA', // this is hackish to fool the datatable sort routine into placing this row at the end of the list...
193
                    '<input id="quoteSource" type="text" style="height:14px; width:99%" onkeydown="fnClickAddQuote(event,this.parentNode.parentNode)"/>',
192
                    '<input id="quoteSource" type="text" style="width:99%" onkeydown="fnClickAddQuote(event,this.parentNode.parentNode)"/>',
194
                    '<input id="quoteText" type="text" style="height:14px; width:99%" onkeydown="fnClickAddQuote(event,this.parentNode.parentNode)"/>',
193
                    '<input id="quoteText" type="text" style="width:99%" onkeydown="fnClickAddQuote(event,this.parentNode.parentNode)"/>',
195
                    '0000-00-00 00:00:00',
194
                    '0000-00-00 00:00:00',
196
                ],
195
                ],
197
                false
196
                false
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-main.tt (-1 / +1 lines)
Lines 141-147 Link Here
141
        [% END # IF koha_news %]
141
        [% END # IF koha_news %]
142
142
143
        [% UNLESS news_item # Don't show under single news item %]
143
        [% UNLESS news_item # Don't show under single news item %]
144
            [% IF ( display_daily_quote && daily_quote ) %]
144
            [% IF ( daily_quote ) %]
145
                <div id="daily-quote">
145
                <div id="daily-quote">
146
                    <h3>Quote of the day</h3>
146
                    <h3>Quote of the day</h3>
147
                    <div>
147
                    <div>
(-)a/mainpage.pl (-1 / +3 lines)
Lines 32-37 use Koha::Patron::Discharge; Link Here
32
use Koha::Reviews;
32
use Koha::Reviews;
33
use Koha::ArticleRequests;
33
use Koha::ArticleRequests;
34
use Koha::ProblemReports;
34
use Koha::ProblemReports;
35
use Koha::Quote;
35
36
36
my $query = new CGI;
37
my $query = new CGI;
37
38
Lines 54-60 my $koha_news_count = scalar @$all_koha_news; Link Here
54
55
55
$template->param(
56
$template->param(
56
    koha_news       => $all_koha_news,
57
    koha_news       => $all_koha_news,
57
    koha_news_count => $koha_news_count
58
    koha_news_count => $koha_news_count,
59
    daily_quote     => Koha::Quote->get_daily_quote_for_interface(),
58
);
60
);
59
61
60
my $branch =
62
my $branch =
(-)a/opac/opac-main.pl (-4 / +1 lines)
Lines 73-80 if (defined $news_id){ Link Here
73
    @all_koha_news   = &GetNewsToDisplay( $template->lang, $homebranch);
73
    @all_koha_news   = &GetNewsToDisplay( $template->lang, $homebranch);
74
}
74
}
75
75
76
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
77
78
# For dashboard
76
# For dashboard
79
my $patron = Koha::Patrons->find( $borrowernumber );
77
my $patron = Koha::Patrons->find( $borrowernumber );
80
78
Lines 101-108 if ( $patron ) { Link Here
101
$template->param(
99
$template->param(
102
    koha_news           => @all_koha_news,
100
    koha_news           => @all_koha_news,
103
    branchcode          => $homebranch,
101
    branchcode          => $homebranch,
104
    display_daily_quote => C4::Context->preference('QuoteOfTheDay'),
102
    daily_quote         => Koha::Quote->get_daily_quote_for_interface(),
105
    daily_quote         => $quote,
106
);
103
);
107
104
108
# If GoogleIndicTransliteration system preference is On Set parameter to load Google's javascript in OPAC search screens
105
# If GoogleIndicTransliteration system preference is On Set parameter to load Google's javascript in OPAC search screens
(-)a/t/db_dependent/Koha/Quotes.t (-2 / +42 lines)
Lines 17-29 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
use DateTime::Format::MySQL;
19
use DateTime::Format::MySQL;
20
use Test::More tests => 12;
20
use Test::More tests => 13;
21
21
22
use Koha::Database;
22
use Koha::Database;
23
use Koha::DateUtils qw(dt_from_string);
23
use Koha::DateUtils qw(dt_from_string);
24
use Koha::Quote;
24
use Koha::Quote;
25
use Koha::Quotes;
25
use Koha::Quotes;
26
26
27
use t::lib::TestBuilder;
28
use t::lib::Mocks;
29
27
BEGIN {
30
BEGIN {
28
    use_ok('Koha::Quote');
31
    use_ok('Koha::Quote');
29
}
32
}
Lines 76-78 my $quote_6 = Koha::Quote->new({ id => 6, source => 'George Washington', text => Link Here
76
79
77
$quote = Koha::Quote->get_daily_quote();
80
$quote = Koha::Quote->get_daily_quote();
78
is( $quote->{id}, 6, ' get_daily_quote returns the only existing quote' );
81
is( $quote->{id}, 6, ' get_daily_quote returns the only existing quote' );
79
- 
82
83
$schema->storage->txn_rollback;
84
85
subtest "get_daily_quote_for_interface" => sub {
86
87
    plan tests => 3;
88
89
    $schema->storage->txn_begin;
90
91
    my ($quote);
92
    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;
93
94
    my $expected_quote = {
95
        id          => 10,
96
        source      => 'Dusk And Her Embrace',
97
        text        => 'Unfurl thy limbs breathless succubus<br/>How the full embosomed fog<br/>Imparts the night to us....',
98
        timestamp   => DateTime::Format::MySQL->format_datetime(dt_from_string),
99
    };
100
101
    t::lib::Mocks::mock_preference('QuoteOfTheDay', '');
102
103
    ##Set interface and get nothing because syspref is not set.
104
    C4::Context->interface('opac');
105
    $quote = Koha::Quote->get_daily_quote_for_interface(id => $quote_1->id);
106
    ok(not($quote), "'QuoteOfTheDay'-syspref not set so nothing returned");
107
108
    ##Set 'QuoteOfTheDay'-syspref to not include current interface 'opac'
109
    t::lib::Mocks::mock_preference('QuoteOfTheDay', 'intra commandline sip2 api yo-mama');
110
    $quote = Koha::Quote->get_daily_quote_for_interface(id => $quote_1->id);
111
    ok(not($quote), "'QuoteOfTheDay'-syspref doesn't include 'opac'");
112
113
    ##Set 'QuoteOfTheDay'-syspref to include current interface 'opac'
114
    t::lib::Mocks::mock_preference('QuoteOfTheDay', 'intraopaccommandline');
115
    $quote = Koha::Quote->get_daily_quote_for_interface(id => $quote_1->id);
116
    is_deeply($quote, $expected_quote, "Got the expected quote");
117
118
    $schema->storage->txn_rollback;
119
};

Return to bug 16371