1 package Koha::Filter::MARC::ViewPolicy;
3 # Copyright 2015 Mark Tompsett
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
22 Koha::Filter::MARC::ViewPolicy - this filters a MARC record.
30 my $processor = Koha::RecordProcessor->new( { filters => ('ViewPolicy') } );
34 Filter to remove fields based on the 'Advance constraints'
35 settings found when editing a particular subfield definition of
36 a MARC bibliographic framework found under the Koha administration
45 use base qw(Koha::RecordProcessor::Base);
46 our $NAME = 'MARC_ViewPolicy';
47 our $VERSION = '3.23'; # Master version I hope it gets in.
49 =head1 SUBROUTINES/METHODS
53 my $processor = Koha::RecordProcessor->new( { filters => ('ViewPolicy') } );
55 my $newrecord = $processor->filter($record);
56 my $newrecords = $processor->filter(\@records);
58 This returns a filtered copy of the record based on the Advanced constraints
72 if ( ref($precord) eq 'ARRAY' ) {
73 @records = @{$precord};
76 push @records, $precord;
80 foreach my $current_record (@records) {
81 my $result = $current_record->clone();
82 my $interface = $self->{options}->{interface} // 'opac';
83 my $frameworkcode = $self->{options}->{frameworkcode} // q{};
84 my $display = _should_display_on_interface();
86 my $marcsubfieldstructure = GetMarcStructure( 0, $frameworkcode );
88 #if ($marcsubfieldstructure->{'000'}->{'@'}->{hidden}>0) {
89 # LDR field is excluded from $current_record->fields().
90 # if we hide it here, the MARCXML->MARC::Record->MARCXML
91 # transformation blows up.
93 foreach my $field ( $result->fields() ) {
97 marcsubfieldstructure => $marcsubfieldstructure,
99 interface => $interface,
104 push @results, $result;
107 if ( scalar @results == 1 ) {
116 my ($parameter) = @_;
118 my $field = $parameter->{field};
119 my $marcsubfieldstructure = $parameter->{marcsubfieldstructure};
120 my $display = $parameter->{display};
121 my $interface = $parameter->{interface};
122 my $result = $parameter->{result};
124 my $tag = $field->tag();
126 foreach my $subpairs ( $field->subfields() ) {
127 my ( $subtag, $value ) = @{$subpairs};
129 # visibility is a "level" (-7 to +7), default to 0
131 $marcsubfieldstructure->{$tag}->{$subtag}->{hidden};
134 if ( $display->{$interface}->{$visibility} ) {
138 # deleting last subfield doesn't delete field, so
139 # this detects that case to delete the field.
140 if ( scalar $field->subfields() <= 1 ) {
141 $result->delete_fields($field);
144 $field->delete_subfield( code => $subtag );
150 # tags less than 10 don't have subfields, use @ trick.
152 # visibility is a "level" (-7 to +7), default to 0
153 my $visibility = $marcsubfieldstructure->{$tag}->{q{@}}->{hidden};
156 if ( $display->{$interface}->{$visibility} ) {
161 $result->delete_fields($field);
171 my $options = $param->{options};
172 $self->{options} = $options;
173 $self->Koha::RecordProcessor::Base::initialize($param);
177 sub _should_display_on_interface {
205 $ prove -v t/RecordProcessor.t
206 $ prove -v t/db_dependent/RecordProcessor_ViewPolicy.t
208 =head1 CONFIGURATION AND ENVIRONMENT
210 Install Koha. This filter will be used appropriately by the OPAC or Staff client.
212 =head1 INCOMPATIBILITIES
214 This is designed for MARC::Record filtering currently. It will not handle MARC::MARCXML.
218 The following Perl libraries are required: Modern::Perl and Carp.
219 The following Koha libraries are required: C4::Biblio, Koha::RecordProcessor, and Koha::RecordProcessor::Base.
220 These should all be installed if the koha-common package is installed or Koha is otherwise installed.
222 =head1 BUGS AND LIMITATIONS
224 This is the initial version. Please feel free to report bugs
225 at http://bugs.koha-community.org/.
231 =head1 LICENSE AND COPYRIGHT
233 Copyright 2015 Mark Tompsett
235 This file is part of Koha.
237 Koha is free software; you can redistribute it and/or modify it
238 under the terms of the GNU General Public License as published by
239 the Free Software Foundation; either version 3 of the License, or
240 (at your option) any later version.
242 Koha is distributed in the hope that it will be useful, but
243 WITHOUT ANY WARRANTY; without even the implied warranty of
244 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
245 GNU General Public License for more details.
247 You should have received a copy of the GNU General Public License
248 along with Koha; if not, see <http://www.gnu.org/licenses>.