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

(-)a/C4/Items.pm (+6 lines)
Lines 1218-1223 $filter->{fromDate} = '01/01/2013'; #Filters only serial issues by the serialite Link Here
1218
                                          #The starting date in C4::Context->preference('dateformat') format
1218
                                          #The starting date in C4::Context->preference('dateformat') format
1219
$filter->{toDate} = '31/12/2014';   #Filters only serial issues by the serialitems.publisheddate
1219
$filter->{toDate} = '31/12/2014';   #Filters only serial issues by the serialitems.publisheddate
1220
                                          #The ending date in C4::Context->preference('dateformat') format
1220
                                          #The ending date in C4::Context->preference('dateformat') format
1221
$filter->{limit} = 15;              #Limits the returning set to this many items
1221
                                          
1222
                                          
1222
Filters are expected to be validated! If a filter is not defined, that filter is not present in the $filter-HASH
1223
Filters are expected to be validated! If a filter is not defined, that filter is not present in the $filter-HASH
1223
1224
Lines 1342-1347 sub GetItemsInfo { Link Here
1342
    }
1343
    }
1343
    
1344
    
1344
    $query .= "ORDER BY home.branchname, items.enumchron, LPAD( items.copynumber, 8, '0' ), items.dateaccessioned DESC" ;
1345
    $query .= "ORDER BY home.branchname, items.enumchron, LPAD( items.copynumber, 8, '0' ), items.dateaccessioned DESC" ;
1346
    if (exists $filter->{limit}) {
1347
        push @$queryParams, $filter->{limit};
1348
        $query .= " LIMIT ?";
1349
    }
1350
    
1345
    my $sth = $dbh->prepare($query);
1351
    my $sth = $dbh->prepare($query);
1346
    $sth->execute(@$queryParams);
1352
    $sth->execute(@$queryParams);
1347
    my $i = 0;
1353
    my $i = 0;
(-)a/installer/data/mysql/sysprefs.sql (+1 lines)
Lines 239-244 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
239
('OpacMaintenance','0','','If ON, enables maintenance warning in OPAC','YesNo'),
239
('OpacMaintenance','0','','If ON, enables maintenance warning in OPAC','YesNo'),
240
('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'),
240
('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'),
241
('OpacMainUserBlockMobile','',NULL,'Show the following HTML in its own column on the main page of the OPAC (mobile version):','free'),
241
('OpacMainUserBlockMobile','',NULL,'Show the following HTML in its own column on the main page of the OPAC (mobile version):','free'),
242
('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'),
242
('OPACMobileUserCSS','',NULL,'Include the following CSS for the mobile view on all pages in the OPAC:','free'),
243
('OPACMobileUserCSS','',NULL,'Include the following CSS for the mobile view on all pages in the OPAC:','free'),
243
('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'),
244
('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'),
244
('OpacNav','Important links here.','70|10','Use HTML tags to add navigational links to the left-hand navigational bar in OPAC','Textarea'),
245
('OpacNav','Important links here.','70|10','Use HTML tags to add navigational links to the left-hand navigational bar in OPAC','Textarea'),
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref (+4 lines)
Lines 188-193 OPAC: Link Here
188
              type: textarea
188
              type: textarea
189
              class: code
189
              class: code
190
        -
190
        -
191
            - On the Bibliographic record details page, show only this many items from the users branch and prompt the user to filter the items if the record has more than this many items.
192
            - pref: OPACmaxItemsOnDetail
193
              class: integer
194
        -
191
            - pref: OpacShowLibrariesPulldownMobile
195
            - pref: OpacShowLibrariesPulldownMobile
192
              choices:
196
              choices:
193
                  yes: Show
197
                  yes: Show
(-)a/koha-tmpl/opac-tmpl/prog/en/modules/opac-detail.tt (-5 / +12 lines)
Lines 1054-1060 YAHOO.util.Event.onContentReady("furtherm", function () { Link Here
1054
1054
1055
<div id="holdings">
1055
<div id="holdings">
1056
    
1056
    
1057
    [% IF ( lotsofitems ) %]
1057
    [% IF ( showFilter ) %]
1058
        [%# Display the items filtering form used to filter the shown items. See the end of this file! %]
1058
        [%# Display the items filtering form used to filter the shown items. See the end of this file! %]
1059
        [% INCLUDE filter_form tab="holdings" %]
1059
        [% INCLUDE filter_form tab="holdings" %]
1060
    [% END %]
1060
    [% END %]
Lines 1062-1071 YAHOO.util.Event.onContentReady("furtherm", function () { Link Here
1062
[% IF ( itemloop.size ) %]    
1062
[% IF ( itemloop.size ) %]    
1063
    
1063
    
1064
    [% IF ( lotsofitems ) %]
1064
    [% IF ( lotsofitems ) %]
1065
	<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> Or use the filter above to limit your selection</p>
1065
        <p>
1066
    [% ELSE %]
1066
            [% IF noBranchItems %]
1067
        [% INCLUDE items_table items=itemloop tab="holdings" %]
1067
                Limiting items to the most recent received last year.</br>
1068
            [% ELSE %]
1069
                Showing only the most recent items from your branch.</br>
1070
            [% END %]
1071
            This record has many physical items. Use the filter above to limit your selection.
1072
        </p>
1068
    [% END %]
1073
    [% END %]
1074
    [% INCLUDE items_table items=itemloop tab="holdings" %]
1075
1069
    [% IF holds_count.defined || priority %]
1076
    [% IF holds_count.defined || priority %]
1070
    <div id="bib_holds">
1077
    <div id="bib_holds">
1071
        [% IF holds_count.defined %]
1078
        [% IF holds_count.defined %]
Lines 1638-1644 YAHOO.util.Event.onContentReady("furtherm", function () { Link Here
1638
    <div id="filterIssuesParentContainer">
1645
    <div id="filterIssuesParentContainer">
1639
    <a id="filterIssuesButton" >Limit issues</a>
1646
    <a id="filterIssuesButton" >Limit issues</a>
1640
    [% IF filter %]
1647
    [% IF filter %]
1641
        <form id="issuesFilter" method="get" action="/cgi-bin/koha/opac-detail.pl">
1648
        <form id="issuesFilterClearer" method="get" action="/cgi-bin/koha/opac-detail.pl">
1642
            <input type="hidden" name="biblionumber" id="biblionumber" value="[% biblionumber %]"/>
1649
            <input type="hidden" name="biblionumber" id="biblionumber" value="[% biblionumber %]"/>
1643
            <input type="submit" name="clearFilter" value="Clear filter" class="submit"/>
1650
            <input type="submit" name="clearFilter" value="Clear filter" class="submit"/>
1644
        </form>
1651
        </form>
(-)a/opac/opac-detail.pl (-19 / +58 lines)
Lines 77-90 $biblionumber = int($biblionumber); Link Here
77
##>> Handling the Serial issue filter parameters from the user
77
##>> Handling the Serial issue filter parameters from the user
78
##
78
##
79
# We can filter issues based on these five values.
79
# We can filter issues based on these five values.
80
my $filterBranchLimiter = $query->param('filterBranchLimiter') ? $query->param('filterBranchLimiter') : '_ShowAll';
80
my $filterBranchLimiter = $query->param('filterBranchLimiter') ? $query->param('filterBranchLimiter') : undef;
81
my $filterVolume = $query->param('filterVolume') ? $query->param('filterVolume') : undef;
81
my $filterVolume = $query->param('filterVolume') ? $query->param('filterVolume') : undef;
82
my $filterNumber = $query->param('filterNumber') ? $query->param('filterNumber') : undef;
82
my $filterNumber = $query->param('filterNumber') ? $query->param('filterNumber') : undef;
83
my $filterIssue = $query->param('filterIssue') ? $query->param('filterIssue') : undef;
83
my $filterIssue = $query->param('filterIssue') ? $query->param('filterIssue') : undef;
84
my $filterFromDate = $query->param('filterFrom') ? $query->param('filterFrom') : undef;
84
my $filterFromDate = $query->param('filterFrom') ? $query->param('filterFrom') : undef;
85
my $filterToDate = $query->param('filterTo') ? $query->param('filterTo') : undef;
85
my $filterToDate = $query->param('filterTo') ? $query->param('filterTo') : undef;
86
86
87
my $filter; #a HASH! Collect the filters here, so they can be more conveniently moved around.
87
my $filter = {}; #a HASH! Collect the filters here, so they can be more conveniently moved around.
88
88
89
#We filter by the branch only if a valid branch is given.
89
#We filter by the branch only if a valid branch is given.
90
if (defined $filterBranchLimiter && $filterBranchLimiter ne '_ShowAll') {
90
if (defined $filterBranchLimiter && $filterBranchLimiter ne '_ShowAll') {
Lines 141-146 if (defined $filterToDate && length $filterToDate > 0) { Link Here
141
    }
141
    }
142
}
142
}
143
143
144
$template->param( filter => $filter );
145
146
##
147
##<< Serial issues filter parameters handled! ##
148
##
149
150
# If there are a lot of items, and the user has not decided
151
# to view them all yet, we first warn him
152
my $itemsCount = GetItemsCount($biblionumber);
153
my $lotsofitems = 0;
154
if ($itemsCount > C4::Context->preference('OPACmaxItemsOnDetail') &&
155
    !($query->param('viewallitems')) ) {
156
    
157
    $lotsofitems = 1;
158
    $template->param('lotsofitems' => $lotsofitems);
159
}
160
161
my @all_items;
162
if ($lotsofitems) {
163
    #Spare the poor old DB from this possibly excruciatinly huge read operation.
164
    if (! scalar(%$filter)) { #Is the $filter empty?
165
        
166
        #Limit the amount of results to the system preference
167
        $filter->{limit} = C4::Context->preference('OPACmaxItemsOnDetail');
168
        
169
        #Limit display of Items based on the users branch
170
        if (C4::Context->userenv){
171
            $filter->{branch} = C4::Context->userenv->{branch};
172
            $filterBranchLimiter = $filter->{branch}; #Making the branches loop react to this!
173
            
174
            @all_items = GetItemsInfo($biblionumber, $filter);
175
        }
176
        #Or if branch cannot be defined or has no items, then display Items only from the past year
177
        if( ! (scalar(@all_items)) ) {
178
            delete $filter->{branch}; #Remove the branch filter as it gave no results
179
            undef $filterBranchLimiter;
180
            
181
            my $now = DateTime->now();
182
            $now->set_year(  ($now->year() - 1)  );
183
            $filter->{fromDate} = Koha::DateUtils::output_pref({ dt => $now, dateformat => 'iso'});
184
            $template->param('noBranchItems' => 1);
185
            @all_items = GetItemsInfo($biblionumber, $filter);
186
        }
187
        
188
    }
189
}
190
#If we haven't found our items yet, then pull them using whatever we've got.
191
if( ! (scalar(@all_items)) ) {
192
    @all_items = GetItemsInfo($biblionumber, $filter);
193
}
194
144
195
145
##Prepare the custom branches loop containing the _ShowAll entry to show issues from all libraries.
196
##Prepare the custom branches loop containing the _ShowAll entry to show issues from all libraries.
146
my $branchloop;
197
my $branchloop;
Lines 153-171 else { Link Here
153
    unshift @$branchloop, { branchcode => '_ShowAll', branchname => 'Show from any library', selected => '0', value => '_ShowAll'};
204
    unshift @$branchloop, { branchcode => '_ShowAll', branchname => 'Show from any library', selected => '0', value => '_ShowAll'};
154
}
205
}
155
$template->param( branchloop => $branchloop );
206
$template->param( branchloop => $branchloop );
156
$template->param( filter => $filter ) if defined $filter;
157
207
158
##
159
##<< Serial issues filter parameters handled! ##
160
##
161
162
163
my @all_items = GetItemsInfo($biblionumber, $filter);
164
208
165
# Now that the filter is no longer needed, we can reuse it to keep the filter modifications in the UI,
209
# Now that the filter is no longer needed, we can reuse it to keep the filter modifications in the UI,
166
#  by reverting the dates to the same format as in the UI layer.
210
#  by reverting the dates and the branch to the same format as in the UI layer.
167
$filter->{fromDate} = $filterFromDate;
211
$filter->{fromDate} = $filterFromDate if $filterFromDate;
168
$filter->{toDate} = $filterToDate;
212
$filter->{toDate} = $filterToDate if $filterToDate;
213
$filter->{branch} = $filterBranchLimiter if $filterBranchLimiter;
214
$template->param('showFilter' => 1) if (scalar(%$filter));
169
215
170
my @hiddenitems;
216
my @hiddenitems;
171
if (scalar @all_items >= 1) {
217
if (scalar @all_items >= 1) {
Lines 731-743 if (scalar(@itemloop) == 0 || scalar(@otheritemloop) == 0) { Link Here
731
    }
777
    }
732
}
778
}
733
779
734
# If there is a lot of items, and the user has not decided
735
# to view them all yet, we first warn him
736
# TODO: The limit of 50 could be a syspref
737
my $viewallitems = $query->param('viewallitems');
738
if (scalar(@itemloop) >= 50 && !$viewallitems) {
739
    $template->param('lotsofitems' => 1);
740
}
741
780
742
## get notes and subjects from MARC record
781
## get notes and subjects from MARC record
743
my $dbh              = C4::Context->dbh;
782
my $dbh              = C4::Context->dbh;
(-)a/t/db_dependent/Items.t (-2 / +5 lines)
Lines 145-151 subtest 'GetHiddenItemnumbers tests' => sub { Link Here
145
145
146
subtest 'Filter items tests' => sub {
146
subtest 'Filter items tests' => sub {
147
    
147
    
148
    plan tests => 2;
148
    plan tests => 3;
149
149
150
    # Start transaction
150
    # Start transaction
151
    $dbh->{AutoCommit} = 0;
151
    $dbh->{AutoCommit} = 0;
Lines 173-178 subtest 'Filter items tests' => sub { Link Here
173
    # Testing the dates filter
173
    # Testing the dates filter
174
    my @shouldBeEmpty = C4::Items::GetItemsInfo($biblionumber, {toDate => '01/01/1933'});
174
    my @shouldBeEmpty = C4::Items::GetItemsInfo($biblionumber, {toDate => '01/01/1933'});
175
    is( scalar(@shouldBeEmpty), 0, "Filtering by date");
175
    is( scalar(@shouldBeEmpty), 0, "Filtering by date");
176
    
177
    # Testing the limit filter
178
    @shouldBeEmpty = C4::Items::GetItemsInfo($biblionumber, {limit => 0});
179
    is( scalar(@shouldBeEmpty), 0, "Filtering by limit");
176
};
180
};
177
181
178
# Helper method to set up a Biblio.
182
# Helper method to set up a Biblio.
179
- 

Return to bug 6385