[% IF holds_count.defined %]
@@ -1641,9 +1649,9 @@ YAHOO.util.Event.onContentReady("furtherm", function () {
Limit issues
[% IF filter %]
-
[% END %]
--- a/opac/opac-detail.pl
+++ a/opac/opac-detail.pl
@@ -77,14 +77,14 @@ $biblionumber = int($biblionumber);
##>> Handling the Serial issue filter parameters from the user
##
# We can filter issues based on these five values.
-my $filterBranchLimiter = $query->param('filterBranchLimiter') ? $query->param('filterBranchLimiter') : '_ShowAll';
+my $filterBranchLimiter = $query->param('filterBranchLimiter') ? $query->param('filterBranchLimiter') : undef;
my $filterVolume = $query->param('filterVolume') ? $query->param('filterVolume') : undef;
my $filterNumber = $query->param('filterNumber') ? $query->param('filterNumber') : undef;
my $filterIssue = $query->param('filterIssue') ? $query->param('filterIssue') : undef;
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,57 @@ 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 $lotsofholdingsitems = 0;
+if ($itemsCount > C4::Context->preference('OPACmaxItemsOnDetail') &&
+ !($query->param('viewallitems')) ) {
+
+ $lotsofholdingsitems = 1;
+ $template->param('lotsofholdingsitems' => $lotsofholdingsitems);
+}
+
+my @all_items;
+if ($lotsofholdingsitems) {
+ #Spare the poor old DB from this possibly excruciatinly huge read operation.
+ if (! scalar(%$filter)) { #Is the $filter empty?
+
+ #Limit the amount of results to the system preference
+ $filter->{limit} = C4::Context->preference('OPACmaxItemsOnDetail');
+
+ #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!
+
+ @all_items = GetItemsInfo($biblionumber, $filter);
+ }
+ #Or if branch cannot be defined or has no items, then display Items only from the past year
+ if( ! (scalar(@all_items)) ) {
+ delete $filter->{branch}; #Remove the branch filter as it gave no results
+ undef $filterBranchLimiter;
+
+ my $now = DateTime->now();
+ $now->set_year( ($now->year() - 1) );
+ $filter->{fromDate} = Koha::DateUtils::output_pref({ dt => $now, dateformat => 'iso'});
+ $template->param('noBranchItems' => 1);
+ @all_items = GetItemsInfo($biblionumber, $filter);
+ }
+
+ }
+}
+#If we haven't found our items yet, then pull them using whatever we've got.
+if( ! (scalar(@all_items)) ) {
+ @all_items = GetItemsInfo($biblionumber, $filter);
+}
+
##Prepare the custom branches loop containing the _ShowAll entry to show issues from all libraries.
my $branchloop;
@@ -153,19 +204,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) {
@@ -734,11 +780,8 @@ 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
+# TODO: The limit of 50 could be a syspref, it already is !!
my $viewallitems = $query->param('viewallitems');
-if (scalar(@itemloop) >= 50 && !$viewallitems) {
- $template->param('lotsofholdingsitems' => 1);
-}
if (scalar(@otheritemloop) >= 50 && !$viewallitems) {
$template->param('lotsofothersholdingsitems' => 1);
}
--- a/t/db_dependent/Items.t
+++ a/t/db_dependent/Items.t
@@ -145,7 +145,7 @@ subtest 'GetHiddenItemnumbers tests' => sub {
subtest 'Filter items tests' => sub {
- plan tests => 2;
+ plan tests => 3;
# Start transaction
$dbh->{AutoCommit} = 0;
@@ -173,6 +173,10 @@ subtest 'Filter items tests' => sub {
# Testing the dates filter
my @shouldBeEmpty = C4::Items::GetItemsInfo($biblionumber, {toDate => '01/01/1933'});
is( scalar(@shouldBeEmpty), 0, "Filtering by date");
+
+ # Testing the limit filter
+ @shouldBeEmpty = C4::Items::GetItemsInfo($biblionumber, {limit => 0});
+ is( scalar(@shouldBeEmpty), 0, "Filtering by limit");
};
# Helper method to set up a Biblio.
--