Bug 26180: Add descending option to rebuild_elasticsearch.pl
[koha.git] / admin / oai_set_mappings.pl
blobd322494f5ca61baea0f9b6f39bd473c10251088c
1 #!/usr/bin/perl
3 # Copyright 2011 BibLibre SARL
4 # This file is part of Koha.
6 # Koha is free software; you can redistribute it and/or modify it
7 # under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
11 # Koha is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with Koha; if not, see <http://www.gnu.org/licenses>.
19 =head1 NAME
21 oai_set_mappings.pl
23 =head1 DESCRIPTION
25 Define mappings for a given set.
26 Mappings are conditions that define which biblio is included in which set.
27 A condition is in the form 200$a = 'abc'.
28 Multiple conditions can be defined for a given set. In this case,
29 the OR operator will be applied.
31 =cut
33 use Modern::Perl;
35 use CGI qw ( -utf8 );
36 use C4::Auth;
37 use C4::Output;
38 use C4::OAI::Sets;
40 use Data::Dumper;
42 my $input = CGI->new;
43 my ($template, $loggedinuser, $cookie, $flags) = get_template_and_user( {
44 template_name => 'admin/oai_set_mappings.tt',
45 query => $input,
46 type => 'intranet',
47 flagsrequired => { 'parameters' => 'manage_oai_sets' },
48 debug => 1,
49 } );
51 my $id = $input->param('id');
52 my $op = $input->param('op');
54 if($op && $op eq "save") {
55 my @marcfields = $input->multi_param('marcfield');
56 my @marcsubfields = $input->multi_param('marcsubfield');
57 my @operators = $input->multi_param('operator');
58 my @marcvalues = $input->multi_param('marcvalue');
59 my @ruleoperators = $input->multi_param('rule_operator');
60 my @ruleorders = $input->multi_param('rule_order');
62 my @mappings;
63 my $i = 0;
64 while($i < @marcfields and $i < @marcsubfields and $i < @marcvalues) {
65 if($marcfields[$i] and $marcsubfields[$i]) {
66 push @mappings, {
67 marcfield => $marcfields[$i],
68 marcsubfield => $marcsubfields[$i],
69 operator => $operators[$i],
70 marcvalue => $marcvalues[$i],
71 rule_operator => $ruleoperators[$i],
72 rule_order => $i
75 $i++;
77 $mappings[0]{'rule_operator'} = undef if (@mappings);
78 ModOAISetMappings($id, \@mappings);
79 $template->param(mappings_saved => 1);
82 my $set = GetOAISet($id);
83 my $mappings = GetOAISetMappings($id);
85 $template->param(
86 id => $id,
87 setName => $set->{'name'},
88 setSpec => $set->{'spec'},
89 mappings => $mappings,
92 output_html_with_http_headers $input, $cookie, $template->output;