From 861b3a40df12121626f366ca6dc8e3f4ac0a93c3 Mon Sep 17 00:00:00 2001 From: Robin Sheat Date: Tue, 20 May 2014 17:15:52 +1200 Subject: [PATCH] Bug 12252 - OAI-PMH items respect OpacHiddenItems This allows the OAI-PMH service to not provide item information when there is a rule that would supress it in OpacHiddenItems. Test plan: * Find an OAI-PMH URL that shows you some items. * Add an entry to OpacHiddenItems that would block that. * Check that it's blocked. --- C4/Biblio.pm | 65 +++++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 51 insertions(+), 14 deletions(-) diff --git a/C4/Biblio.pm b/C4/Biblio.pm index b6f98b4..d404dc9 100644 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -1261,18 +1261,34 @@ sub GetMarcSubfieldStructureFromKohaField { =head2 GetMarcBiblio - my $record = GetMarcBiblio($biblionumber, [$embeditems]); + my $record = GetMarcBiblio($biblionumber, [$embeditems], [$opac]); -Returns MARC::Record representing bib identified by -C<$biblionumber>. If no bib exists, returns undef. -C<$embeditems>. If set to true, items data are included. -The MARC record contains biblio data, and items data if $embeditems is set to true. +Returns MARC::Record representing a biblio record, or C if the +biblionumber doesn't exist. + +=over 4 + +=item C<$biblionumber> + +the biblionumber + +=item C<$embeditems> + +set to true to include item information. + +=item C<$opac> + +set to true to make the result suited for OPAC view. This causes things like +OpacHiddenItems to be applied. + +=back =cut sub GetMarcBiblio { my $biblionumber = shift; my $embeditems = shift || 0; + my $opac = shift || 0; my $dbh = C4::Context->dbh; my $sth = $dbh->prepare("SELECT marcxml FROM biblioitems WHERE biblionumber=? "); $sth->execute($biblionumber); @@ -1282,15 +1298,21 @@ sub GetMarcBiblio { my $record = MARC::Record->new(); if ($marcxml) { - $record = eval { MARC::Record::new_from_xml( $marcxml, "utf8", C4::Context->preference('marcflavour') ) }; + $record = eval { + MARC::Record::new_from_xml( $marcxml, "utf8", + C4::Context->preference('marcflavour') ); + }; if ($@) { warn " problem with :$biblionumber : $@ \n$marcxml"; } return unless $record; - C4::Biblio::_koha_marc_update_bib_ids($record, '', $biblionumber, $biblionumber); - C4::Biblio::EmbedItemsInMarcBiblio($record, $biblionumber) if ($embeditems); + C4::Biblio::_koha_marc_update_bib_ids( $record, '', $biblionumber, + $biblionumber ); + C4::Biblio::EmbedItemsInMarcBiblio( $record, $biblionumber, undef, $opac ) + if ($embeditems); return $record; - } else { + } + else { return; } } @@ -2882,12 +2904,14 @@ sub ModZebra { =head2 EmbedItemsInMarcBiblio - EmbedItemsInMarcBiblio($marc, $biblionumber, $itemnumbers); + EmbedItemsInMarcBiblio($marc, $biblionumber, $itemnumbers, $opac); Given a MARC::Record object containing a bib record, modify it to include the items attached to it as 9XX per the bib's MARC framework. -if $itemnumbers is defined, only specified itemnumbers are embedded +if $itemnumbers is defined, only specified itemnumbers are embedded. + +If $opac is true, then opac-relevant suppressions are included. =cut @@ -2909,10 +2933,23 @@ sub EmbedItemsInMarcBiblio { $sth->execute($biblionumber); my @item_fields; my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField( "items.itemnumber", $frameworkcode ); - while (my ($itemnumber) = $sth->fetchrow_array) { + my @items; + my $opachiddenitems = + ( C4::Context->preference('OpacHiddenItems') !~ /^\s*$/ ); + require C4::Items; + while ( my ($itemnumber) = $sth->fetchrow_array ) { next if @$itemnumbers and not grep { $_ == $itemnumber } @$itemnumbers; - require C4::Items; - my $item_marc = C4::Items::GetMarcItem($biblionumber, $itemnumber); + my $i = C4::Items::GetItem($itemnumber) if $opachiddenitems; + push @items, { itemnumber => $itemnumber, item => $i }; + } + my @hiddenitems = + C4::Items::GetHiddenItemnumbers( map { $_->{item} } @items ) + if $opachiddenitems; + # Convert to a hash for quick searching + my %hiddenitems = map { $_ => 1 } @hiddenitems; + foreach my $itemnumber ( map { $_->{itemnumber} } @items ) { + next if $hiddenitems{$itemnumber}; + my $item_marc = C4::Items::GetMarcItem( $biblionumber, $itemnumber ); push @item_fields, $item_marc->field($itemtag); } $marc->append_fields(@item_fields); -- 1.8.3.2