@@ -, +, @@ --- C4/OAI/Sets.pm | 29 ++++++++++++++----- admin/oai_set_mappings.pl | 4 ++- installer/data/mysql/kohastructure.sql | 1 + installer/data/mysql/updatedatabase.pl | 7 +++++ .../prog/en/modules/admin/oai_set_mappings.tt | 17 +++++++++-- .../prog/en/modules/help/admin/oai_set_mappings.tt | 6 ++-- 6 files changed, 49 insertions(+), 15 deletions(-) --- a/C4/OAI/Sets.pm +++ a/C4/OAI/Sets.pm @@ -290,11 +290,12 @@ sub AddOAISet { 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 } @@ -311,6 +312,7 @@ The first hashref keys are the sets IDs, so it looks like this: { marcfield => 'XXX', marcsubfield => 'Y', + operator => 'A', marcvalue => 'zzzz' }, { @@ -337,6 +339,7 @@ sub GetOAISetsMappings { push @{ $mappings->{$result->{'set_id'}} }, { marcfield => $result->{'marcfield'}, marcsubfield => $result->{'marcsubfield'}, + operator => $result->{'operator'}, marcvalue => $result->{'marcvalue'} }; } @@ -371,6 +374,7 @@ sub GetOAISetMappings { push @mappings, { marcfield => $result->{'marcfield'}, marcsubfield => $result->{'marcsubfield'}, + operator => $result->{'operator'}, marcvalue => $result->{'marcvalue'} }; } @@ -384,6 +388,7 @@ sub GetOAISetMappings { { marcfield => 'XXX', marcsubfield => 'Y', + operator => 'A', marcvalue => 'zzzz' }, ... @@ -409,12 +414,12 @@ sub ModOAISetMappings { 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'}); } } } @@ -491,12 +496,20 @@ sub CalcOAISetsBiblio { 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; + } } } } --- a/admin/oai_set_mappings.pl +++ a/admin/oai_set_mappings.pl @@ -55,15 +55,17 @@ my $op = $input->param('op'); 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; my $i = 0; while($i < @marcfields and $i < @marcsubfields and $i < @marcvalues) { - if($marcfields[$i] and $marcsubfields[$i] and $marcvalues[$i]) { + if($marcfields[$i] and $marcsubfields[$i]) { push @mappings, { marcfield => $marcfields[$i], marcsubfield => $marcsubfields[$i], + operator => $operators[$i], marcvalue => $marcvalues[$i] }; } --- a/installer/data/mysql/kohastructure.sql +++ a/installer/data/mysql/kohastructure.sql @@ -1422,6 +1422,7 @@ CREATE TABLE `oai_sets_mappings` ( `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; --- a/installer/data/mysql/updatedatabase.pl +++ a/installer/data/mysql/updatedatabase.pl @@ -6181,6 +6181,13 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) { SetVersion ($DBversion); } +$DBversion = "3.11.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 OAI notequal: add operator column to OAI mappings table)\n"; + SetVersion ($DBversion); +} + =head1 FUNCTIONS =head2 TableExists($table) --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/oai_set_mappings.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/oai_set_mappings.tt @@ -52,7 +52,7 @@ function returnToSetsPage() {
To delete a condition, just leave at least one of 'Field', 'Subfield' or 'Value' empty and click on 'Save'.
+To delete a condition, just leave at least one of 'Field' or 'Subfield' empty and click on 'Save'.
-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'.
+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'.
And it is case sensitive : a record having 999$9 = 'xxx' will not belong to a set where condition is 999$9 = 'XXX'.
--