Lines 89-109
sub filter {
Link Here
|
89 |
unless ( exists $self->{_cached_frameworks}->{$frameworkcode} ) { |
89 |
unless ( exists $self->{_cached_frameworks}->{$frameworkcode} ) { |
90 |
$self->{_cached_frameworks}->{$frameworkcode} = GetMarcStructure( 0, $frameworkcode, { unsafe => 1 } ); |
90 |
$self->{_cached_frameworks}->{$frameworkcode} = GetMarcStructure( 0, $frameworkcode, { unsafe => 1 } ); |
91 |
} |
91 |
} |
92 |
|
|
|
93 |
my $marcsubfieldstructure = $self->{_cached_frameworks}->{$frameworkcode}; |
92 |
my $marcsubfieldstructure = $self->{_cached_frameworks}->{$frameworkcode}; |
|
|
93 |
unless ( exists $self->{_cached_hidden_fields}->{$frameworkcode}->{$interface} ){ |
94 |
$self->{_cached_hidden_fields}->{$frameworkcode}->{$interface} = |
95 |
_get_hidden_fields_from_framework({ |
96 |
marcsubfieldstructure => $marcsubfieldstructure, |
97 |
hide => $hide, |
98 |
interface => $interface, |
99 |
}); |
100 |
} |
101 |
my $hidden_fields = $self->{_cached_hidden_fields}->{$frameworkcode}->{$interface}; |
94 |
|
102 |
|
95 |
#if ($marcsubfieldstructure->{'000'}->{'@'}->{hidden}>0) { |
103 |
#if ($marcsubfieldstructure->{'000'}->{'@'}->{hidden}>0) { |
96 |
# LDR field is excluded from $current_record->fields(). |
104 |
# LDR field is excluded from $current_record->fields(). |
97 |
# if we hide it here, the MARCXML->MARC::Record->MARCXML |
105 |
# if we hide it here, the MARCXML->MARC::Record->MARCXML |
98 |
# transformation blows up. |
106 |
# transformation blows up. |
99 |
#} |
107 |
#} |
100 |
foreach my $field ( $result->fields() ) { |
108 |
foreach my $field ( keys %{$hidden_fields} ) { |
101 |
_filter_field( |
109 |
_filter_field( |
102 |
{ |
110 |
{ |
103 |
field => $field, |
111 |
field => $field, |
104 |
marcsubfieldstructure => $marcsubfieldstructure, |
112 |
subfields => $hidden_fields->{$field}, |
105 |
hide => $hide, |
|
|
106 |
interface => $interface, |
107 |
result => $result |
113 |
result => $result |
108 |
} |
114 |
} |
109 |
); |
115 |
); |
Lines 112-161
sub filter {
Link Here
|
112 |
return; |
118 |
return; |
113 |
} |
119 |
} |
114 |
|
120 |
|
115 |
sub _filter_field { |
121 |
sub _get_hidden_fields_from_framework { |
116 |
my ($parameter) = @_; |
122 |
my ($params) = @_; |
117 |
|
123 |
my $mss = $params->{marcsubfieldstructure}; |
118 |
my $field = $parameter->{field}; |
124 |
my $interface = $params->{interface}; |
119 |
my $marcsubfieldstructure = $parameter->{marcsubfieldstructure}; |
125 |
my $hide = $params->{hide}; |
120 |
my $hide = $parameter->{hide}; |
126 |
my $hidden_fields; |
121 |
my $interface = $parameter->{interface}; |
127 |
foreach my $tag (keys %{$mss}) { |
122 |
my $result = $parameter->{result}; |
128 |
if ( $tag >= FIRST_NONCONTROL_TAG ) { |
123 |
|
129 |
foreach my $subtag (keys %{$mss->{$tag}}) { |
124 |
my $tag = $field->tag(); |
130 |
next unless ref $mss->{$tag}->{$subtag} eq 'HASH'; |
125 |
if ( $tag >= FIRST_NONCONTROL_TAG ) { |
131 |
my $visibility = $mss->{$tag}->{$subtag}->{hidden}; |
126 |
foreach my $subpairs ( $field->subfields() ) { |
132 |
$visibility //= 0; |
127 |
my ( $subtag, $value ) = @{$subpairs}; |
133 |
if( $hide->{$interface}->{$visibility}){ |
128 |
|
134 |
$hidden_fields->{$tag}->{$subtag} = 1; |
|
|
135 |
} |
136 |
} |
137 |
} else { |
129 |
# visibility is a "level" (-9 to +9), default to 0 |
138 |
# visibility is a "level" (-9 to +9), default to 0 |
130 |
# -8 is flagged, and 9/-9 are not implemented. |
139 |
# -8 is flagged, and 9/-9 are not implemented. |
131 |
my $visibility = |
140 |
my $visibility = $mss->{$tag}->{q{@}}->{hidden}; |
132 |
$marcsubfieldstructure->{$tag}->{$subtag}->{hidden}; |
|
|
133 |
$visibility //= 0; |
141 |
$visibility //= 0; |
134 |
if ( $hide->{$interface}->{$visibility} ) { |
142 |
if ( $hide->{$interface}->{$visibility} ) { |
|
|
143 |
$hidden_fields->{$tag}->{q{@}} = 1; |
144 |
} |
145 |
} |
146 |
} |
147 |
return $hidden_fields; |
148 |
} |
149 |
|
150 |
|
151 |
sub _filter_field { |
152 |
my ($parameter) = @_; |
135 |
|
153 |
|
|
|
154 |
my $field = $parameter->{field}; |
155 |
my $subfields = $parameter->{subfields}; |
156 |
my $result = $parameter->{result}; |
157 |
|
158 |
my @result_fields = $result->field($field); |
159 |
return unless @result_fields; |
160 |
foreach my $result_field ( @result_fields ){ |
161 |
if ( $field >= FIRST_NONCONTROL_TAG ) { |
162 |
foreach my $subfield ( keys %{$subfields}) { |
136 |
# deleting last subfield doesn't delete field, so |
163 |
# deleting last subfield doesn't delete field, so |
137 |
# this detects that case to delete the field. |
164 |
# this detects that case to delete the field. |
138 |
if ( scalar $field->subfields() <= 1 ) { |
165 |
if ( scalar $result_field->subfields() <= 1 ) { |
139 |
$result->delete_fields($field); |
166 |
$result->delete_fields($result_field); |
140 |
} |
167 |
} |
141 |
else { |
168 |
else { |
142 |
$field->delete_subfield( code => $subtag ); |
169 |
$result_field->delete_subfield( code => $subfield ); |
143 |
} |
170 |
} |
144 |
} |
171 |
} |
|
|
172 |
} else { |
173 |
$result->delete_fields($result_field); |
145 |
} |
174 |
} |
146 |
} |
175 |
} |
147 |
|
176 |
|
148 |
# control tags don't have subfields, use @ trick. |
|
|
149 |
else { |
150 |
# visibility is a "level" (-9 to +9), default to 0 |
151 |
# -8 is flagged, and 9/-9 are not implemented. |
152 |
my $visibility = $marcsubfieldstructure->{$tag}->{q{@}}->{hidden}; |
153 |
$visibility //= 0; |
154 |
if ( $hide->{$interface}->{$visibility} ) { |
155 |
$result->delete_fields($field); |
156 |
} |
157 |
|
158 |
} |
159 |
return; |
177 |
return; |
160 |
} |
178 |
} |
161 |
|
179 |
|
162 |
- |
|
|