Bug 9988: Add Koha objects for table need_merge_authorities
[koha.git] / Koha / Authority / MergeRequest.pm
1 package Koha::Authority::MergeRequest;
2
3 # Copyright Rijksmuseum 2017
4 #
5 # This file is part of Koha.
6 #
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
10 # version.
11 #
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.
15 #
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.
19
20 use Modern::Perl;
21
22 use parent qw(Koha::Object);
23
24 use Koha::Authorities;
25 use Koha::Authority::MergeRequests;
26 use Koha::Authority::Types;
27
28 =head1 NAME
29
30 Koha::Authority::MergeRequest - Koha::Object class for single need_merge_authorities record
31
32 =head1 SYNOPSIS
33
34 use Koha::Authority::MergeRequest;
35
36 =head1 DESCRIPTION
37
38 Description
39
40 =head1 METHODS
41
42 =head2 INSTANCE METHODS
43
44 =head3 new
45
46     $self->new({
47         authid => $id,
48         [ authid_new => $new, ]
49         [ oldrecord => $marc, ]
50     });
51
52     authid refers to the old authority id,
53     authid_new optionally refers to a new different authority id
54
55     oldrecord is the MARC record belonging to the original authority record
56
57     This method returns an object and initializes the reportxml property.
58
59 =cut
60
61 sub new {
62     my ( $class, $params ) = @_;
63     my $oldrecord = delete $params->{oldrecord};
64     delete $params->{reportxml}; # just making sure it is empty
65     my $self = $class->SUPER::new( $params );
66
67     if( $self->authid && $oldrecord ) {
68         my $auth = Koha::Authorities->find( $self->authid );
69         my $type = $auth ? Koha::Authority::Types->find($auth->authtypecode) : undef;
70         $self->reportxml( Koha::Authority::MergeRequests->reporting_tag_xml({ record => $oldrecord, tag => $type->auth_tag_to_report })) if $type;
71     }
72     return $self;
73 }
74
75 =head3 oldmarc
76
77     my $record = $self->oldmarc;
78
79     Convert reportxml back to MARC::Record.
80
81 =cut
82
83 sub oldmarc {
84     my ( $self ) = @_;
85     return if !$self->reportxml;
86     return MARC::Record->new_from_xml( $self->reportxml, 'UTF-8' );
87 }
88
89 =head2 CLASS METHODS
90
91 =head3 _type
92
93 Returns name of corresponding DBIC resultset
94
95 =cut
96
97 sub _type {
98     return 'NeedMergeAuthority';
99 }
100
101 =head1 AUTHOR
102
103 Marcel de Rooy (Rijksmuseum)
104
105 Koha Development Team
106
107 =cut
108
109 1;