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

(-)a/Koha/Authority.pm (-2 / +3 lines)
Lines 38-46 use MARC::Record; Link Here
38
use MARC::File::XML;
38
use MARC::File::XML;
39
use C4::Charset;
39
use C4::Charset;
40
40
41
use base qw(Class::Accessor);
41
use base qw(Koha::Record);
42
42
43
__PACKAGE__->mk_accessors(qw( authid authtype record marcflavour ));
43
__PACKAGE__->mk_accessors(qw( authid authtype marcflavour ));
44
44
45
=head2 new
45
=head2 new
46
46
Lines 59-64 sub new { Link Here
59
    return $self;
59
    return $self;
60
}
60
}
61
61
62
62
=head2 get_from_authid
63
=head2 get_from_authid
63
64
64
    my $auth = Koha::Authority->get_from_authid($authid);
65
    my $auth = Koha::Authority->get_from_authid($authid);
(-)a/Koha/Record.pm (+115 lines)
Line 0 Link Here
1
package Koha::Record;
2
3
# Copyright 2013 C & P Bibliography Services
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
=head1 NAME
21
22
Koha::Record - base class for MARC records
23
24
=head1 SYNOPSIS
25
26
    my $record = new Koha::Record({ 'record' => $marcrecord });
27
28
=head1 DESCRIPTION
29
30
Object-oriented class that encapsulates all records in Koha.
31
32
=cut
33
34
use strict;
35
use warnings;
36
use C4::Context;
37
use MARC::Record;
38
39
use base qw(Class::Accessor);
40
41
__PACKAGE__->mk_accessors(qw( record marcflavour ));
42
43
44
=head2 createMarcHash
45
46
Create a MARC hash for use when merging records.
47
48
=cut
49
50
sub createMarcHash {
51
    my ($self, $tagslib) = @_;
52
    my $record = $self->record;
53
    my @array;
54
    my @fields = $record->fields();
55
56
57
    foreach my $field (@fields) {
58
    my $fieldtag = $field->tag();
59
    if ($fieldtag < 10) {
60
        if (!defined($tagslib) || $tagslib->{$fieldtag}->{'@'}->{'tab'} >= 0) {
61
        push @array, {
62
            field => [
63
                    {
64
                    tag => $fieldtag,
65
                    key => _createKey(),
66
                    value => $field->data(),
67
                    }
68
                ]
69
                };
70
        }
71
    } else {
72
        my @subfields = $field->subfields();
73
        my @subfield_array;
74
        foreach my $subfield (@subfields) {
75
        if (!defined($tagslib) || $tagslib->{$fieldtag}->{@$subfield[0]}->{'tab'} >= 0) {
76
            push @subfield_array, {
77
                                    subtag => @$subfield[0],
78
                                    subkey => _createKey(),
79
                                    value => @$subfield[1],
80
                                  };
81
        }
82
83
        }
84
85
        if ((!defined($tagslib) || $tagslib->{$fieldtag}->{'tab'} >= 0) && $fieldtag ne '995' && $fieldtag ne '999') {
86
        push @array, {
87
            field => [
88
                {
89
                    tag => $fieldtag,
90
                    key => _createKey(),
91
                    indicator1 => $field->indicator(1),
92
                    indicator2 => $field->indicator(2),
93
                    subfield   => [@subfield_array],
94
                }
95
            ]
96
            };
97
        }
98
99
    }
100
    }
101
    return [@array];
102
103
}
104
105
=head2 _createKey
106
107
Create a random value to set it into the input name
108
109
=cut
110
111
sub _createKey {
112
    return int(rand(1000000));
113
}
114
115
1;
(-)a/cataloguing/merge.pl (-67 / +7 lines)
Lines 30-35 use C4::Serials; Link Here
30
use C4::Koha;
30
use C4::Koha;
31
use C4::Reserves qw/MergeHolds/;
31
use C4::Reserves qw/MergeHolds/;
32
use C4::Acquisition qw/ModOrder GetOrdersByBiblionumber/;
32
use C4::Acquisition qw/ModOrder GetOrdersByBiblionumber/;
33
use Koha::Record;
33
34
34
my $input = new CGI;
35
my $input = new CGI;
35
my @biblionumber = $input->param('biblionumber');
36
my @biblionumber = $input->param('biblionumber');
Lines 168-175 if ($merge) { Link Here
168
            my $notreference = ($biblionumber[0] == $mergereference) ? $biblionumber[1] : $biblionumber[0];
169
            my $notreference = ($biblionumber[0] == $mergereference) ? $biblionumber[1] : $biblionumber[0];
169
170
170
            # Creating a loop for display
171
            # Creating a loop for display
171
            my @record1 = _createMarcHash(GetMarcBiblio($mergereference), $tagslib);
172
172
            my @record2 = _createMarcHash(GetMarcBiblio($notreference), $tagslib);
173
            my $recordObj1 = new Koha::Record({ 'record' => GetMarcBiblio($mergereference) });
174
            my $recordObj2 = new Koha::Record({ 'record' => GetMarcBiblio($notreference) });
175
176
            my @record1 = $recordObj1->createMarcHash($tagslib);
177
            my @record2 = $recordObj2->createMarcHash($tagslib);
173
178
174
            # Parameters
179
            # Parameters
175
            $template->param(
180
            $template->param(
Lines 231-298 exit; Link Here
231
# ------------------------
236
# ------------------------
232
# Functions
237
# Functions
233
# ------------------------
238
# ------------------------
234
sub _createMarcHash {
235
     my $record = shift;
236
    my $tagslib = shift;
237
    my @array;
238
    my @fields = $record->fields();
239
240
241
    foreach my $field (@fields) {
242
    my $fieldtag = $field->tag();
243
    if ($fieldtag < 10) {
244
        if ($tagslib->{$fieldtag}->{'@'}->{'tab'} >= 0) {
245
        push @array, {
246
            field => [
247
                    {
248
                    tag => $fieldtag,
249
                    key => createKey(),
250
                    value => $field->data(),
251
                    }
252
                ]
253
                };
254
        }
255
    } else {
256
        my @subfields = $field->subfields();
257
        my @subfield_array;
258
        foreach my $subfield (@subfields) {
259
        if ($tagslib->{$fieldtag}->{@$subfield[0]}->{'tab'} >= 0) {
260
            push @subfield_array, {
261
                                    subtag => @$subfield[0],
262
                                    subkey => createKey(),
263
                                    value => @$subfield[1],
264
                                  };
265
        }
266
267
        }
268
269
        if ($tagslib->{$fieldtag}->{'tab'} >= 0 && $fieldtag ne '995') {
270
        push @array, {
271
            field => [
272
                {
273
                    tag => $fieldtag,
274
                    key => createKey(),
275
                    indicator1 => $field->indicator(1),
276
                    indicator2 => $field->indicator(2),
277
                    subfield   => [@subfield_array],
278
                }
279
            ]
280
            };
281
        }
282
283
    }
284
    }
285
    return [@array];
286
287
}
288
289
=head2 CreateKey
290
291
Create a random value to set it into the input name
292
293
=cut
294
295
sub createKey {
296
    return int(rand(1000000));
297
}
298
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/merge-record.inc (+219 lines)
Line 0 Link Here
1
[% BLOCK sourcetab %]
2
    <div id="tabrecord[% recordnumber %]">
3
    [% IF ( records ) %]
4
5
        <div class="record">
6
        <ul id="ulrecord[% recordnumber %]">
7
        [% FOREACH record IN records %]
8
            [% FOREACH fiel IN record.field %]
9
            <li id="k[% fiel.key %]">
10
                <input type="checkbox" [% IF (defaultrecord) %]checked="checked"[% END %] class="fieldpick" id="rec_[% recordnumber %]_[% fiel.key %]" />
11
                <span class="field">[% fiel.tag %]</span>
12
13
                <input type="hidden" name="tag_[% fiel.tag %]_indicator1_[% fiel.key %]" value="[% fiel.indicator1 %]" />
14
                <input type="hidden" name="tag_[% fiel.tag %]_indicator2_[% fiel.key %]" value="[% fiel.indicator2 %]" />
15
                [% IF ( fiel.value ) %] / [% fiel.value %]
16
                <input type="hidden" name="tag_[% fiel.tag %]_code_00_[% fiel.key %]" value="00" />
17
                <input type="hidden" name="tag_[% fiel.tag %]_subfield_00_[% fiel.key %]" value="[% fiel.value %]" />
18
                [% END %]
19
20
                [% IF ( fiel.subfield ) %]
21
                <ul>
22
                    [% FOREACH subfiel IN fiel.subfield %]
23
                    <li id="k[% subfiel.subkey %]">
24
                        <input type="checkbox" [% IF (defaultrecord) %]checked="checked"[% END %] class="subfieldpick" id="rec_[% recordnumber %]_[% subfiel.subkey %]" />
25
                        <span class="subfield">[% subfiel.subtag %]</span> / [% subfiel.value %]
26
                    <input type="hidden" name="tag_[% subfiel.tag %]_code_[% subfiel.subtag %]_[% subfiel.key %]_[% subfiel.subkey %]" value="[% subfiel.subtag %]" />
27
                    <input type="hidden" name="tag_[% subfiel.tag %]_subfield_[% subfiel.subtag %]_[% subfiel.key %]_[% subfiel.subkey %]" value="[% subfiel.value |html%]" />
28
                    </li>
29
                    [% END %]
30
                </ul>
31
                [% END %]
32
            [% END %]
33
            </li>
34
        [% END %]
35
        </ul>
36
        </div><!-- /div.record -->
37
    [% END %]
38
    </div><!-- /div#tabrecord[% recordnumber %] -->
39
[% END %]
40
[% BLOCK mergejs %]
41
    // Creating tabs
42
    $("#tabs").tabs();
43
44
    // Toggle a field / subfield
45
    function toggleField(pField) {
46
47
    // Getting the key of the clicked checkbox
48
    var ckid   = $(pField).attr("id");
49
    var tab    = ckid.split('_');
50
    var source = tab[1]; // From which record the click came from
51
    var key    = tab[2];
52
    var type   = $(pField).attr("class");
53
54
    // Getting field/subfield
55
    var field;
56
    var subfield;
57
    if (type == "subfieldpick") {
58
59
            field = $(pField).parent().parent().parent().find("span.field").text();
60
            subfield = $(pField).parent().find("span.subfield").text();
61
    } else {
62
63
            field = $(pField).parent().find("span.field").text();
64
    }
65
66
    // If the field has just been checked
67
    if (pField.checked) {
68
69
        // We check for repeatability
70
        var canbeadded = true;
71
        if (type == "subfieldpick") {
72
        var repeatable = 1;
73
        var alreadyexists = 0;
74
        if (tagslib[field] && tagslib[field][subfield]) {
75
            repeatable = tagslib[field][subfield].repeatable; // Note : we can't use the dot notation here (tagslib.021) because the key is a number
76
            // TODO : Checking for subfields
77
        }
78
        } else {
79
        if (tagslib[field]) {
80
            repeatable = tagslib[field].repeatable;
81
            alreadyexists = $("#resultul span.field:contains(" + field + ")");
82
            if (repeatable == 0 && alreadyexists.length != 0) {
83
            canbeadded = false;
84
            }
85
        }
86
        }
87
        // If the field is not repeatable, we check if it already exists in the result table
88
        if (canbeadded == false) {
89
        alert(_("The field is non-repeatable and already exists in the destination record. Therefore, you cannot add it."));
90
        pField.checked = 0;
91
        } else {
92
93
        // Cloning the field or subfield we picked
94
        var clone = $(pField).parent().clone();
95
96
        // Removing the checkboxes from it
97
        $(clone).find("input.subfieldpick, input.fieldpick").each(function() {
98
            $(this).remove();
99
        });
100
101
102
        // If we are a subfield
103
        if (type == "subfieldpick") {
104
            // then we need to find who is our parent field...
105
            fieldkey = $(pField).parent().parent().parent().attr("id");
106
107
            // Find where to add the subfield
108
109
            // First, check if the field is not already in the destination record
110
            if ($("#resultul li#" + fieldkey).length > 0) {
111
            // If so, we add our field to it
112
            $("#resultul li#" + fieldkey + " ul").append(clone);
113
            } else {
114
            // If not, we add the subfield to the first matching field
115
            var where = 0;
116
            $("#resultul li span.field").each(function() {
117
                if (where == 0 && $(this).text() == field) {
118
                where = this;
119
                }
120
            });
121
122
            // If there is no matching field in the destination record
123
            if (where == 0) {
124
125
                // TODO:
126
                // We select the whole field and removing non-selected subfields, instead of...
127
128
                // Alerting the user
129
                alert(_("This subfield cannot be added: there is no") + " " + field + " " + _("field in the destination record."));
130
                pField.checked = false;
131
132
            } else {
133
                $(where).nextAll("ul").append(clone);
134
            }
135
136
            }
137
138
139
140
        } else {
141
            // If we are a field
142
            var where = 0;
143
            // Find where to add the field
144
            $("#resultul li span.field").each(function() {
145
            if (where == 0 && $(this).text() > field) {
146
                where = this;
147
            }
148
            });
149
150
            $(where).parent().before(clone);
151
        }
152
        }
153
    } else {
154
155
        // Else, we remove it from the results tab
156
        $("ul#resultul li#k" + key).remove();
157
    }
158
}
159
160
161
    // When a field is checked / unchecked
162
    $('input.fieldpick').click(function() {
163
    toggleField(this);
164
    // (un)check all subfields
165
    var ischecked = this.checked;
166
    $(this).parent().find("input.subfieldpick").each(function() {
167
        this.checked = ischecked;
168
    });
169
    });
170
171
    // When a field or subfield is checked / unchecked
172
    $("input.subfieldpick").click(function() {
173
    toggleField(this);
174
    });
175
[% END %]
176
[% BLOCK mergesource %]
177
<div id="tabs" class="toptabs">
178
<h2>Source records</h2>
179
    <ul>
180
    <li><a href="#tabrecord1">[% recordid1 %]</a></li>
181
    <li><a href="#tabrecord2">[% recordid2 %]</a></li>
182
    </ul>
183
    [% PROCESS sourcetab records=record1 recordnumber=1 defaultrecord=1 %]
184
    [% PROCESS sourcetab records=record2 recordnumber=2 defaultrecord=0 %]
185
</div> <!-- // #tabs -->
186
[% END %]
187
[% BLOCK mergetarget %]
188
<div id="result">
189
    <h2>Destination record</h2>
190
    <div style="border:1px solid #E8E8E8;padding:1em;margin-top:2em;">
191
        <ul id="resultul">
192
        [% FOREACH record IN record1 %]
193
            [% FOREACH fiel IN record.field %]<li id="k[% fiel.key %]">
194
                <span class="field">[% fiel.tag %]</span>
195
                <input type="hidden" name="tag_[% fiel.tag %]_indicator1_[% fiel.key %]" value="[% fiel.indicator1 %]" />
196
                <input type="hidden" name="tag_[% fiel.tag %]_indicator2_[% fiel.key %]" value="[% fiel.indicator2 %]" />
197
                [% IF ( fiel.value ) %] /
198
                    [% fiel.value %]
199
                    <input type="hidden" name="tag_[% fiel.tag %]_code_00_[% fiel.key %]" value="00" />
200
                    <input type="hidden" name="tag_[% fiel.tag %]_subfield_00_[% fiel.key %]" value="[% fiel.value |html%]" />
201
                [% END %]
202
203
                [% IF ( fiel.subfield ) %]
204
                    <ul>
205
                        [% FOREACH subfiel IN fiel.subfield %]
206
                            <li id="k[% subfiel.subkey %]">
207
                                <span class="subfield">[% subfiel.subtag %]</span> / [% subfiel.value %]
208
                                <input type="hidden" name="tag_[% subfiel.tag %]_code_[% subfiel.subtag %]_[% subfiel.key %]_[% subfiel.subkey %]" value="[% subfiel.subtag %]" />
209
                                <input type="hidden" name="tag_[% subfiel.tag %]_subfield_[% subfiel.subtag %]_[% subfiel.key %]_[% subfiel.subkey %]" value="[% subfiel.value |html%]" />
210
                            </li>
211
                        [% END %]
212
                    </ul>
213
                [% END %]
214
            </li>[% END %]
215
        [% END %]
216
        </ul>
217
    </div>
218
</div> <!-- // #result -->
219
[% END %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/merge.tt (-258 / +6 lines)
Lines 1-3 Link Here
1
[% PROCESS 'merge-record.inc' %]
1
[% INCLUDE 'doc-head-open.inc' %]
2
[% INCLUDE 'doc-head-open.inc' %]
2
<title>Koha &rsaquo; Cataloging &rsaquo; Merging records</title>
3
<title>Koha &rsaquo; Cataloging &rsaquo; Merging records</title>
3
[% INCLUDE 'greybox.inc' %]
4
[% INCLUDE 'greybox.inc' %]
Lines 16-167 div#result { margin-top: 1em; } Link Here
16
	    $("ul#ulrecord2").remove();
17
	    $("ul#ulrecord2").remove();
17
}
18
}
18
19
19
20
$(document).ready(function(){
20
$(document).ready(function(){
21
    // Creating tabs
22
    $("#tabs").tabs();
23
24
    // Getting marc structure via ajax
21
    // Getting marc structure via ajax
25
    tagslib = [];
22
    tagslib = [];
26
    $.getJSON("/cgi-bin/koha/cataloguing/merge_ajax.pl", {frameworkcode : "[% framework %]" }, function(json) {
23
    $.getJSON("/cgi-bin/koha/cataloguing/merge_ajax.pl", {frameworkcode : "[% framework %]" }, function(json) {
27
	tagslib = json;
24
        tagslib = json;
28
    });
25
    });
29
26
    [% PROCESS mergejs %]
30
31
    // Toggle a field / subfield
32
    function toggleField(pField) {
33
34
	// Getting the key of the clicked checkbox
35
	var ckid   = $(pField).attr("id");
36
	var tab    = ckid.split('_');
37
	var source = tab[1]; // From which record the click came from
38
	var key    = tab[2];
39
	var type   = $(pField).attr("class");
40
41
	// Getting field/subfield
42
	var field;
43
	var subfield;
44
	if (type == "subfieldpick") {
45
46
		    field = $(pField).parent().parent().parent().find("span.field").text();
47
		    subfield = $(pField).parent().find("span.subfield").text();
48
	} else {
49
50
		    field = $(pField).parent().find("span.field").text();
51
	}
52
53
	// If the field has just been checked
54
	if (pField.checked) {
55
56
	    // We check for repeatability
57
	    var canbeadded = true;
58
	    if (type == "subfieldpick") {
59
		var repeatable = 1;
60
		var alreadyexists = 0;
61
		if (tagslib[field] && tagslib[field][subfield]) {
62
		    repeatable = tagslib[field][subfield].repeatable; // Note : we can't use the dot notation here (tagslib.021) because the key is a number 
63
		    // TODO : Checking for subfields
64
		}
65
	    } else {
66
		if (tagslib[field]) {
67
		    repeatable = tagslib[field].repeatable;
68
		    alreadyexists = $("#resultul span.field:contains(" + field + ")");
69
		    if (repeatable == 0 && alreadyexists.length != 0) {
70
			canbeadded = false;
71
		    }
72
		}
73
	    }
74
	    // If the field is not repeatable, we check if it already exists in the result table
75
	    if (canbeadded == false) {
76
		alert(_("The field is non-repeatable and already exists in the destination record. Therefore, you cannot add it."));
77
		pField.checked = 0;
78
	    } else {
79
80
		// Cloning the field or subfield we picked
81
		var clone = $(pField).parent().clone();
82
83
		// Removing the checkboxes from it
84
		$(clone).find("input.subfieldpick, input.fieldpick").each(function() {
85
		    $(this).remove();
86
		});
87
88
89
		// If we are a subfield
90
		if (type == "subfieldpick") {
91
		    // then we need to find who is our parent field...
92
		    fieldkey = $(pField).parent().parent().parent().attr("id");
93
94
		    // Find where to add the subfield
95
96
		    // First, check if the field is not already in the destination record
97
		    if ($("#resultul li#" + fieldkey).length > 0) { 
98
			// If so, we add our field to it
99
			$("#resultul li#" + fieldkey + " ul").append(clone);
100
		    } else {
101
			// If not, we add the subfield to the first matching field
102
			var where = 0;
103
			$("#resultul li span.field").each(function() {
104
			    if (where == 0 && $(this).text() == field) {
105
				where = this;
106
			    }
107
			});
108
109
			// If there is no matching field in the destination record
110
			if (where == 0) {
111
112
			    // TODO: 
113
			    // We select the whole field and removing non-selected subfields, instead of...
114
115
			    // Alerting the user 
116
			    alert(_("This subfield cannot be added: there is no") + " " + field + " " + _("field in the destination record."));
117
			    pField.checked = false;
118
119
			} else {
120
			    $(where).nextAll("ul").append(clone);
121
			}
122
123
		    }
124
125
		    
126
		    
127
		} else {
128
		    // If we are a field
129
		    var where = 0;
130
		    // Find where to add the field
131
		    $("#resultul li span.field").each(function() {
132
			if (where == 0 && $(this).text() > field) {
133
			    where = this;
134
			}
135
		    });
136
137
		    $(where).parent().before(clone);
138
		}
139
	    }
140
	} else {
141
142
	    // Else, we remove it from the results tab
143
	    $("ul#resultul li#k" + key).remove();
144
	}
145
}
146
147
148
    // When a field is checked / unchecked 
149
    $('input.fieldpick').click(function() {
150
	toggleField(this);
151
	// (un)check all subfields
152
	var ischecked = this.checked;
153
	$(this).parent().find("input.subfieldpick").each(function() {
154
	    this.checked = ischecked;
155
	});
156
    });
157
158
    // When a field or subfield is checked / unchecked
159
    $("input.subfieldpick").click(function() {
160
	toggleField(this);
161
    });
162
163
});
27
});
164
28
29
165
function changeFramework(fw) {
30
function changeFramework(fw) {
166
    $("#Frameworks").val(fw);
31
    $("#Frameworks").val(fw);
167
}
32
}
Lines 253-379 function changeFramework(fw) { Link Here
253
118
254
<div class="yui-g">
119
<div class="yui-g">
255
<div class="yui-u first">
120
<div class="yui-u first">
256
<div id="tabs" class="toptabs">
121
[% PROCESS mergesource recordid1=biblio1 recordid2=biblio2 %]
257
<h2>Source records</h2>
258
    <ul>
259
	<li><a href="#tabrecord1">[% biblio1 %]</a></li>
260
	<li><a href="#tabrecord2">[% biblio2 %]</a></li>
261
    </ul>
262
    <div id="tabrecord1">
263
	[% IF ( record1 ) %]
264
265
	    <div class="record">
266
		<ul id="ulrecord1">
267
		[% FOREACH record IN record1 %]
268
			[% FOREACH fiel IN record.field %]
269
			<li id="k[% fiel.key %]">
270
			    <input type="checkbox" checked="checked" class="fieldpick" id="rec_1_[% fiel.key %]" /> 
271
			    <span class="field">[% fiel.tag %]</span>
272
273
			    <input type="hidden" name="tag_[% fiel.tag %]_indicator1_[% fiel.key %]" value="[% fiel.indicator1 %]" />
274
			    <input type="hidden" name="tag_[% fiel.tag %]_indicator2_[% fiel.key %]" value="[% fiel.indicator2 %]" />
275
			    [% IF ( fiel.value ) %] / [% fiel.value %]
276
				<input type="hidden" name="tag_[% fiel.tag %]_code_00_[% fiel.key %]" value="00" />
277
				<input type="hidden" name="tag_[% fiel.tag %]_subfield_00_[% fiel.key %]" value="[% fiel.value %]" />
278
			    [% END %]
279
280
			    [% IF ( fiel.subfield ) %]
281
				<ul>
282
				    [% FOREACH subfiel IN fiel.subfield %]
283
					<li id="k[% subfiel.subkey %]">
284
					    <input type="checkbox" checked="checked" class="subfieldpick" id="rec_1_[% subfiel.subkey %]" /> 
285
					    <span class="subfield">[% subfiel.subtag %]</span> / [% subfiel.value %]
286
				    <input type="hidden" name="tag_[% subfiel.tag %]_code_[% subfiel.subtag %]_[% subfiel.key %]_[% subfiel.subkey %]" value="[% subfiel.subtag %]" />
287
				    <input type="hidden" name="tag_[% subfiel.tag %]_subfield_[% subfiel.subtag %]_[% subfiel.key %]_[% subfiel.subkey %]" value="[% subfiel.value |html%]" />
288
					</li>
289
				    [% END %]
290
				</ul>
291
			    [% END %]
292
		    [% END %]
293
		    </li>
294
		[% END %]
295
		</ul>
296
	    </div><!-- /div.record -->
297
[% END %]
298
    </div><!-- /div#tabrecord1 -->
299
    <div id="tabrecord2">
300
	[% IF ( record2 ) %]
301
302
	   <div class="record">
303
		<ul id="ulrecord2">
304
		[% FOREACH record IN record2 %]
305
		    [% FOREACH fiel IN record.field %]
306
		    <li id="k[% fiel.key %]">
307
			<input type="checkbox" class="fieldpick" id="rec_2_[% fiel.key %]" /> 
308
			<span class="field">[% fiel.tag %]</span>
309
310
			<input type="hidden" name="tag_[% fiel.tag %]_indicator1_[% fiel.key %]" value="[% fiel.indicator1 %]" />
311
			<input type="hidden" name="tag_[% fiel.tag %]_indicator2_[% fiel.key %]" value="[% fiel.indicator2 %]" />
312
			[% IF ( fiel.value ) %] / [% fiel.value %]
313
			<input type="hidden" name="tag_[% fiel.tag %]_code_00_[% fiel.key %]" value="00" />
314
			<input type="hidden" name="tag_[% fiel.tag %]_subfield_00_[% fiel.key %]" value="[% fiel.value |html%]" />
315
			[% END %]
316
317
			[% IF ( fiel.subfield ) %]
318
			    <ul>
319
				[% FOREACH subfiel IN fiel.subfield %]
320
				    <li id="k[% subfiel.subkey %]">
321
					<input type="checkbox" class="subfieldpick" id="rec_2_[% subfiel.subkey %]" />
322
					<span class="subfield">[% subfiel.subtag %]</span> / [% subfiel.value %]
323
				    <input type="hidden" name="tag_[% subfiel.tag %]_code_[% subfiel.subtag %]_[% subfiel.key %]_[% subfiel.subkey %]" value="[% subfiel.subtag %]" />
324
				    <input type="hidden" name="tag_[% subfiel.tag %]_subfield_[% subfiel.subtag %]_[% subfiel.key %]_[% subfiel.subkey %]" value="[% subfiel.value |html%]" />
325
				    </li>
326
				[% END %]
327
			    </ul>
328
			[% END %]
329
		    [% END %]
330
		    </li>
331
		[% END %]
332
		</ul>
333
	    </div>
334
	    <!-- /div.record -->
335
336
337
338
339
	[% END %]
340
    </div><!-- /div#tabrecord2 -->
341
</div> <!-- // #tabs -->
342
</div>
122
</div>
343
<div class="yui-u">
123
<div class="yui-u">
344
<div id="result">
124
[% PROCESS mergetarget %]
345
    <h2>Destination record</h2>
346
    <div style="border:1px solid #E8E8E8;padding:1em;margin-top:2em;">
347
	    <ul id="resultul">
348
	[% FOREACH record IN record1 %]
349
		    [% FOREACH fiel IN record.field %]<li id="k[% fiel.key %]"><span class="field">[% fiel.tag %]</span>  
350
			<input type="hidden" name="tag_[% fiel.tag %]_indicator1_[% fiel.key %]" value="[% fiel.indicator1 %]" />
351
			<input type="hidden" name="tag_[% fiel.tag %]_indicator2_[% fiel.key %]" value="[% fiel.indicator2 %]" />
352
		    [% IF ( fiel.value ) %] /
353
			[% fiel.value %]
354
			<input type="hidden" name="tag_[% fiel.tag %]_code_00_[% fiel.key %]" value="00" />
355
			<input type="hidden" name="tag_[% fiel.tag %]_subfield_00_[% fiel.key %]" value="[% fiel.value |html%]" />
356
		    [% END %]
357
			
358
		    [% IF ( fiel.subfield ) %]
359
			<ul>
360
			    [% FOREACH subfiel IN fiel.subfield %]
361
				<li id="k[% subfiel.subkey %]">
362
				    <span class="subfield">[% subfiel.subtag %]</span> / [% subfiel.value %]
363
				    <input type="hidden" name="tag_[% subfiel.tag %]_code_[% subfiel.subtag %]_[% subfiel.key %]_[% subfiel.subkey %]" value="[% subfiel.subtag %]" />
364
				    <input type="hidden" name="tag_[% subfiel.tag %]_subfield_[% subfiel.subtag %]_[% subfiel.key %]_[% subfiel.subkey %]" value="[% subfiel.value |html%]" />
365
				</li>
366
			    [% END %]
367
			</ul>
368
		    [% END %]
369
370
		    [% END %]
371
		    </li>
372
		[% END %]
373
374
	    </ul>
375
</div>
376
</div> <!-- // #result -->
377
</div> <!-- .yui-u -->
125
</div> <!-- .yui-u -->
378
126
379
<input type="hidden" name="biblio1" value="[% biblio1 %]" />
127
<input type="hidden" name="biblio1" value="[% biblio1 %]" />
(-)a/t/Koha_Record.t (-1 / +99 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
# Copyright 2013 C & P Bibliography Services
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 2 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 strict;
21
use warnings;
22
23
use Test::More tests => 4;
24
25
BEGIN {
26
        use_ok('Koha::Record');
27
}
28
29
my $marcrecord = MARC::Record->new;
30
31
$marcrecord->add_fields(
32
        [ '001', '1234' ],
33
        [ '150', ' ', ' ', a => 'Cooking' ],
34
        [ '450', ' ', ' ', a => 'Cookery', z => 'Instructional manuals' ],
35
        );
36
my $record = Koha::Record->new({ 'record' => $marcrecord });
37
38
is(ref($record), 'Koha::Record', 'Created valid Koha::Record object');
39
40
my $samplehash = [
41
    {
42
        'field' => [
43
            {
44
                'value' => '1234',
45
                'tag'   => '001',
46
            }
47
        ]
48
    },
49
    {
50
        'field' => [
51
            {
52
                'subfield' => [
53
                    {
54
                        'value'  => 'Cooking',
55
                        'subtag' => 'a'
56
                    }
57
                ],
58
                'indicator2' => ' ',
59
                'tag'        => 150,
60
                'indicator1' => ' ',
61
            }
62
        ]
63
    },
64
    {
65
        'field' => [
66
            {
67
                'subfield' => [
68
                    {
69
                        'value'  => 'Cookery',
70
                        'subtag' => 'a'
71
                    },
72
                    {
73
                        'value' => 'Instructional manuals',
74
                        'subtag' => 'z'
75
                    }
76
                ],
77
                'indicator2' => ' ',
78
                'tag'        => 450,
79
                'indicator1' => ' ',
80
            }
81
        ]
82
    }
83
];
84
85
my $hash = $record->createMarcHash();
86
my %fieldkeys;
87
require Data::Dumper;
88
foreach my $field (@$hash) {
89
    $fieldkeys{delete $field->{'field'}->[0]->{'key'}}++;
90
    if (defined $field->{'field'}->[0]->{'subfield'}) {
91
        foreach my $subfield (@{$field->{'field'}->[0]->{'subfield'}}) {
92
            $fieldkeys{delete $subfield->{'subkey'}}++;
93
        }
94
    }
95
}
96
97
is_deeply($hash, $samplehash, 'Generated hash correctly');
98
my $dupkeys = grep { $_ > 1 } values %fieldkeys;
99
is($dupkeys, 0, 'No duplicate keys');

Return to bug 9755