Lines 140-174
sub search_form {
Link Here
|
140 |
|
140 |
|
141 |
=head2 authorities |
141 |
=head2 authorities |
142 |
|
142 |
|
143 |
my $authorities = $heading->authorities([$skipmetadata]); |
143 |
my $authorities = $heading->authorities([$skipmetadata][$checkvalidity]); |
144 |
|
144 |
|
145 |
Return a list of authority records for this |
145 |
Return a list of authority records for this heading. |
146 |
heading. If passed a true value for $skipmetadata, |
146 |
If passed a true value for $skipmetadata, SearchAuthorities will return only authids. |
147 |
SearchAuthorities will return only authids. |
147 |
If passed a true value for $checkvalidity, SearchAuthorities will check authorities validity. |
148 |
|
148 |
|
149 |
=cut |
149 |
=cut |
150 |
|
150 |
|
151 |
sub authorities { |
151 |
sub authorities { |
152 |
my $self = shift; |
152 |
my $self = shift; |
153 |
my $skipmetadata = shift; |
153 |
my $skipmetadata = shift; |
154 |
my ( $results, $total ) = _search( $self, 'match-heading', $skipmetadata ); |
154 |
my $checkvalidity = shift; |
155 |
return $results; |
155 |
return $self->_search( 'match-heading', $skipmetadata, $checkvalidity ); |
156 |
} |
156 |
} |
157 |
|
157 |
|
158 |
=head2 preferred_authorities |
158 |
=head2 preferred_authorities |
159 |
|
159 |
|
160 |
my $preferred_authorities = $heading->preferred_authorities; |
160 |
my $preferred_authorities = $heading->preferred_authorities; |
161 |
|
161 |
|
162 |
Return a list of authority records for headings |
162 |
Return a list of authority records for this heading that are a preferred form of the heading. |
163 |
that are a preferred form of the heading. |
163 |
If passed a true value for $skipmetadata, SearchAuthorities will return only authids. |
|
|
164 |
If passed a true value for $checkvalidity, SearchAuthorities will check authorities validity. |
164 |
|
165 |
|
165 |
=cut |
166 |
=cut |
166 |
|
167 |
|
167 |
sub preferred_authorities { |
168 |
sub preferred_authorities { |
168 |
my $self = shift; |
169 |
my $self = shift; |
169 |
my $skipmetadata = shift || undef; |
170 |
my $skipmetadata = shift; |
170 |
my ( $results, $total ) = _search( 'see-from', $skipmetadata ); |
171 |
my $checkvalidity = shift; |
171 |
return $results; |
172 |
return $self->_search( 'see-from', $skipmetadata, $checkvalidity ); |
|
|
173 |
} |
174 |
|
175 |
=head2 check_link_validity |
176 |
|
177 |
my $isvalid = $heading->check_valid_auth_link($authid); |
178 |
|
179 |
Check whether the link with specified auth is valid. |
180 |
|
181 |
=cut |
182 |
|
183 |
sub check_valid_auth_link { |
184 |
#TODO should be merged with C4::Biblio->_check_valid_auth_link |
185 |
my $self = shift; |
186 |
my $authid = shift; |
187 |
|
188 |
my $field_value = $self->{'field'}->as_string('abcdefghijklmnopqrstuvwxyz'); |
189 |
return unless $field_value; |
190 |
|
191 |
require C4::AuthoritiesMarc; |
192 |
my $authorized_heading = |
193 |
C4::AuthoritiesMarc::GetAuthorizedHeading( { 'authid' => $authid } ); |
194 |
return unless $authorized_heading; |
195 |
|
196 |
return ($field_value eq $authorized_heading); |
172 |
} |
197 |
} |
173 |
|
198 |
|
174 |
=head1 INTERNAL METHODS |
199 |
=head1 INTERNAL METHODS |
Lines 181-186
sub _search {
Link Here
|
181 |
my $self = shift; |
206 |
my $self = shift; |
182 |
my $index = shift || undef; |
207 |
my $index = shift || undef; |
183 |
my $skipmetadata = shift || undef; |
208 |
my $skipmetadata = shift || undef; |
|
|
209 |
my $checkvalidity = shift || undef; |
184 |
my @marclist; |
210 |
my @marclist; |
185 |
my @and_or; |
211 |
my @and_or; |
186 |
my @excluding = []; |
212 |
my @excluding = []; |
Lines 202-212
sub _search {
Link Here
|
202 |
# push @value, $self->{'thesaurus'}; |
228 |
# push @value, $self->{'thesaurus'}; |
203 |
# } |
229 |
# } |
204 |
require C4::AuthoritiesMarc; |
230 |
require C4::AuthoritiesMarc; |
205 |
return C4::AuthoritiesMarc::SearchAuthorities( |
231 |
my ( $authorities, $nbresults ) = C4::AuthoritiesMarc::SearchAuthorities( |
206 |
\@marclist, \@and_or, \@excluding, \@operator, |
232 |
\@marclist, \@and_or, \@excluding, \@operator, |
207 |
\@value, 0, 20, $self->{'auth_type'}, |
233 |
\@value, 0, 10000, $self->{'auth_type'}, |
208 |
'AuthidAsc', $skipmetadata |
234 |
'AuthidAsc', $skipmetadata |
209 |
); |
235 |
); |
|
|
236 |
|
237 |
if ($checkvalidity) { |
238 |
my @authorities_cheked; |
239 |
foreach (@$authorities) { |
240 |
if ( $self->check_valid_auth_link( $_->{'authid'} ) ) { |
241 |
push @authorities_cheked, $_; |
242 |
} |
243 |
} |
244 |
$authorities = \@authorities_cheked; |
245 |
} |
246 |
|
247 |
return $authorities; |
210 |
} |
248 |
} |
211 |
|
249 |
|
212 |
=head1 INTERNAL FUNCTIONS |
250 |
=head1 INTERNAL FUNCTIONS |