GetOAISetsMappings returns mappings for all OAI Sets.
Mappings define how biblios are categorized in sets.
-A mapping is defined by three properties:
+A mapping is defined by four properties:
{
marcfield => 'XXX', # the MARC field to check
marcsubfield => 'Y', # the MARC subfield to check
+ operator => 'A', # the operator 'equal' or 'notequal'; 'equal' if ''
marcvalue => 'zzzz', # the value to check
}
{
marcfield => 'XXX',
marcsubfield => 'Y',
+ operator => 'A',
marcvalue => 'zzzz'
},
{
push @{ $mappings->{$result->{'set_id'}} }, {
marcfield => $result->{'marcfield'},
marcsubfield => $result->{'marcsubfield'},
+ operator => $result->{'operator'},
marcvalue => $result->{'marcvalue'}
};
}
push @mappings, {
marcfield => $result->{'marcfield'},
marcsubfield => $result->{'marcsubfield'},
+ operator => $result->{'operator'},
marcvalue => $result->{'marcvalue'}
};
}
{
marcfield => 'XXX',
marcsubfield => 'Y',
+ operator => 'A',
marcvalue => 'zzzz'
},
...
if(scalar @$mappings > 0) {
$query = qq{
- INSERT INTO oai_sets_mappings (set_id, marcfield, marcsubfield, marcvalue)
- VALUES (?,?,?,?)
+ INSERT INTO oai_sets_mappings (set_id, marcfield, marcsubfield, operator, marcvalue)
+ VALUES (?,?,?,?,?)
};
$sth = $dbh->prepare($query);
foreach (@$mappings) {
- $sth->execute($set_id, $_->{'marcfield'}, $_->{'marcsubfield'}, $_->{'marcvalue'});
+ $sth->execute($set_id, $_->{'marcfield'}, $_->{'marcsubfield'}, $_->{'operator'}, $_->{'marcvalue'});
}
}
}
next if not $mapping;
my $field = $mapping->{'marcfield'};
my $subfield = $mapping->{'marcsubfield'};
+ my $operator = $mapping->{'operator'};
my $value = $mapping->{'marcvalue'};
-
my @subfield_values = $record->subfield($field, $subfield);
- if(0 < grep /^$value$/, @subfield_values) {
- push @biblio_sets, $set_id;
- last;
+ if ($operator eq 'notequal') {
+ if(0 == grep /^$value$/, @subfield_values) {
+ push @biblio_sets, $set_id;
+ last;
+ }
+ }
+ else {
+ if(0 < grep /^$value$/, @subfield_values) {
+ push @biblio_sets, $set_id;
+ last;
+ }
}
}
}
if($op && $op eq "save") {
my @marcfields = $input->param('marcfield');
my @marcsubfields = $input->param('marcsubfield');
+ my @operators = $input->param('operator');
my @marcvalues = $input->param('marcvalue');
my @mappings;
push @mappings, {
marcfield => $marcfields[$i],
marcsubfield => $marcsubfields[$i],
+ operator => $operators[$i],
marcvalue => $marcvalues[$i]
};
}
`set_id` int(11) NOT NULL,
`marcfield` char(3) NOT NULL,
`marcsubfield` char(1) NOT NULL,
+ `operator` varchar(8) NOT NULL default 'equal',
`marcvalue` varchar(80) NOT NULL,
CONSTRAINT `oai_sets_mappings_ibfk_1` FOREIGN KEY (`set_id`) REFERENCES `oai_sets` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
SetVersion ($DBversion);
}
+$DBversion = "3.13.00.XXX";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+ $dbh->do("ALTER TABLE oai_sets_mappings ADD COLUMN operator varchar(8) NOT NULL default 'equal' AFTER marcsubfield;");
+ print "Upgrade to $DBversion done (Bug 9295: OAI notequal: add operator column to OAI mappings table)\n";
+ SetVersion ($DBversion);
+}
+
=head1 FUNCTIONS
=head2 TableExists($table)
<tr>
<th>Field</th>
<th>Subfield</th>
- <th> </th>
+ <th>Operator</th>
<th>Value</th>
<th> </th>
<th> </th>
<tr>
<td><input type="text" name="marcfield" size="3" value="[% mapping.marcfield %]" /></td>
<td style="text-align:center"><input type="text" name="marcsubfield" size="1" value="[% mapping.marcsubfield %]" /></td>
- <td>is equal to</td>
+ <td><select name=operator>
+ [% IF mapping.operator == 'equal' %]
+ <option selected value="equal">is equal to</option>
+ <option value="notequal">not equal to</option>
+ [% ELSE %]
+ <option value="equal">is equal to</option>
+ <option selected value="notequal">not equal to</option>
+ [% END %]
+ </select></td>
<td><input type="text" name="marcvalue" value="[% mapping.marcvalue %]" /></td>
<td style="text-align:center">
[% IF ( loop.last ) %]
<tr>
<td><input type="text" name="marcfield" size="3" /></td>
<td style="text-align:center"><input type="text" name="marcsubfield" size="1" /></td>
- <td>is equal to</td>
+ <td><select name=operator>
+ <option value="equal">is equal to</option>
+ <option value="notequal">not equal to</option>
+ </select></td>
<td><input type="text" name="marcvalue" /></td>
<td><input type="button" id="ORbutton" value="OR" /></td>
<td><a class="clear-field" href="#">Delete</a></td>
<h2>Defining a mapping</h2>
<ol>
- <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>
+ <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>
<li>If you want to add another condition, click on 'OR' button and repeat step 1.</li>
<li>Click on 'Save'</li>
</ol>
-<p>To delete a condition, just leave at least one of 'Field', 'Subfield' or 'Value' empty and click on 'Save'.</p>
+<p>To delete a condition, just leave at least one of 'Field' or 'Subfield' empty and click on 'Save'.</p>
-<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>
+<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>
<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>