From 0fd441c6507ba3fe85c926314da5c7af861ed4a5 Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Fri, 26 Jan 2018 10:17:33 +0100 Subject: [PATCH] Bug 14769: Add Koha::Authority::controlled_biblio_indicators Content-Type: text/plain; charset=utf-8 --- Koha/Authority.pm | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/Koha/Authority.pm b/Koha/Authority.pm index ac2b25c..8c0211a 100644 --- a/Koha/Authority.pm +++ b/Koha/Authority.pm @@ -20,6 +20,8 @@ package Koha::Authority; use Modern::Perl; use base qw(Koha::Object); + +use Koha::Authority::BiblioIndicators; use Koha::SearchEngine::Search; =head1 NAME @@ -59,6 +61,54 @@ sub linked_biblionumbers { return Koha::Authorities->linked_biblionumbers( $params ); } +=head3 controlled_biblio_indicators + + Some authority types control the indicators of some corresponding + biblio fields (especially in MARC21). + For example, if you have a PERSO_NAME authority (report tag 100), the + first indicator of biblio field 600 directly comes from the authority, + and the second indicator depends on thesaurus settings in the authority + record. Use this method to obtain such controlled values. In this example + you should pass 600 in the biblio_tag parameter. + + my $result = $self->controlled_biblio_indicators({ + record => $auth_marc, biblio_tag => $bib_tag + }); + my $ind1 = $result->{ind1}; + my $ind2 = $result->{ind2}; + + If an indicator is not controlled, the result hash does not contain a key + for its value. + + Note: The record parameter is a temporary bypass in order to prevent + needless conversion of $self->marcxml. + +=cut + +sub controlled_biblio_indicators { + my ( $self, $params ) = @_; + my $tag = $params->{biblio_tag} // q{}; + my $record = $params->{record}; + + my $flavour = C4::Context->preference('marcflavour') eq 'UNIMARC' + ? 'UNIMARCAUTH' + : 'MARC21'; + if( !$record ) { + $record = MARC::Record->new_from_xml( + $self->marcxml, 'UTF-8', $flavour ); + } + + my $authtype = Koha::Authority::Types->find( $self->authtypecode ); + return {} if !$authtype; + + return Koha::Authority::BiblioIndicators->new->get({ + auth_record => $record, + report_tag => $authtype->auth_tag_to_report, + biblio_tag => $tag, + flavour => $flavour, + }); +} + =head2 Class Methods =head3 type -- 2.1.4