From 45302d975325e626a9979f5fe01c025f52a23877 Mon Sep 17 00:00:00 2001 From: Mark Tompsett Date: Thu, 11 Jul 2013 23:13:42 -0400 Subject: [PATCH] Bug 10584 - Hide OPAC biblio details if all items are hidden If there are items for a given biblio number, and they are all hidden, then biblio needs to be hidden. If the biblio needs to be hidden, it immediately redirects to a 404.pl page, just as if the biblionumber does not exist. Arrays used to represent all the items were relocated and used, added if they didn't exist. Arrays representing the hidden items were relocated and used if they existed, added if they didn't exist. Upon debugging the opac-MARCdetail.pl modification, it was discovered the reason getHiddenItems was failing was because 'use YAML qw/Load/;' was not mentioned in C4::Items, and other libraries were triggering the loading of YAML to compensate for opac-detail.pl and opac-ISBDdetail.pl files. --- C4/Items.pm | 1 + opac/opac-ISBDdetail.pl | 12 +++++++++++- opac/opac-MARCdetail.pl | 15 +++++++++++++++ opac/opac-detail.pl | 18 ++++++++++++------ 4 files changed, 39 insertions(+), 7 deletions(-) diff --git a/C4/Items.pm b/C4/Items.pm index 64db262..c1d7974 100644 --- a/C4/Items.pm +++ b/C4/Items.pm @@ -30,6 +30,7 @@ use MARC::Record; use C4::ClassSource; use C4::Log; use List::MoreUtils qw/any/; +use YAML qw/Load/; use Data::Dumper; # used as part of logging item record changes, not just for # debugging; so please don't remove this diff --git a/opac/opac-ISBDdetail.pl b/opac/opac-ISBDdetail.pl index 94055a9..8b813e3 100755 --- a/opac/opac-ISBDdetail.pl +++ b/opac/opac-ISBDdetail.pl @@ -84,6 +84,17 @@ $template->param( 'AllowOnShelfHolds' => C4::Context->preference('AllowOnShelfHo $template->param( 'ItemsIssued' => CountItemsIssued( $biblionumber ) ); my $marcflavour = C4::Context->preference("marcflavour"); + +my @items = GetItemsInfo($biblionumber); +if (scalar @items >= 1) { + my @hiddenitems = GetHiddenItemnumbers(@items); + + if (scalar @hiddenitems == scalar @items ) { + print $query->redirect("/cgi-bin/koha/errors/404.pl"); # escape early + exit; + } +} + my $record = GetMarcBiblio($biblionumber); if ( ! $record ) { print $query->redirect("/cgi-bin/koha/errors/404.pl"); @@ -138,7 +149,6 @@ $template->param( my $norequests = 1; my $res = GetISBDView($biblionumber, "opac"); -my @items = GetItemsInfo( $biblionumber ); my $itemtypes = GetItemTypes(); for my $itm (@items) { diff --git a/opac/opac-MARCdetail.pl b/opac/opac-MARCdetail.pl index 2a69244..f5e5995 100755 --- a/opac/opac-MARCdetail.pl +++ b/opac/opac-MARCdetail.pl @@ -50,6 +50,7 @@ use C4::Output; use CGI; use MARC::Record; use C4::Biblio; +use C4::Items; use C4::Acquisition; use C4::Koha; @@ -62,6 +63,20 @@ my $itemtype = &GetFrameworkCode($biblionumber); my $tagslib = &GetMarcStructure( 0, $itemtype ); my $biblio = GetBiblioData($biblionumber); $biblionumber = $biblio->{biblionumber}; + +print STDERR "biblionumber: $biblionumber\n"; +my @all_items = GetItemsInfo($biblionumber); +if (scalar @all_items >= 1) { + my @hiddenitems = GetHiddenItemnumbers(@all_items); + print STDERR "Scalar GHI: " . (scalar @hiddenitems) . "\n"; + + if (scalar @hiddenitems == scalar @all_items ) { + print $query->redirect("/cgi-bin/koha/errors/404.pl"); # escape early + exit; + } +} +print STDERR "Scalar AI: " . (scalar @all_items) . "\n"; + my $record = GetMarcBiblio($biblionumber, 1); if ( ! $record ) { print $query->redirect("/cgi-bin/koha/errors/404.pl"); diff --git a/opac/opac-detail.pl b/opac/opac-detail.pl index d1f5d91..aca8ad3 100755 --- a/opac/opac-detail.pl +++ b/opac/opac-detail.pl @@ -70,9 +70,20 @@ my ( $template, $borrowernumber, $cookie ) = get_template_and_user( } ); -my $biblionumber = $query->param('biblionumber') || $query->param('bib'); +my $biblionumber = $query->param('biblionumber') || $query->param('bib') || 0; $biblionumber = int($biblionumber); +my @all_items = GetItemsInfo($biblionumber); +my @hiddenitems; +if (scalar @all_items >= 1) { + push @hiddenitems, GetHiddenItemnumbers(@all_items); + + if (scalar @hiddenitems == scalar @all_items ) { + print $query->redirect("/cgi-bin/koha/errors/404.pl"); # escape early + exit; + } +} + my $record = GetMarcBiblio($biblionumber); if ( ! $record ) { print $query->redirect("/cgi-bin/koha/errors/404.pl"); # escape early @@ -397,8 +408,6 @@ $template->param( 'ItemsIssued' => CountItemsIssued( $biblionumber ) ); $template->param('OPACShowCheckoutName' => C4::Context->preference("OPACShowCheckoutName") ); $template->param('OPACShowBarcode' => C4::Context->preference("OPACShowBarcode") ); -# change back when ive fixed request.pl -my @all_items = GetItemsInfo( $biblionumber ); # adding items linked via host biblios @@ -421,9 +430,6 @@ foreach my $hostfield ( $record->field($analyticfield)) { my @items; -# Getting items to be hidden -my @hiddenitems = GetHiddenItemnumbers(@all_items); - # Are there items to hide? my $hideitems; $hideitems = 1 if C4::Context->preference('hidelostitems') or scalar(@hiddenitems) > 0; -- 1.7.9.5