From 69841f7fa45b6bd88dcf5b67ed66e30682e708ee Mon Sep 17 00:00:00 2001 From: Olli-Antti Kivilahti Date: Mon, 28 Oct 2013 15:59:00 +0200 Subject: [PATCH] Bug 6385 - All items should optionally be displayed by default in the OPAC Added a system preference "OPACmaxItemsOnDetail" to set a threshold after which only results from the users branch are displayed, or Items from the past year if homebranch cannot be defined. This tightly couples with bug 11129 which provides the filtering mechanism to display smaller result sets. Also added lots of complexity to define the warning messages based on is the filter used to override the "OPACmaxItemsOnDetail". --- installer/data/mysql/sysprefs.sql | 1 + .../prog/en/modules/admin/preferences/opac.pref | 4 ++ koha-tmpl/opac-tmpl/prog/en/modules/opac-detail.tt | 17 ++++-- opac/opac-detail.pl | 61 +++++++++++++++------- 4 files changed, 60 insertions(+), 23 deletions(-) diff --git a/installer/data/mysql/sysprefs.sql b/installer/data/mysql/sysprefs.sql index 165ed01..4db2935 100644 --- a/installer/data/mysql/sysprefs.sql +++ b/installer/data/mysql/sysprefs.sql @@ -239,6 +239,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('OpacMaintenance','0','','If ON, enables maintenance warning in OPAC','YesNo'), ('OpacMainUserBlock','Welcome to Koha...\r\n
','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'), +('OPACmaxItemsOnDetail', '50', NULL, 'On the Bibliographic record details page, show only items from the users branch and prompt the user to filter the items if the record has more then this many items.', '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'), diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref index a75c7ef..c2441c2 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref @@ -188,6 +188,10 @@ OPAC: type: textarea class: code - + - On the Bibliographic record details page, show only items from the users branch and prompt the user to filter the items if the record has more then this many items. + - pref: OPACmaxItemsOnDetail + class: integer + - - pref: OpacShowLibrariesPulldownMobile choices: yes: Show diff --git a/koha-tmpl/opac-tmpl/prog/en/modules/opac-detail.tt b/koha-tmpl/opac-tmpl/prog/en/modules/opac-detail.tt index cb76413..a1a04ca 100644 --- a/koha-tmpl/opac-tmpl/prog/en/modules/opac-detail.tt +++ b/koha-tmpl/opac-tmpl/prog/en/modules/opac-detail.tt @@ -1054,7 +1054,7 @@ YAHOO.util.Event.onContentReady("furtherm", function () {
- [% IF ( lotsofitems ) %] + [% IF ( showFilter ) %] [%# Display the items filtering form used to filter the shown items. See the end of this file! %] [% INCLUDE filter_form tab="holdings" %] [% END %] @@ -1062,10 +1062,17 @@ YAHOO.util.Event.onContentReady("furtherm", function () { [% IF ( itemloop.size ) %] [% IF ( lotsofitems ) %] -

This record has many physical items. Click here to view them all. Or use the filter above to limit your selection

- [% ELSE %] - [% INCLUDE items_table items=itemloop tab="holdings" %] +

+ [% IF userBranchNotDefined %] + Limiting items to received last year.
+ [% ELSE %] + Showing only items from your branch.
+ [% END %] + This record has many physical items. Use the filter above to limit your selection. +

[% END %] + [% INCLUDE items_table items=itemloop tab="holdings" %] + [% IF holds_count.defined || priority %]
[% IF holds_count.defined %] @@ -1638,7 +1645,7 @@ YAHOO.util.Event.onContentReady("furtherm", function () {
Limit issues [% IF filter %] -
+
diff --git a/opac/opac-detail.pl b/opac/opac-detail.pl index 343bf2e..01fc7b5 100755 --- a/opac/opac-detail.pl +++ b/opac/opac-detail.pl @@ -84,7 +84,7 @@ my $filterIssue = $query->param('filterIssue') ? $query->param('filterIssue') : my $filterFromDate = $query->param('filterFrom') ? $query->param('filterFrom') : undef; my $filterToDate = $query->param('filterTo') ? $query->param('filterTo') : undef; -my $filter; #a HASH! Collect the filters here, so they can be more conveniently moved around. +my $filter = {}; #a HASH! Collect the filters here, so they can be more conveniently moved around. #We filter by the branch only if a valid branch is given. if (defined $filterBranchLimiter && $filterBranchLimiter ne '_ShowAll') { @@ -141,6 +141,43 @@ if (defined $filterToDate && length $filterToDate > 0) { } } +$template->param( filter => $filter ); + +## +##<< Serial issues filter parameters handled! ## +## + +# If there are a lot of items, and the user has not decided +# to view them all yet, we first warn him +my $itemsCount = GetItemsCount($biblionumber); +my $lotsofitems = 0; +if ($itemsCount > C4::Context->preference('OPACmaxItemsOnDetail') && + !($query->param('viewallitems')) ) { + + $lotsofitems = 1; + $template->param('lotsofitems' => $lotsofitems); +} + +my @all_items; +if ($lotsofitems) { + #Spare the poor old DB from this possibly excruciatinly huge read operation. + if (! scalar(%$filter)) { #Is the $filter empty? + #Limit display of Items based on the users branch + if (C4::Context->userenv){ + $filter->{branch} = C4::Context->userenv->{branch}; + $filterBranchLimiter = $filter->{branch}; #Making the branches loop react to this! + } + #Or if branch cannot be defined, then display Items only from the past year + else { + my $now = DateTime->now(); + $now->set_year( ($now->year() - 1) ); + $filter->{fromDate} = Koha::DateUtils::output_pref({ dt => $now, dateformat => 'iso'}); + $template->param('userBranchNotDefined' => 1); + } + } +} +@all_items = GetItemsInfo($biblionumber, $filter); + ##Prepare the custom branches loop containing the _ShowAll entry to show issues from all libraries. my $branchloop; @@ -153,19 +190,14 @@ else { unshift @$branchloop, { branchcode => '_ShowAll', branchname => 'Show from any library', selected => '0', value => '_ShowAll'}; } $template->param( branchloop => $branchloop ); -$template->param( filter => $filter ) if defined $filter; - -## -##<< Serial issues filter parameters handled! ## -## - -my @all_items = GetItemsInfo($biblionumber, $filter); # Now that the filter is no longer needed, we can reuse it to keep the filter modifications in the UI, -# by reverting the dates to the same format as in the UI layer. -$filter->{fromDate} = $filterFromDate; -$filter->{toDate} = $filterToDate; +# by reverting the dates and the branch to the same format as in the UI layer. +$filter->{fromDate} = $filterFromDate if $filterFromDate; +$filter->{toDate} = $filterToDate if $filterToDate; +$filter->{branch} = $filterBranchLimiter if $filterBranchLimiter; +$template->param('showFilter' => 1) if (scalar(%$filter)); my @hiddenitems; if (scalar @all_items >= 1) { @@ -731,13 +763,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('lotsofitems' => 1); -} ## get notes and subjects from MARC record my $dbh = C4::Context->dbh; -- 1.8.1.2