Bug 11256: Opac: Set a number of items to display on a biblio detail page.
authorJonathan Druart <jonathan.druart@biblibre.com>
Fri, 15 Nov 2013 11:02:53 +0000 (12:02 +0100)
committerGalen Charlton <gmc@esilibrary.com>
Fri, 21 Feb 2014 18:34:27 +0000 (18:34 +0000)
Currently, the number of items to display is hardcoded (50).
But the perl script loads all items before to check if the number of
items is oversized.

This patch adds a new pref OpacMaxItemsToDisplay (default to 50). If the
*total* number of items for a biblio is greater, no item is displayed
and a link allows to display all items.

Test plan:
1/ search a biblio with many items
2/ set the pref according the number of items you want to display
3/ verify the items are not displayed if the number of items is greater
the pref value
4/ enable the OpacSeparateHoldings pref and verify the items are
displayed in different tabs (if items have different locations).

Signed-off-by: Chris Cormack <chris@bigballofwax.co.nz>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
installer/data/mysql/sysprefs.sql
installer/data/mysql/updatedatabase.pl
koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref
koha-tmpl/opac-tmpl/prog/en/modules/opac-detail.tt
opac/opac-detail.pl

index 89bf368..2c45345 100644 (file)
@@ -240,6 +240,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `
 ('OpacMaintenance','0','','If ON, enables maintenance warning in OPAC','YesNo'),
 ('OpacMainUserBlock','Welcome to Koha...\r\n<hr>','70|10','A user-defined block of HTML  in the main content area of the opac main page','Textarea'),
 ('OpacMainUserBlockMobile','',NULL,'Show the following HTML in its own column on the main page of the OPAC (mobile version):','free'),
+('OpacMaxItemsToDisplay','50','','Max items to display at the OPAC on a biblio detail','Integer'),
 ('OPACMobileUserCSS','',NULL,'Include the following CSS for the mobile view on all pages in the OPAC:','free'),
 ('OPACMySummaryHTML','','70|10','Enter the HTML that will appear in a column on the \'my summary\' and \'my reading history\' tabs when a user is logged in to the OPAC. Enter {BIBLIONUMBER}, {TITLE}, {AUTHOR}, or {ISBN} in place of their respective variables in the HTML. Leave blank to disable.','Textarea'),
 ('OpacNav','Important links here.','70|10','Use HTML tags to add navigational links to the left-hand navigational bar in OPAC','Textarea'),
index baf17e5..ccc7e68 100755 (executable)
@@ -8005,6 +8005,13 @@ if ( CheckVersion($DBversion) ) {
     $dbh->{RaiseError} = 0;
 }
 
+$DBversion = "3.15.00.XXX";
+if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
+    $dbh->do("INSERT IGNORE INTO systempreferences (variable,value,options,explanation,type) VALUES('OpacMaxItemsToDisplay','50','','Max items to display at the OPAC on a biblio detail','Integer')");
+    print "Upgrade to $DBversion done (Bug 11256: Add system preference OpacMaxItemsToDisplay)\n";
+    SetVersion($DBversion);
+}
+
 =head1 FUNCTIONS
 
 =head2 TableExists($table)
index 1364ff1..9c1fc1f 100644 (file)
@@ -286,6 +286,12 @@ OPAC:
                   yes: Show
                   no: Don't show
             - "the name of the staff member who managed a suggestion in OPAC."
+        -
+            - Display
+            - pref: OpacMaxItemsToDisplay
+              class: integer
+            - items on the biblio detail page (if the biblio has more items, a link allow to display all items).
+
     Features:
         -
             - pref: opacuserlogin
index 3f3ade7..26bbbc4 100644 (file)
@@ -938,7 +938,7 @@ YAHOO.util.Event.onContentReady("furtherm", function () {
 
 <ul>   
     [% IF ( defaulttab == 'holdings' ) %]<li id="tab_holdings" class="ui-tabs-selected">[% ELSE %]<li id="tab_holdings">[% END %]
-        <a href="#holdings">[% IF SeparateHoldings %][% LoginBranchname %] holdings[% ELSE %]Holdings[% END %] ( [% itemloop.size || 0 %] )</a>
+        <a href="#holdings">[% IF SeparateHoldings %][% LoginBranchname %] holdings[% ELSE %]Holdings[% END %][% UNLESS too_many_items %]  ( [% itemloop.size || 0 %] )[% END %]</a>
     </li>
     [% IF (SeparateHoldings) %]
         <li><a href="#otherholdings">Other holdings ( [% otheritemloop.size || 0 %] )</a></li>
@@ -1038,12 +1038,10 @@ YAHOO.util.Event.onContentReady("furtherm", function () {
 
 
 <div id="holdings">
-[% IF ( itemloop.size ) %]
-    [% IF ( lotsofholdingsitems ) %]
-        <p>This record has many physical items. <a href="/cgi-bin/koha/opac-detail.pl?biblionumber=[% biblionumber %]&amp;viewallitems=1#holdings">Click here to view them all.</a></p>
-    [% ELSE %]
-        [% INCLUDE items_table items=itemloop tab="holdings" %]
-    [% END %]
+[% IF too_many_items %]
+    <p>This record has many physical items ([% items_count %]). <a href="/cgi-bin/koha/opac-detail.pl?biblionumber=[% biblionumber %]&amp;viewallitems=1">Click here to view them all.</a></p>
+[% ELSIF ( itemloop.size ) %]
+    [% INCLUDE items_table items=itemloop tab="holdings" %]
     [% IF holds_count.defined || priority %]
     <div id="bib_holds">
         [% IF holds_count.defined %]
@@ -1075,12 +1073,8 @@ YAHOO.util.Event.onContentReady("furtherm", function () {
 
 [% IF (SeparateHoldings) %]
     <div id="otherholdings">
-        [% IF (otheritemloop.size) %]
-            [% IF lotsofothersholdingsitems %]
-                <p>This record has many physical items. <a href="/cgi-bin/koha/opac-detail.pl?biblionumber=[% biblionumber %]&amp;viewallitems=1#otherholdings">Click here to view them all.</a></p>
-            [% ELSE %]
-                [% INCLUDE items_table items=otheritemloop tab="otherholdings" %]
-            [% END %]
+        [% IF otheritemloop.size %]
+            [% INCLUDE items_table items=otheritemloop tab="otherholdings" %]
         [% ELSE %]
             No other items.
         [% END %]
index 0f6906b..0c2a6d9 100755 (executable)
@@ -561,7 +561,15 @@ if ($currentbranch and C4::Context->preference('OpacSeparateHoldings')) {
     $template->param(SeparateHoldings => 1);
 }
 my $separatebranch = C4::Context->preference('OpacSeparateHoldingsBranch');
-for my $itm (@items) {
+my $viewallitems = $query->param('viewallitems');
+my $max_items_to_display = C4::Context->preference('OpacMaxItemsToDisplay') // 50;
+if ( not $viewallitems and @items > $max_items_to_display ) {
+    $template->param(
+        too_many_items => 1,
+        items_count => scalar( @items ),
+    );
+} else {
+  for my $itm (@items) {
     $itm->{holds_count} = $item_reserves{ $itm->{itemnumber} };
     $itm->{priority} = $priority{ $itm->{itemnumber} };
     $norequests = 0
@@ -616,6 +624,7 @@ for my $itm (@items) {
     } else {
         push @itemloop, $itm;
     }
+  }
 }
 
 # Display only one tab if one items list is empty
@@ -626,17 +635,6 @@ if (scalar(@itemloop) == 0 || scalar(@otheritemloop) == 0) {
     }
 }
 
-# If there is a lot of items, and the user has not decided
-# to view them all yet, we first warn him
-# TODO: The limit of 50 could be a syspref
-my $viewallitems = $query->param('viewallitems');
-if (scalar(@itemloop) >= 50 && !$viewallitems) {
-    $template->param('lotsofholdingsitems' => 1);
-}
-if (scalar(@otheritemloop) >= 50 && !$viewallitems) {
-    $template->param('lotsofothersholdingsitems' => 1);
-}
-
 ## get notes and subjects from MARC record
 my $dbh              = C4::Context->dbh;
 my $marcnotesarray   = GetMarcNotes   ($record,$marcflavour);