From b4eecfbe3c95ef36196bf38c643a3984f77d1ff7 Mon Sep 17 00:00:00 2001 From: Mark Tompsett Date: Fri, 18 Aug 2017 18:33:31 +0000 Subject: [PATCH] Bug 14385: Modify opac-ISBDdetail and opac-MARCdetail Both files had similar logic. They were rearranged and optimized, so that both files would have practically identical initial blocks of code. Optimizations were possible, because GetMarcBiblio returns a filtered record, so that there is no double call (once in the opac-### file and once in GetMarcBiblio) to GetHiddenItemnumbers. --- opac/opac-ISBDdetail.pl | 79 ++++++++++++++++++++++---------------------- opac/opac-MARCdetail.pl | 87 ++++++++++++++++++++++--------------------------- 2 files changed, 79 insertions(+), 87 deletions(-) diff --git a/opac/opac-ISBDdetail.pl b/opac/opac-ISBDdetail.pl index b003509..9fd472c 100755 --- a/opac/opac-ISBDdetail.pl +++ b/opac/opac-ISBDdetail.pl @@ -58,6 +58,15 @@ use Koha::RecordProcessor; my $query = CGI->new(); + +my $biblionumber = $query->param('biblionumber'); +if ( ! $biblionumber ) { + print $query->redirect('/cgi-bin/koha/errors/404.pl'); + exit; +} +$biblionumber = int($biblionumber); + +#open template my ( $template, $loggedinuser, $cookie ) = get_template_and_user( { template_name => "opac-ISBDdetail.tt", @@ -68,51 +77,32 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( } ); -my $biblionumber = $query->param('biblionumber'); -$biblionumber = int($biblionumber); - -# get biblionumbers stored in the cart -if(my $cart_list = $query->cookie("bib_list")){ - my @cart_list = split(/\//, $cart_list); - if ( grep {$_ eq $biblionumber} @cart_list) { - $template->param( incart => 1 ); - } -} - -$template->param( 'ItemsIssued' => CountItemsIssued( $biblionumber ) ); - -my $marcflavour = C4::Context->preference("marcflavour"); - -my @items = GetItemsInfo($biblionumber); -if (scalar @items >= 1) { - my $borrowernumber; - my $borcat; - if (C4::Context->userenv) { - $borrowernumber = C4::Context->userenv->{'number'}; - } - if ( C4::Context->preference('OpacHiddenItemsExceptions') ) { - - # we need to fetch the borrower info here, so we can pass the category - my $borrower = Koha::Patrons->find( { borrowernumber => $borrowernumber } ); - $borcat = $borrower ? $borrower->categorycode : q{}; - } - - my @hiddenitems = GetHiddenItemnumbers( { items => \@items, borcat => $borcat }); - - if (scalar @hiddenitems == scalar @items ) { - print $query->redirect("/cgi-bin/koha/errors/404.pl"); # escape early - exit; - } +my $borcat = q{}; +if ( C4::Context->preference('OpacHiddenItemsExceptions') ) { + # we need to fetch the borrower info here, so we can pass the category + my $borrower = Koha::Patrons->find( { borrowernumber => $loggedinuser } ); + $borcat = $borrower ? $borrower->categorycode : $borcat; } my $record = GetMarcBiblio({ biblionumber => $biblionumber, - embed_items => 1 }); + embed_items => 1, + opac => 1, + borcat => $borcat }); if ( ! $record ) { print $query->redirect("/cgi-bin/koha/errors/404.pl"); exit; } -my $framework = GetFrameworkCode( $biblionumber ); + +my @all_items = GetItemsInfo($biblionumber); +my $framework = &GetFrameworkCode( $biblionumber ); +my ($tag_itemnumber, $subtag_itemnumber) = &GetMarcFromKohaField('items.itemnumber',$framework); +my @nonhiddenitems = $record->field($tag_itemnumber); +if (scalar @all_items >= 1 && scalar @nonhiddenitems == 0) { + print $query->redirect('/cgi-bin/koha/errors/404.pl'); # escape early + exit; +} + my $record_processor = Koha::RecordProcessor->new({ filters => 'ViewPolicy', options => { @@ -122,6 +112,18 @@ my $record_processor = Koha::RecordProcessor->new({ }); $record_processor->process($record); +# get biblionumbers stored in the cart +if(my $cart_list = $query->cookie("bib_list")){ + my @cart_list = split(/\//, $cart_list); + if ( grep {$_ eq $biblionumber} @cart_list) { + $template->param( incart => 1 ); + } +} + +$template->param( 'ItemsIssued' => CountItemsIssued( $biblionumber ) ); + +my $marcflavour = C4::Context->preference("marcflavour"); + # some useful variables for enhanced content; # in each case, we're grabbing the first value we find in # the record and normalizing it @@ -143,7 +145,6 @@ $template->param( #coping with subscriptions my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber); -my $dbh = C4::Context->dbh; my $dat = TransformMarcToKoha( $record ); my @subscriptions = SearchSubscriptions({ biblionumber => $biblionumber, orderby => 'title' }); @@ -179,7 +180,7 @@ my $res = GetISBDView({ my $itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search_with_localization->unblessed } }; my $patron = Koha::Patrons->find( $loggedinuser ); -for my $itm (@items) { +for my $itm (@all_items) { $norequests = 0 if $norequests && !$itm->{'withdrawn'} diff --git a/opac/opac-MARCdetail.pl b/opac/opac-MARCdetail.pl index cc6bb53..64a5214 100755 --- a/opac/opac-MARCdetail.pl +++ b/opac/opac-MARCdetail.pl @@ -61,50 +61,51 @@ use Koha::Biblios; use Koha::Patrons; use Koha::RecordProcessor; -my $query = new CGI; - -my $dbh = C4::Context->dbh; +my $query = CGI->new(); my $biblionumber = $query->param('biblionumber'); if ( ! $biblionumber ) { print $query->redirect("/cgi-bin/koha/errors/404.pl"); exit; } +$biblionumber = int($biblionumber); + +# open template +my ( $template, $loggedinuser, $cookie ) = get_template_and_user( + { + template_name => "opac-MARCdetail.tt", + query => $query, + type => "opac", + authnotrequired => ( C4::Context->preference("OpacPublic") ? 1 : 0 ), + debug => 1, + } +); + +my $borcat = q{}; +if ( C4::Context->preference('OpacHiddenItemsExceptions') ) { + # we need to fetch the borrower info here, so we can pass the category + my $borrower = Koha::Patrons->find( { borrowernumber => $loggedinuser } ); + $borcat = $borrower ? $borrower->categorycode : $borcat; +} my $record = GetMarcBiblio({ biblionumber => $biblionumber, - embed_items => 1 }); + embed_items => 1, + opac => 1, + borcat => $borcat }); if ( ! $record ) { print $query->redirect("/cgi-bin/koha/errors/404.pl"); exit; } my @all_items = GetItemsInfo($biblionumber); -my @items2hide; -if (scalar @all_items >= 1) { - my $borrowernumber; - my $borcat; - if (C4::Context->userenv) { - $borrowernumber = C4::Context->userenv->{'number'}; - } - if ( C4::Context->preference('OpacHiddenItemsExceptions') ) { - - # we need to fetch the borrower info here, so we can pass the category - my $borrower = Koha::Patrons->find( { borrowernumber => $borrowernumber } ); - $borcat = $borrower ? $borrower->categorycode : q{}; - } - push @items2hide, GetHiddenItemnumbers({ items => \@all_items, borcat => $borcat }); - - if (scalar @items2hide == scalar @all_items ) { - print $query->redirect("/cgi-bin/koha/errors/404.pl"); - exit; - } -} - my $framework = &GetFrameworkCode( $biblionumber ); -my $tagslib = &GetMarcStructure( 0, $framework ); my ($tag_itemnumber,$subtag_itemnumber) = &GetMarcFromKohaField('items.itemnumber',$framework); -my $biblio = Koha::Biblios->find( $biblionumber ); +my @nonhiddenitems = $record->field($tag_itemnumber); +if (scalar @all_items >= 1 && scalar @nonhiddenitems == 0) { + print $query->redirect("/cgi-bin/koha/errors/404.pl"); + exit; +} my $record_processor = Koha::RecordProcessor->new({ filters => 'ViewPolicy', @@ -115,23 +116,6 @@ my $record_processor = Koha::RecordProcessor->new({ }); $record_processor->process($record); -# open template -my ( $template, $loggedinuser, $cookie ) = get_template_and_user( - { - template_name => "opac-MARCdetail.tt", - query => $query, - type => "opac", - authnotrequired => ( C4::Context->preference("OpacPublic") ? 1 : 0 ), - debug => 1, - } -); - -my ($bt_tag,$bt_subtag) = GetMarcFromKohaField('biblio.title',$framework); -$template->param( - bibliotitle => $biblio->title, -) if $tagslib->{$bt_tag}->{$bt_subtag}->{hidden} <= 0 && # <=0 OPAC visible. - $tagslib->{$bt_tag}->{$bt_subtag}->{hidden} > -8; # except -8; - # get biblionumbers stored in the cart if(my $cart_list = $query->cookie("bib_list")){ my @cart_list = split(/\//, $cart_list); @@ -140,6 +124,16 @@ if(my $cart_list = $query->cookie("bib_list")){ } } +$template->param( 'ItemsIssued' => CountItemsIssued( $biblionumber ) ); + +my $biblio = Koha::Biblios->find( $biblionumber ); +my $tagslib = &GetMarcStructure( 0, $framework ); +my ($bt_tag,$bt_subtag) = GetMarcFromKohaField('biblio.title',$framework); +$template->param( + bibliotitle => $biblio->title, +) if $tagslib->{$bt_tag}->{$bt_subtag}->{hidden} <= 0 && # <=0 OPAC visible. + $tagslib->{$bt_tag}->{$bt_subtag}->{hidden} > -8; # except -8; + my $allow_onshelf_holds; my $patron = Koha::Patrons->find( $loggedinuser ); for my $itm (@all_items) { @@ -148,7 +142,6 @@ for my $itm (@all_items) { } $template->param( 'AllowOnShelfHolds' => $allow_onshelf_holds ); -$template->param( 'ItemsIssued' => CountItemsIssued( $biblionumber ) ); # adding the $RequestOnOpac param my $RequestOnOpac; @@ -278,6 +271,7 @@ for ( my $tabloop = 0 ; $tabloop <= 9 ; $tabloop++ ) { # loop through each tag # warning : we may have differents number of columns in each row. Thus, we first build a hash, complete it if necessary # then construct template. +# $record has already had all the item fields filtered above. my @fields = $record->fields(); my %witness ; #---- stores the list of subfields used at least once, with the "meaning" of the code @@ -285,9 +279,6 @@ my @item_subfield_codes; my @item_loop; foreach my $field (@fields) { next if ( $field->tag() < 10 ); - next if ( ( $field->tag() eq $tag_itemnumber ) && - ( any { $field->subfield($subtag_itemnumber) eq $_ } - @items2hide) ); my @subf = $field->subfields; my $item; -- 2.1.4