View | Details | Raw Unified | Return to bug 9072
Collapse All | Expand All

(-)a/C4/AuthoritiesMarc.pm (-1 / +2 lines)
Lines 1180-1191 sub GetAuthorizedHeading { Link Here
1180
    unless ($record = $args->{record}) {
1180
    unless ($record = $args->{record}) {
1181
        return unless $args->{authid};
1181
        return unless $args->{authid};
1182
        $record = GetAuthority($args->{authid});
1182
        $record = GetAuthority($args->{authid});
1183
        return unless $record;
1183
    }
1184
    }
1184
    if (C4::Context->preference('marcflavour') eq 'UNIMARC') {
1185
    if (C4::Context->preference('marcflavour') eq 'UNIMARC') {
1185
# construct UNIMARC summary, that is quite different from MARC21 one
1186
# construct UNIMARC summary, that is quite different from MARC21 one
1186
# accepted form
1187
# accepted form
1187
        foreach my $field ($record->field('2..')) {
1188
        foreach my $field ($record->field('2..')) {
1188
            return $field->as_string('abcdefghijlmnopqrstuvwxyz');
1189
            return $field->as_string('abcdefghijklmnopqrstuvwxyz');
1189
        }
1190
        }
1190
    } else {
1191
    } else {
1191
        foreach my $field ($record->field('1..')) {
1192
        foreach my $field ($record->field('1..')) {
(-)a/C4/Heading.pm (-13 / +51 lines)
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
(-)a/C4/Linker/Default.pm (-1 / +2 lines)
Lines 40-46 sub get_link { Link Here
40
    else {
40
    else {
41
41
42
        # look for matching authorities
42
        # look for matching authorities
43
        my $authorities = $heading->authorities(1);    # $skipmetadata = true
43
        # Skip meta datas and use CheckValidity from LinkerOptions
44
        my $authorities = $heading->authorities(1, $self->{'CheckValidity'});
44
45
45
        if ( $behavior eq 'default' && $#{$authorities} == 0 ) {
46
        if ( $behavior eq 'default' && $#{$authorities} == 0 ) {
46
            $authid = $authorities->[0]->{'authid'};
47
            $authid = $authorities->[0]->{'authid'};
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/authorities.pref (-2 / +1 lines)
Lines 57-63 Authorities: Link Here
57
            - Set the following options for the authority linker
57
            - Set the following options for the authority linker
58
            - pref: LinkerOptions
58
            - pref: LinkerOptions
59
              class: multi
59
              class: multi
60
            - (separate options with |)
60
            - (separate options with |). Use : CheckValidity.
61
        -
61
        -
62
            - pref: LinkerRelink
62
            - pref: LinkerRelink
63
              default: yes
63
              default: yes
64
- 

Return to bug 9072