1 package Koha::Authority::MergeRequest;
3 # Copyright Rijksmuseum 2017
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 3 of the License, or (at your option) any later
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 use parent qw(Koha::Object);
24 use Koha::Authorities;
25 use Koha::Authority::Types;
29 Koha::Authority::MergeRequest - Koha::Object class for single need_merge_authorities record
33 use Koha::Authority::MergeRequest;
41 =head2 INSTANCE METHODS
47 [ authid_new => $new, ]
48 [ oldrecord => $marc, ]
51 authid refers to the old authority id,
52 authid_new optionally refers to a new different authority id
54 oldrecord is the MARC record belonging to the original authority record
56 This method returns an object and initializes the reportxml property.
61 my ( $class, $params ) = @_;
62 my $oldrecord = delete $params->{oldrecord};
63 delete $params->{reportxml}; # just making sure it is empty
64 my $self = $class->SUPER::new( $params );
66 if( $self->authid && $oldrecord ) {
67 my $auth = Koha::Authorities->find( $self->authid );
68 my $type = $auth ? Koha::Authority::Types->find($auth->authtypecode) : undef;
69 $self->reportxml( $self->reporting_tag_xml({ record => $oldrecord, tag => $type->auth_tag_to_report })) if $type;
76 my $record = $self->oldmarc;
78 Convert reportxml back to MARC::Record.
84 return if !$self->reportxml;
85 return MARC::Record->new_from_xml( $self->reportxml, 'UTF-8' );
90 =head3 reporting_tag_xml
92 my $xml = Koha::Authority::MergeRequest->reporting_tag_xml({
93 record => $record, tag => $tag,
98 sub reporting_tag_xml {
99 my ( $class, $params ) = @_;
100 return if !$params->{record} || !$params->{tag};
102 my $newrecord = MARC::Record->new;
103 $newrecord->encoding( 'UTF-8' );
104 my $reportfield = $params->{record}->field( $params->{tag} );
105 return if !$reportfield;
107 # For UNIMARC we need a field 100 that includes the encoding
108 # at position 13 and 14
109 if( C4::Context->preference('marcflavour') eq 'UNIMARC' ) {
110 $newrecord->append_fields(
111 MARC::Field->new( '100', '', '', a => ' 'x13 . '50' ),
115 $newrecord->append_fields( $reportfield );
116 return $newrecord->as_xml(
117 C4::Context->preference('marcflavour') eq 'UNIMARC' ?
125 Returns name of corresponding DBIC resultset
130 return 'NeedMergeAuthority';
135 Marcel de Rooy (Rijksmuseum)
137 Koha Development Team