From dabe713390d4a7acac3cbb0be652828da075321d Mon Sep 17 00:00:00 2001 From: Fridolyn SOMERS Date: Fri, 16 Nov 2012 16:33:32 +0100 Subject: [PATCH 1/4] Bug 9072: Add CheckValidity option to Linker --- C4/AuthoritiesMarc.pm | 3 +- C4/Heading.pm | 64 ++++++++++++++++---- C4/Linker/Default.pm | 3 +- .../en/modules/admin/preferences/authorities.pref | 2 +- 4 files changed, 56 insertions(+), 16 deletions(-) diff --git a/C4/AuthoritiesMarc.pm b/C4/AuthoritiesMarc.pm index db340ba..f0345ea 100644 --- a/C4/AuthoritiesMarc.pm +++ b/C4/AuthoritiesMarc.pm @@ -1180,12 +1180,13 @@ sub GetAuthorizedHeading { unless ($record = $args->{record}) { return unless $args->{authid}; $record = GetAuthority($args->{authid}); + return unless $record; } if (C4::Context->preference('marcflavour') eq 'UNIMARC') { # construct UNIMARC summary, that is quite different from MARC21 one # accepted form foreach my $field ($record->field('2..')) { - return $field->as_string('abcdefghijlmnopqrstuvwxyz'); + return $field->as_string('abcdefghijklmnopqrstuvwxyz'); } } else { foreach my $field ($record->field('1..')) { diff --git a/C4/Heading.pm b/C4/Heading.pm index dca4d1b..bc2f7c1 100644 --- a/C4/Heading.pm +++ b/C4/Heading.pm @@ -140,35 +140,60 @@ sub search_form { =head2 authorities - my $authorities = $heading->authorities([$skipmetadata]); + my $authorities = $heading->authorities([$skipmetadata][$checkvalidity]); -Return a list of authority records for this -heading. If passed a true value for $skipmetadata, -SearchAuthorities will return only authids. +Return a list of authority records for this heading. +If passed a true value for $skipmetadata, SearchAuthorities will return only authids. +If passed a true value for $checkvalidity, SearchAuthorities will check authorities validity. =cut sub authorities { my $self = shift; my $skipmetadata = shift; - my ( $results, $total ) = _search( $self, 'match-heading', $skipmetadata ); - return $results; + my $checkvalidity = shift; + return $self->_search( 'match-heading', $skipmetadata, $checkvalidity ); } =head2 preferred_authorities my $preferred_authorities = $heading->preferred_authorities; -Return a list of authority records for headings -that are a preferred form of the heading. +Return a list of authority records for this heading that are a preferred form of the heading. +If passed a true value for $skipmetadata, SearchAuthorities will return only authids. +If passed a true value for $checkvalidity, SearchAuthorities will check authorities validity. =cut sub preferred_authorities { my $self = shift; - my $skipmetadata = shift || undef; - my ( $results, $total ) = _search( 'see-from', $skipmetadata ); - return $results; + my $skipmetadata = shift; + my $checkvalidity = shift; + return $self->_search( 'see-from', $skipmetadata, $checkvalidity ); +} + +=head2 check_link_validity + + my $isvalid = $heading->check_valid_auth_link($authid); + +Check whether the link with specified auth is valid. + +=cut + +sub check_valid_auth_link { + #TODO should be merged with C4::Biblio->_check_valid_auth_link + my $self = shift; + my $authid = shift; + + my $field_value = $self->{'field'}->as_string('abcdefghijklmnopqrstuvwxyz'); + return unless $field_value; + + require C4::AuthoritiesMarc; + my $authorized_heading = + C4::AuthoritiesMarc::GetAuthorizedHeading( { 'authid' => $authid } ); + return unless $authorized_heading; + + return ($field_value eq $authorized_heading); } =head1 INTERNAL METHODS @@ -181,6 +206,7 @@ sub _search { my $self = shift; my $index = shift || undef; my $skipmetadata = shift || undef; + my $checkvalidity = shift || undef; my @marclist; my @and_or; my @excluding = []; @@ -202,11 +228,23 @@ sub _search { # push @value, $self->{'thesaurus'}; # } require C4::AuthoritiesMarc; - return C4::AuthoritiesMarc::SearchAuthorities( + my ( $authorities, $nbresults ) = C4::AuthoritiesMarc::SearchAuthorities( \@marclist, \@and_or, \@excluding, \@operator, - \@value, 0, 20, $self->{'auth_type'}, + \@value, 0, 10000, $self->{'auth_type'}, 'AuthidAsc', $skipmetadata ); + + if ($checkvalidity) { + my @authorities_cheked; + foreach (@$authorities) { + if ( $self->check_valid_auth_link( $_->{'authid'} ) ) { + push @authorities_cheked, $_; + } + } + $authorities = \@authorities_cheked; + } + + return $authorities; } =head1 INTERNAL FUNCTIONS diff --git a/C4/Linker/Default.pm b/C4/Linker/Default.pm index 445b408..ac49187 100644 --- a/C4/Linker/Default.pm +++ b/C4/Linker/Default.pm @@ -40,7 +40,8 @@ sub get_link { else { # look for matching authorities - my $authorities = $heading->authorities(1); # $skipmetadata = true + # Skip meta datas and use CheckValidity from LinkerOptions + my $authorities = $heading->authorities(1, $self->{'CheckValidity'}); if ( $behavior eq 'default' && $#{$authorities} == 0 ) { $authid = $authorities->[0]->{'authid'}; diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/authorities.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/authorities.pref index f4cc9e3..35d2a4c 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/authorities.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/authorities.pref @@ -57,7 +57,7 @@ Authorities: - Set the following options for the authority linker - pref: LinkerOptions class: multi - - (separate options with |) + - (separate options with |). Use : CheckValidity. - - pref: LinkerRelink default: yes -- 1.7.9.5