Bug 2093: Add OPAC Summary for logged-in users
authorAleisha Amohia <aleishaamohia@hotmail.com>
Wed, 26 Apr 2017 05:18:13 +0000 (05:18 +0000)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Fri, 27 Oct 2017 17:09:04 +0000 (14:09 -0300)
This patch adds a summary to the OPAC once the user has logged in that
shows the users number of checkouts, overdues, holds pending, holds
waiting and total fines. We also have a syspref OPACUserSummary to turn
this feature on and off. Default is ON.

To test:
1) Apply patch and update database
2) Set up some checkouts, overdues, holds pending AND waiting and fines
for a user
3) Log into OPAC as that user, see summary. Confirm links all work as
expected
4) Confirm that if there are no checkouts / overdues etc that the link
disappears from the summary
5) Turn OPACUserSummary OFF and confirm the summary does not show on the
mainpage.

Sponsored-by: Catalyst IT

Signed-off-by: Hugo Agud <hagud@orex.es>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>

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

installer/data/mysql/atomicupdate/bug_2093_-_add_OPACUserSummary_syspref.sql [new file with mode: 0644]
installer/data/mysql/sysprefs.sql
koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref
koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-main.tt
opac/opac-main.pl

diff --git a/installer/data/mysql/atomicupdate/bug_2093_-_add_OPACUserSummary_syspref.sql b/installer/data/mysql/atomicupdate/bug_2093_-_add_OPACUserSummary_syspref.sql
new file mode 100644 (file)
index 0000000..bd8bba3
--- /dev/null
@@ -0,0 +1 @@
+INSERT IGNORE INTO systempreferences (`variable`,`value`,`options`,`explanation`,`type`) VALUES ('OPACUserSummary', 1, NULL, "Show the summary of a logged in user's checkouts, overdues, holds and fines on the mainpage", 'YesNo');
index 91c125e..dba207c 100644 (file)
@@ -395,6 +395,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `
 ('OPACUserCSS','',NULL,'Add CSS to be included in the OPAC in an embedded <style> tag.','free'),
 ('OPACUserJS','','70|10','Define custom javascript for inclusion in OPAC','Textarea'),
 ('opacuserlogin','1',NULL,'Enable or disable display of user login features','YesNo'),
+('OPACUserSummary', 1, NULL, "Show the summary of a logged in user's checkouts, overdues, holds and fines on the mainpage", 'YesNo'),
 ('OPACViewOthersSuggestions','0',NULL,'If ON, allows all suggestions to be displayed in the OPAC','YesNo'),
 ('OPACXSLTDetailsDisplay','default','','Enable XSL stylesheet control over details page display on OPAC','Free'),
 ('OPACXSLTListsDisplay','default','','Enable XSLT stylesheet control over lists pages display on OPAC','Free'),
index d76c27b..c44b109 100644 (file)
@@ -1,6 +1,12 @@
 OPAC:
     Appearance:
         -
+            - pref: OPACUserSummary
+              choices:
+                  yes: Show
+                  no: "Don't show"
+            - "a summary of a logged in user's checkouts, overdues, holds and fines on the mainpage"
+        -
             - For search results in the OPAC, show the item's
             - pref: OPACResultsLibrary
               choices:
index ba5372e..e60087b 100644 (file)
@@ -1,5 +1,6 @@
 [% USE Koha %]
 [% USE Branches %]
+[% USE Price %]
 [% INCLUDE 'doc-head-open.inc' %]
 <title>[% IF ( LibraryNameTitle ) %][% LibraryNameTitle %][% ELSE %]Koha online[% END %] catalog</title>
 [% INCLUDE 'doc-head-close.inc' %]
                                 </form>
                             </div> <!-- /#login -->
                         [% END # /casAuthentication %]
-                    [% END # / loggedinusername %]
+                    [% ELSE %]
+                        [% IF Koha.Preference('OPACUserSummary') %]
+                            <div id="user_summary">
+                                <h1>Welcome, <a href="/cgi-bin/koha/opac-user.pl"><span class="loggedinusername">[% USER_INFO.title %] [% USER_INFO.firstname %] [% USER_INFO.surname %]</span></a></h1>
+                                <ul id="user_summary_shortcuts">
+                                    [% IF checkouts && checkouts > 0 %]
+                                        <li><a href="/cgi-bin/koha/opac-user.pl">[% checkouts %] checkout(s)</a></li>
+                                    [% END %]
+                                    [% IF overdues && overdues > 0 %]
+                                        <li><a href="/cgi-bin/koha/opac-user.pl">[% overdues %] overdue(s)</a></li>
+                                    [% END %]
+                                    [% IF holds_pending && holds_pending > 0 %]
+                                        <li><a href="/cgi-bin/koha/opac-user.pl">[% holds_pending %] hold(s) pending</a></li>
+                                    [% END %]
+                                    [% IF holds_waiting && holds_waiting > 0 %]
+                                        <li><a href="/cgi-bin/koha/opac-user.pl">[% holds_waiting %] hold(s) waiting</a></li>
+                                    [% END %]
+                                    [% IF total_owing && total_owing > 0 %]
+                                        <li><a href="/cgi-bin/koha/opac-account.pl">[% total_owing | $Price %] due</a></li>
+                                    [% END %]
+                                </ul>
+                            </div>
+                        [% END %]
+                    [% END # /loggedinusername %]
                 [% END # /opacuserlogin %]
                 [% IF ( OpacNavRight ) %]
                     <div id="opacnavright">
index 2f1f18c..d63392b 100755 (executable)
@@ -25,6 +25,10 @@ use C4::Output;
 use C4::NewsChannels;    # GetNewsToDisplay
 use C4::Languages qw(getTranslatedLanguages accept_language);
 use C4::Koha qw( GetDailyQuote );
+use C4::Members;
+use C4::Overdues;
+use C4::Reserves;
+use Koha::Checkouts;
 
 my $input = new CGI;
 my $dbh   = C4::Context->dbh;
@@ -62,7 +66,24 @@ my $koha_news_count = scalar @$all_koha_news;
 
 my $quote = GetDailyQuote();   # other options are to pass in an exact quote id or select a random quote each pass... see perldoc C4::Koha
 
+my $checkouts = Koha::Checkouts->search({ borrowernumber => $borrowernumber })->count;
+my ( $overdues_count, $overdues ) = checkoverdues($borrowernumber);
+my @holds = GetReservesFromBorrowernumber($borrowernumber);
+my $holds_pending = 0;
+foreach my $hold (@holds) {
+    if (not defined($hold->{found})){
+        $holds_pending++;
+    }
+}
+my @holds_waiting = GetReservesFromBorrowernumber($borrowernumber, 'W');
+my ( $total , $accts, $numaccts) = GetMemberAccountRecords( $borrowernumber );
+
 $template->param(
+    checkouts           => $checkouts,
+    overdues            => $overdues_count,
+    holds_pending       => $holds_pending,
+    holds_waiting       => scalar @holds_waiting,
+    total_owing         => $total,
     koha_news           => $all_koha_news,
     koha_news_count     => $koha_news_count,
     branchcode          => $homebranch,