Bugzilla – Attachment 113875 Details for
Bug 15448
Placing hold on specific items doesn't enforce OpacHiddenItems
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 15448: Clean existing code in opac-detail
Bug-15448-Clean-existing-code-in-opac-detail.patch (text/plain), 8.29 KB, created by
Jonathan Druart
on 2020-11-20 11:26:10 UTC
(
hide
)
Description:
Bug 15448: Clean existing code in opac-detail
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2020-11-20 11:26:10 UTC
Size:
8.29 KB
patch
obsolete
>From 2839c03c75af8eaebf1479cc7c2f8f30aae1fffa Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Fri, 20 Nov 2020 12:11:07 +0100 >Subject: [PATCH] Bug 15448: Clean existing code in opac-detail > >This patch groups the code related to OpacHiddenItems and hidelostitems. >It certainly fixed few issues (we are now filtering after EasyAnalyticalRecords), maybe not... > >At least now the code is at the same place. >--- > opac/opac-detail.pl | 110 ++++++++++++++++++++++++++------------------ > 1 file changed, 64 insertions(+), 46 deletions(-) > >diff --git a/opac/opac-detail.pl b/opac/opac-detail.pl >index 8b935af155..38fa2d1d55 100755 >--- a/opac/opac-detail.pl >+++ b/opac/opac-detail.pl >@@ -82,18 +82,6 @@ my ( $template, $borrowernumber, $cookie ) = get_template_and_user( > } > ); > >-my @all_items = GetItemsInfo($biblionumber); >-if( $specific_item ) { >- @all_items = grep { $_->{itemnumber} == $query->param('itemnumber') } @all_items; >- $template->param( specific_item => 1 ); >-} >-my @hiddenitems; >-my $patron = Koha::Patrons->find( $borrowernumber ); >-our $borcat= q{}; >-if ( C4::Context->preference('OpacHiddenItemsExceptions') ) { >- $borcat = $patron ? $patron->categorycode : q{}; >-} >- > my $record = GetMarcBiblio({ > biblionumber => $biblionumber, > opac => 1 }); >@@ -102,16 +90,7 @@ if ( ! $record ) { > exit; > } > >-if ( scalar @all_items >= 1 ) { >- push @hiddenitems, >- GetHiddenItemnumbers( { items => \@all_items, borcat => $borcat } ); >- >- if (scalar @hiddenitems == scalar @all_items ) { >- print $query->redirect("/cgi-bin/koha/errors/404.pl"); # escape early >- exit; >- } >-} >- >+our $logged_in_patron = Koha::Patrons->find( $borrowernumber ); > my $biblio = Koha::Biblios->find( $biblionumber ); > my $framework = $biblio ? $biblio->frameworkcode : q{}; > my $record_processor = Koha::RecordProcessor->new({ >@@ -280,7 +259,7 @@ if ($session->param('busc')) { > my @newresults; > my $search_context = { > 'interface' => 'opac', >- 'category' => $borcat >+ 'category' => $logged_in_patron ? $logged_in_patron->categorycode : undef, > }; > for (my $i=0;$i<@servers;$i++) { > my $server = $servers[$i]; >@@ -507,6 +486,7 @@ if ($session->param('busc')) { > for (my $j = 0; $j < @arrBiblios; $j++) { > next unless ($arrBiblios[$j]); > $dataBiblioPaging = Koha::Biblios->find( $arrBiblios[$j] ) if ($arrBiblios[$j] != $biblionumber); >+ next unless $dataBiblioPaging; > push @listResults, {index => $j + 1 + $offset, biblionumber => $arrBiblios[$j], title => ($arrBiblios[$j] == $biblionumber)?'':$dataBiblioPaging->title, author => ($arrBiblios[$j] != $biblionumber && $dataBiblioPaging->author)?$dataBiblioPaging->author:'', url => ($arrBiblios[$j] == $biblionumber)?'':'opac-detail.pl?biblionumber=' . $arrBiblios[$j]}; > } > $template->param('listResults' => \@listResults) if (@listResults); >@@ -519,6 +499,12 @@ $template->param( > OPACShowCheckoutName => C4::Context->preference("OPACShowCheckoutName"), > ); > >+my @all_items = GetItemsInfo($biblionumber); >+if( $specific_item ) { >+ @all_items = grep { $_->{itemnumber} == $query->param('itemnumber') } @all_items; >+ $template->param( specific_item => 1 ); >+} >+ > if ( C4::Context->preference('EasyAnalyticalRecords') ) { > # adding items linked via host biblios > my $analyticfield = '773'; >@@ -539,24 +525,56 @@ if ( C4::Context->preference('EasyAnalyticalRecords') ) { > } > } > >-my @items; >- >-# Are there items to hide? >-my $hideitems; >-$hideitems = 1 if C4::Context->preference('hidelostitems') or scalar(@hiddenitems) > 0; >+my @filtered_items; >+if ( @all_items ) { >+ @filtered_items = filter_items( { items => \@all_items, patron => $logged_in_patron, } ); > >-# Hide items >-if ($hideitems) { >- for my $itm (@all_items) { >- if ( C4::Context->preference('hidelostitems') ) { >- push @items, $itm unless $itm->{itemlost} or any { $itm->{'itemnumber'} eq $_ } @hiddenitems; >- } else { >- push @items, $itm unless any { $itm->{'itemnumber'} eq $_ } @hiddenitems; >+ unless ( @filtered_items ) { >+ print $query->redirect("/cgi-bin/koha/errors/404.pl"); # escape early >+ exit; > } > } >-} else { >+ >+sub filter_items { >+ my ( $params ) = @_; >+ my @all_items = @{$params->{items}}; >+ my $patron = $params->{patron}; >+ my @hiddenitems; >+ my $patron_category = >+ ( C4::Context->preference('OpacHiddenItemsExceptions') && $patron ) >+ ? $patron->categorycode >+ : undef; >+ >+ if ( scalar @all_items >= 1 ) { >+ push @hiddenitems, >+ GetHiddenItemnumbers( { items => \@all_items, borcat => $patron_category } ); >+ >+ return () if scalar @hiddenitems == scalar @all_items; >+ } >+ >+ my @items; >+ # Are there items to hide? >+ my $hideitems; >+ >+ # Hide items >+ if ( C4::Context->preference('hidelostitems') || @hiddenitems ) { >+ for my $itm (@all_items) { >+ if ( C4::Context->preference('hidelostitems') ) { >+ push @items, $itm >+ unless $itm->{itemlost} >+ or any { $itm->{'itemnumber'} eq $_ } @hiddenitems; >+ } >+ else { >+ push @items, $itm >+ unless any { $itm->{'itemnumber'} eq $_ } @hiddenitems; >+ } >+ } >+ } > # Or not >- @items = @all_items; >+ else { >+ @items = @all_items; >+ } >+ return @items; > } > > my $branch = ''; >@@ -580,7 +598,7 @@ if ( C4::Context->preference('HighlightOwnItemsOnOPAC') ) { > my @our_items; > my @other_items; > >- foreach my $item ( @items ) { >+ foreach my $item ( @filtered_items ) { > if ( $item->{branchcode} eq $branchcode ) { > $item->{'this_branch'} = 1; > push( @our_items, $item ); >@@ -589,7 +607,7 @@ if ( C4::Context->preference('HighlightOwnItemsOnOPAC') ) { > } > } > >- @items = ( @our_items, @other_items ); >+ @filtered_items= ( @our_items, @other_items ); > } > } > >@@ -650,7 +668,7 @@ foreach my $subscription (@subscriptions) { > push @subs, \%cell; > } > >-$dat->{'count'} = scalar(@items); >+$dat->{'count'} = scalar(@filtered_items); > > > my (%item_reserves, %priority); >@@ -709,13 +727,13 @@ if ( C4::Context->preference('OPACAcquisitionDetails' ) ) { > > my $allow_onshelf_holds; > my ( $itemloop_has_images, $otheritemloop_has_images ); >-if ( not $viewallitems and @items > $max_items_to_display ) { >+if ( not $viewallitems and @filtered_items > $max_items_to_display ) { > $template->param( > too_many_items => 1, >- items_count => scalar( @items ), >+ items_count => scalar( @filtered_items ), > ); > } else { >- for my $itm (@items) { >+ for my $itm (@filtered_items) { > my $item = Koha::Items->find( $itm->{itemnumber} ); > $itm->{holds_count} = $item_reserves{ $itm->{itemnumber} }; > $itm->{priority} = $priority{ $itm->{itemnumber} }; >@@ -727,7 +745,7 @@ if ( not $viewallitems and @items > $max_items_to_display ) { > && !$itemtypes->{$itm->{'itype'}}->{notforloan} > && $itm->{'itemnumber'}; > >- $allow_onshelf_holds = Koha::CirculationRules->get_onshelfholds_policy( { item => $item, patron => $patron } ) >+ $allow_onshelf_holds = Koha::CirculationRules->get_onshelfholds_policy( { item => $item, patron => $logged_in_patron } ) > unless $allow_onshelf_holds; > > # get collection code description, too >@@ -843,7 +861,7 @@ if( C4::Context->preference('ArticleRequests') ) { > OpacStarRatings => C4::Context->preference("OpacStarRatings"), > ); > >-if (C4::Context->preference("AlternateHoldingsField") && scalar @items == 0) { >+if (C4::Context->preference("AlternateHoldingsField") && scalar @filtered_items == 0) { > my $fieldspec = C4::Context->preference("AlternateHoldingsField"); > my $subfields = substr $fieldspec, 3; > my $holdingsep = C4::Context->preference("AlternateHoldingsSeparator") || ' '; >@@ -1257,7 +1275,7 @@ if (C4::Context->preference('OpacHighlightedWords')) { > $template->{VARS}->{'trackclicks'} = C4::Context->preference('TrackClicks'); > > if ( C4::Context->preference('UseCourseReserves') ) { >- foreach my $i ( @items ) { >+ foreach my $i ( @filtered_items ) { > $i->{'course_reserves'} = GetItemCourseReservesInfo( itemnumber => $i->{'itemnumber'} ); > } > } >-- >2.20.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 15448
:
46100
|
113875
|
113876
|
114188
|
114189
|
114191
|
114193
|
114194
|
114208
|
114209
|
114263
|
114264
|
114578
|
115133
|
115134