From b8766376ad0164d6c9cce0e50f84951d799d3d60 Mon Sep 17 00:00:00 2001 From: Mark Tompsett Date: Wed, 16 Mar 2016 17:10:02 -0400 Subject: [PATCH] Add ShouldHideMARC to ViewPolicy filter https://bugs.koha-community.org/show_bug.cgi?id=11592 --- Koha/Filter/MARC/ViewPolicy.pm | 57 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/Koha/Filter/MARC/ViewPolicy.pm b/Koha/Filter/MARC/ViewPolicy.pm index 98df72d..0515cec 100644 --- a/Koha/Filter/MARC/ViewPolicy.pm +++ b/Koha/Filter/MARC/ViewPolicy.pm @@ -215,6 +215,63 @@ sub _should_hide_on_interface { return $hide; } + +=head2 ShouldHideMARC + +Return a hash reference of whether a field, built from +kohafield and tag, is hidden (1) or not (0) for a given +interface + + my $OpacHideMARC = + GetOpacHideMARC( { + frameworkcode => $frameworkcode, + interface => 'opac', + } ); + + if ($OpacHideMARC->{'stocknumber'}==1) { + print "Hidden!\n"; + } + +C<$OpacHideMARC> is a ref to a hash which contains a series +of key value pairs indicating if that field (key) is +hidden (value == 1) or not (value == 0). + +C<$frameworkcode> is the framework code. + +C<$interface> is the interface. It defaults to 'opac' if +nothing is passed. Valid values include 'opac' or 'intranet'. + +=cut + +sub ShouldHideMARC { + my ($self,$parms) = @_; + my $frameworkcode = $parms->{frameworkcode} // ''; + my $interface = $parms->{interface} // 'opac'; + my $hide = _should_hide_on_interface(); + + my $dbh = C4::Context->dbh; + my $sth = $dbh->prepare("SELECT kohafield AS field, tagfield AS tag, hidden FROM marc_subfield_structure WHERE kohafield>'' AND frameworkcode=? ORDER BY field, tagfield;"); + $sth->execute($frameworkcode); + + my %shouldhidemarc; + my $data = $sth->fetchall_hashref( [ qw(field tag) ] ); + foreach my $fullfield (keys %{$data}) { + my @tmpsplit = split(/\./,$fullfield); + my $field = $tmpsplit[-1]; + foreach my $tag (keys %{$data->{$fullfield}}) { + my $shouldhide = $hide->{$interface}->{ $data->{$fullfield}->{$tag}->{'hidden'} }; + if ($shouldhide) { + $shouldhidemarc{ $field } = 1; + } + elsif ( !exists($shouldhidemarc{ $field }) ) { + $shouldhidemarc{ $field } = 0; + } + } + } + return \%shouldhidemarc; +} + + =head1 DIAGNOSTICS $ prove -v t/RecordProcessor.t -- 2.1.4