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

(-)a/C4/OAI/Sets.pm (-8 / +21 lines)
Lines 290-300 sub AddOAISet { Link Here
290
GetOAISetsMappings returns mappings for all OAI Sets.
290
GetOAISetsMappings returns mappings for all OAI Sets.
291
291
292
Mappings define how biblios are categorized in sets.
292
Mappings define how biblios are categorized in sets.
293
A mapping is defined by three properties:
293
A mapping is defined by four properties:
294
294
295
    {
295
    {
296
        marcfield => 'XXX',     # the MARC field to check
296
        marcfield => 'XXX',     # the MARC field to check
297
        marcsubfield => 'Y',    # the MARC subfield to check
297
        marcsubfield => 'Y',    # the MARC subfield to check
298
        operator => 'A',        # the operator 'equal' or 'notequal'; 'equal' if ''
298
        marcvalue => 'zzzz',    # the value to check
299
        marcvalue => 'zzzz',    # the value to check
299
    }
300
    }
300
301
Lines 311-316 The first hashref keys are the sets IDs, so it looks like this: Link Here
311
            {
312
            {
312
                marcfield => 'XXX',
313
                marcfield => 'XXX',
313
                marcsubfield => 'Y',
314
                marcsubfield => 'Y',
315
                operator => 'A',
314
                marcvalue => 'zzzz'
316
                marcvalue => 'zzzz'
315
            },
317
            },
316
            {
318
            {
Lines 337-342 sub GetOAISetsMappings { Link Here
337
        push @{ $mappings->{$result->{'set_id'}} }, {
339
        push @{ $mappings->{$result->{'set_id'}} }, {
338
            marcfield => $result->{'marcfield'},
340
            marcfield => $result->{'marcfield'},
339
            marcsubfield => $result->{'marcsubfield'},
341
            marcsubfield => $result->{'marcsubfield'},
342
            operator => $result->{'operator'},
340
            marcvalue => $result->{'marcvalue'}
343
            marcvalue => $result->{'marcvalue'}
341
        };
344
        };
342
    }
345
    }
Lines 371-376 sub GetOAISetMappings { Link Here
371
        push @mappings, {
374
        push @mappings, {
372
            marcfield => $result->{'marcfield'},
375
            marcfield => $result->{'marcfield'},
373
            marcsubfield => $result->{'marcsubfield'},
376
            marcsubfield => $result->{'marcsubfield'},
377
            operator => $result->{'operator'},
374
            marcvalue => $result->{'marcvalue'}
378
            marcvalue => $result->{'marcvalue'}
375
        };
379
        };
376
    }
380
    }
Lines 384-389 sub GetOAISetMappings { Link Here
384
        {
388
        {
385
            marcfield => 'XXX',
389
            marcfield => 'XXX',
386
            marcsubfield => 'Y',
390
            marcsubfield => 'Y',
391
            operator => 'A',
387
            marcvalue => 'zzzz'
392
            marcvalue => 'zzzz'
388
        },
393
        },
389
        ...
394
        ...
Lines 409-420 sub ModOAISetMappings { Link Here
409
414
410
    if(scalar @$mappings > 0) {
415
    if(scalar @$mappings > 0) {
411
        $query = qq{
416
        $query = qq{
412
            INSERT INTO oai_sets_mappings (set_id, marcfield, marcsubfield, marcvalue)
417
            INSERT INTO oai_sets_mappings (set_id, marcfield, marcsubfield, operator, marcvalue)
413
            VALUES (?,?,?,?)
418
            VALUES (?,?,?,?,?)
414
        };
419
        };
415
        $sth = $dbh->prepare($query);
420
        $sth = $dbh->prepare($query);
416
        foreach (@$mappings) {
421
        foreach (@$mappings) {
417
            $sth->execute($set_id, $_->{'marcfield'}, $_->{'marcsubfield'}, $_->{'marcvalue'});
422
            $sth->execute($set_id, $_->{'marcfield'}, $_->{'marcsubfield'}, $_->{'operator'}, $_->{'marcvalue'});
418
        }
423
        }
419
    }
424
    }
420
}
425
}
Lines 491-502 sub CalcOAISetsBiblio { Link Here
491
            next if not $mapping;
496
            next if not $mapping;
492
            my $field = $mapping->{'marcfield'};
497
            my $field = $mapping->{'marcfield'};
493
            my $subfield = $mapping->{'marcsubfield'};
498
            my $subfield = $mapping->{'marcsubfield'};
499
            my $operator = $mapping->{'operator'};
494
            my $value = $mapping->{'marcvalue'};
500
            my $value = $mapping->{'marcvalue'};
495
496
            my @subfield_values = $record->subfield($field, $subfield);
501
            my @subfield_values = $record->subfield($field, $subfield);
497
            if(0 < grep /^$value$/, @subfield_values) {
502
            if ($operator eq 'notequal') {
498
                push @biblio_sets, $set_id;
503
                if(0 == grep /^$value$/, @subfield_values) {
499
                last;
504
                    push @biblio_sets, $set_id;
505
                    last;
506
                }
507
            }
508
            else {
509
                if(0 < grep /^$value$/, @subfield_values) {
510
                    push @biblio_sets, $set_id;
511
                    last;
512
                }
500
            }
513
            }
501
        }
514
        }
502
    }
515
    }
(-)a/admin/oai_set_mappings.pl (-1 / +3 lines)
Lines 55-69 my $op = $input->param('op'); Link Here
55
if($op && $op eq "save") {
55
if($op && $op eq "save") {
56
    my @marcfields = $input->param('marcfield');
56
    my @marcfields = $input->param('marcfield');
57
    my @marcsubfields = $input->param('marcsubfield');
57
    my @marcsubfields = $input->param('marcsubfield');
58
    my @operators = $input->param('operator');
58
    my @marcvalues = $input->param('marcvalue');
59
    my @marcvalues = $input->param('marcvalue');
59
60
60
    my @mappings;
61
    my @mappings;
61
    my $i = 0;
62
    my $i = 0;
62
    while($i < @marcfields and $i < @marcsubfields and $i < @marcvalues) {
63
    while($i < @marcfields and $i < @marcsubfields and $i < @marcvalues) {
63
        if($marcfields[$i] and $marcsubfields[$i] and $marcvalues[$i]) {
64
        if($marcfields[$i] and $marcsubfields[$i]) {
64
            push @mappings, {
65
            push @mappings, {
65
                marcfield    => $marcfields[$i],
66
                marcfield    => $marcfields[$i],
66
                marcsubfield => $marcsubfields[$i],
67
                marcsubfield => $marcsubfields[$i],
68
                operator     => $operators[$i],
67
                marcvalue    => $marcvalues[$i]
69
                marcvalue    => $marcvalues[$i]
68
            };
70
            };
69
        }
71
        }
(-)a/installer/data/mysql/kohastructure.sql (+1 lines)
Lines 1422-1427 CREATE TABLE `oai_sets_mappings` ( Link Here
1422
  `set_id` int(11) NOT NULL,
1422
  `set_id` int(11) NOT NULL,
1423
  `marcfield` char(3) NOT NULL,
1423
  `marcfield` char(3) NOT NULL,
1424
  `marcsubfield` char(1) NOT NULL,
1424
  `marcsubfield` char(1) NOT NULL,
1425
  `operator` varchar(8) NOT NULL default 'equal',
1425
  `marcvalue` varchar(80) NOT NULL,
1426
  `marcvalue` varchar(80) NOT NULL,
1426
  CONSTRAINT `oai_sets_mappings_ibfk_1` FOREIGN KEY (`set_id`) REFERENCES `oai_sets` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
1427
  CONSTRAINT `oai_sets_mappings_ibfk_1` FOREIGN KEY (`set_id`) REFERENCES `oai_sets` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
1427
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1428
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
(-)a/installer/data/mysql/updatedatabase.pl (+7 lines)
Lines 6181-6186 if (C4::Context->preference("Version") < TransformToNum($DBversion)) { Link Here
6181
    SetVersion ($DBversion);
6181
    SetVersion ($DBversion);
6182
}
6182
}
6183
6183
6184
$DBversion = "3.11.00.xxx";
6185
if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
6186
   $dbh->do("ALTER TABLE oai_sets_mappings ADD COLUMN operator varchar(8) NOT NULL default 'equal' AFTER marcsubfield;");
6187
   print "Upgrade to $DBversion done (Bug OAI notequal: add operator column to OAI mappings table)\n";
6188
   SetVersion ($DBversion);
6189
}
6190
6184
=head1 FUNCTIONS
6191
=head1 FUNCTIONS
6185
6192
6186
=head2 TableExists($table)
6193
=head2 TableExists($table)
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/oai_set_mappings.tt (-3 / +14 lines)
Lines 52-58 function returnToSetsPage() { Link Here
52
            <tr>
52
            <tr>
53
              <th>Field</th>
53
              <th>Field</th>
54
              <th>Subfield</th>
54
              <th>Subfield</th>
55
              <th>&nbsp;</th>
55
              <th>Operator</th>
56
              <th>Value</th>
56
              <th>Value</th>
57
              <th>&nbsp;</th>
57
              <th>&nbsp;</th>
58
            </tr>
58
            </tr>
Lines 63-69 function returnToSetsPage() { Link Here
63
                <tr>
63
                <tr>
64
                  <td><input type="text" name="marcfield" size="3" value="[% mapping.marcfield %]" /></td>
64
                  <td><input type="text" name="marcfield" size="3" value="[% mapping.marcfield %]" /></td>
65
                  <td style="text-align:center"><input type="text" name="marcsubfield" size="1" value="[% mapping.marcsubfield %]" /></td>
65
                  <td style="text-align:center"><input type="text" name="marcsubfield" size="1" value="[% mapping.marcsubfield %]" /></td>
66
                  <td>is equal to</td>
66
                  <td><select name=operator>
67
                      [% IF mapping.operator == 'equal' %]
68
                        <option selected value="equal">is equal to</option>
69
                        <option value="notequal">not equal to</option>
70
                      [% ELSE %]
71
                        <option value="equal">is equal to</option>
72
                        <option selected value="notequal">not equal to</option>
73
                      [% END %]
74
                      </select></td>
67
                  <td><input type="text" name="marcvalue" value="[% mapping.marcvalue %]" /></td>
75
                  <td><input type="text" name="marcvalue" value="[% mapping.marcvalue %]" /></td>
68
                  <td style="text-align:center">
76
                  <td style="text-align:center">
69
                    [% IF ( loop.last ) %]
77
                    [% IF ( loop.last ) %]
Lines 78-84 function returnToSetsPage() { Link Here
78
              <tr>
86
              <tr>
79
                <td><input type="text" name="marcfield" size="3" /></td>
87
                <td><input type="text" name="marcfield" size="3" /></td>
80
                <td style="text-align:center"><input type="text" name="marcsubfield" size="1" /></td>
88
                <td style="text-align:center"><input type="text" name="marcsubfield" size="1" /></td>
81
                <td>is equal to</td>
89
                <td><select name=operator>
90
                    <option value="equal">is equal to</option>
91
                    <option value="notequal">not equal to</option>
92
                    </select></td> 
82
                <td><input type="text" name="marcvalue" /></td>
93
                <td><input type="text" name="marcvalue" /></td>
83
                <td><input type="button" id="ORbutton" value="OR" onclick="newCondition()"/></td>
94
                <td><input type="button" id="ORbutton" value="OR" onclick="newCondition()"/></td>
84
              </tr>
95
              </tr>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/help/admin/oai_set_mappings.tt (-4 / +3 lines)
Lines 7-20 Link Here
7
<h2>Defining a mapping</h2>
7
<h2>Defining a mapping</h2>
8
8
9
<ol>
9
<ol>
10
    <li>Fill the fields 'Field', 'Subfield' and 'Value'. For example if you want to include in this set all records that have a 999$9 equal to 'XXX'. Fill 'Field' with 999, 'Subfield' with 9 and 'Value' with XXX.</li>
10
    <li>Fill the fields 'Field', 'Subfield', 'Operator' and 'Value'. For example if you want to include in this set all records that have a 999$9 equal to 'XXX'. Fill 'Field' with 999, 'Subfield' with 9, 'Operator' with is equal to and 'Value' with XXX.</li>
11
    <li>If you want to add another condition, click on 'OR' button and repeat step 1.</li>
11
    <li>If you want to add another condition, click on 'OR' button and repeat step 1.</li>
12
    <li>Click on 'Save'</li>
12
    <li>Click on 'Save'</li>
13
</ol>
13
</ol>
14
14
15
<p>To delete a condition, just leave at least one of 'Field', 'Subfield' or 'Value' empty and click on 'Save'.</p>
15
<p>To delete a condition, just leave at least one of 'Field' or 'Subfield' empty and click on 'Save'.</p>
16
16
17
<p>Note: Actually, a condition is true if value in the corresponding subfield is strictly equal to what is defined if 'Value'. A record having 999$9 = 'XXX YYY' will not belong to a set where condition is 999$9 = 'XXX'.</p>
17
<p>Note: Actually, a condition is true if value in the corresponding subfield is strictly 'equal' or 'not equal' to what is defined if 'Value'. A record having 999$9 = 'XXX YYY' will not belong to a set where condition is 999$9 = 'XXX'.</p>
18
18
19
<p>And it is case sensitive : a record having 999$9 = 'xxx' will not belong to a set where condition is 999$9 = 'XXX'.</p>
19
<p>And it is case sensitive : a record having 999$9 = 'xxx' will not belong to a set where condition is 999$9 = 'XXX'.</p>
20
20
21
- 

Return to bug 9295