Lines 290-308
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 four properties: |
293 |
A mapping is defined by six 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 |
operator => 'A', # the operator 'equal' or 'notequal'; 'equal' if '' |
299 |
marcvalue => 'zzzz', # the value to check |
299 |
marcvalue => 'zzzz', # the value to check |
|
|
300 |
rule_operator => 'and|or|undef', # the operator between the rules |
301 |
rule_order => 'n' # the order of the rule for the mapping |
300 |
} |
302 |
} |
301 |
|
303 |
|
302 |
If defined in a set mapping, a biblio which have at least one 'Y' subfield of |
304 |
If defined in a set mapping, a biblio which have at least one 'Y' subfield of |
303 |
one 'XXX' field equal to 'zzzz' will belong to this set. |
305 |
one 'XXX' field equal to 'zzzz' will belong to this set. |
304 |
If multiple mappings are defined in a set, the biblio will belong to this set |
|
|
305 |
if at least one condition is matched. |
306 |
|
306 |
|
307 |
GetOAISetsMappings returns a hashref of arrayrefs of hashrefs. |
307 |
GetOAISetsMappings returns a hashref of arrayrefs of hashrefs. |
308 |
The first hashref keys are the sets IDs, so it looks like this: |
308 |
The first hashref keys are the sets IDs, so it looks like this: |
Lines 313-319
The first hashref keys are the sets IDs, so it looks like this:
Link Here
|
313 |
marcfield => 'XXX', |
313 |
marcfield => 'XXX', |
314 |
marcsubfield => 'Y', |
314 |
marcsubfield => 'Y', |
315 |
operator => 'A', |
315 |
operator => 'A', |
316 |
marcvalue => 'zzzz' |
316 |
marcvalue => 'zzzz', |
|
|
317 |
rule_operator => 'and|or|undef', |
318 |
rule_order => 'n' |
317 |
}, |
319 |
}, |
318 |
{ |
320 |
{ |
319 |
... |
321 |
... |
Lines 329-335
The first hashref keys are the sets IDs, so it looks like this:
Link Here
|
329 |
sub GetOAISetsMappings { |
331 |
sub GetOAISetsMappings { |
330 |
my $dbh = C4::Context->dbh; |
332 |
my $dbh = C4::Context->dbh; |
331 |
my $query = qq{ |
333 |
my $query = qq{ |
332 |
SELECT * FROM oai_sets_mappings |
334 |
SELECT * FROM oai_sets_mappings ORDER BY set_id, rule_order |
333 |
}; |
335 |
}; |
334 |
my $sth = $dbh->prepare($query); |
336 |
my $sth = $dbh->prepare($query); |
335 |
$sth->execute; |
337 |
$sth->execute; |
Lines 340-346
sub GetOAISetsMappings {
Link Here
|
340 |
marcfield => $result->{'marcfield'}, |
342 |
marcfield => $result->{'marcfield'}, |
341 |
marcsubfield => $result->{'marcsubfield'}, |
343 |
marcsubfield => $result->{'marcsubfield'}, |
342 |
operator => $result->{'operator'}, |
344 |
operator => $result->{'operator'}, |
343 |
marcvalue => $result->{'marcvalue'} |
345 |
marcvalue => $result->{'marcvalue'}, |
|
|
346 |
rule_operator => $result->{'rule_operator'}, |
347 |
rule_order => $result->{'rule_order'} |
344 |
}; |
348 |
}; |
345 |
} |
349 |
} |
346 |
|
350 |
|
Lines 365-370
sub GetOAISetMappings {
Link Here
|
365 |
SELECT * |
369 |
SELECT * |
366 |
FROM oai_sets_mappings |
370 |
FROM oai_sets_mappings |
367 |
WHERE set_id = ? |
371 |
WHERE set_id = ? |
|
|
372 |
ORDER BY rule_order |
368 |
}; |
373 |
}; |
369 |
my $sth = $dbh->prepare($query); |
374 |
my $sth = $dbh->prepare($query); |
370 |
$sth->execute($set_id); |
375 |
$sth->execute($set_id); |
Lines 375-381
sub GetOAISetMappings {
Link Here
|
375 |
marcfield => $result->{'marcfield'}, |
380 |
marcfield => $result->{'marcfield'}, |
376 |
marcsubfield => $result->{'marcsubfield'}, |
381 |
marcsubfield => $result->{'marcsubfield'}, |
377 |
operator => $result->{'operator'}, |
382 |
operator => $result->{'operator'}, |
378 |
marcvalue => $result->{'marcvalue'} |
383 |
marcvalue => $result->{'marcvalue'}, |
|
|
384 |
rule_operator => $result->{'rule_operator'}, |
385 |
rule_order => $result->{'rule_order'} |
379 |
}; |
386 |
}; |
380 |
} |
387 |
} |
381 |
|
388 |
|
Lines 411-425
sub ModOAISetMappings {
Link Here
|
411 |
}; |
418 |
}; |
412 |
my $sth = $dbh->prepare($query); |
419 |
my $sth = $dbh->prepare($query); |
413 |
$sth->execute($set_id); |
420 |
$sth->execute($set_id); |
414 |
|
|
|
415 |
if(scalar @$mappings > 0) { |
421 |
if(scalar @$mappings > 0) { |
416 |
$query = qq{ |
422 |
$query = qq{ |
417 |
INSERT INTO oai_sets_mappings (set_id, marcfield, marcsubfield, operator, marcvalue) |
423 |
INSERT INTO oai_sets_mappings (set_id, marcfield, marcsubfield, operator, marcvalue, rule_operator, rule_order) |
418 |
VALUES (?,?,?,?,?) |
424 |
VALUES (?,?,?,?,?,?,?) |
419 |
}; |
425 |
}; |
420 |
$sth = $dbh->prepare($query); |
426 |
$sth = $dbh->prepare($query); |
421 |
foreach (@$mappings) { |
427 |
foreach (@$mappings) { |
422 |
$sth->execute($set_id, $_->{'marcfield'}, $_->{'marcsubfield'}, $_->{'operator'}, $_->{'marcvalue'}); |
428 |
$sth->execute($set_id, $_->{'marcfield'}, $_->{'marcsubfield'}, $_->{'operator'}, $_->{'marcvalue'}, $_->{'rule_operator'}, $_->{'rule_order'}); |
423 |
} |
429 |
} |
424 |
} |
430 |
} |
425 |
} |
431 |
} |
Lines 492-521
sub CalcOAISetsBiblio {
Link Here
|
492 |
|
498 |
|
493 |
my @biblio_sets; |
499 |
my @biblio_sets; |
494 |
foreach my $set_id (keys %$oai_sets_mappings) { |
500 |
foreach my $set_id (keys %$oai_sets_mappings) { |
|
|
501 |
|
502 |
my $rules = []; |
495 |
foreach my $mapping (@{ $oai_sets_mappings->{$set_id} }) { |
503 |
foreach my $mapping (@{ $oai_sets_mappings->{$set_id} }) { |
496 |
next if not $mapping; |
504 |
next if not $mapping; |
497 |
my $field = $mapping->{'marcfield'}; |
505 |
my $rule_operator = $mapping->{'rule_operator'}; |
498 |
my $subfield = $mapping->{'marcsubfield'}; |
506 |
my $result = _evalRule($record, $mapping); |
499 |
my $operator = $mapping->{'operator'}; |
507 |
|
500 |
my $value = $mapping->{'marcvalue'}; |
508 |
# First rule or 'or' rule is always pushed |
501 |
my @subfield_values = $record->subfield($field, $subfield); |
509 |
if (!@$rules || $rule_operator eq 'or') { |
502 |
if ($operator eq 'notequal') { |
510 |
push @$rules, [$result]; |
503 |
if(0 == grep /^$value$/, @subfield_values) { |
511 |
next; |
504 |
push @biblio_sets, $set_id; |
|
|
505 |
last; |
506 |
} |
507 |
} |
512 |
} |
508 |
else { |
513 |
|
509 |
if(0 < grep /^$value$/, @subfield_values) { |
514 |
# 'and' rule is pushed in the last 'or' rule |
510 |
push @biblio_sets, $set_id; |
515 |
push @{$rules->[-1]}, $result; |
511 |
last; |
516 |
} |
512 |
} |
517 |
|
|
|
518 |
my @evaluated_and; |
519 |
foreach my $ruleset (@$rules) { |
520 |
if (0 < grep /0/, @{$ruleset}) { |
521 |
push @evaluated_and, 0; |
522 |
} else { |
523 |
push @evaluated_and, 1; |
513 |
} |
524 |
} |
514 |
} |
525 |
} |
|
|
526 |
|
527 |
if (grep /1/, @evaluated_and) { |
528 |
push @biblio_sets, $set_id; |
529 |
} |
530 |
|
515 |
} |
531 |
} |
516 |
return @biblio_sets; |
532 |
return @biblio_sets; |
517 |
} |
533 |
} |
518 |
|
534 |
|
|
|
535 |
# Does the record match a given mapping rule? |
536 |
sub _evalRule { |
537 |
my $record = shift; |
538 |
my $mapping = shift; |
539 |
|
540 |
my $field = $mapping->{'marcfield'}; |
541 |
my $subfield = $mapping->{'marcsubfield'}; |
542 |
my $operator = $mapping->{'operator'}; |
543 |
my $value = $mapping->{'marcvalue'}; |
544 |
my @subfield_values = $record->subfield($field, $subfield); |
545 |
if ($operator eq 'notequal') { |
546 |
if(0 == grep /^$value$/, @subfield_values) { |
547 |
return 1; |
548 |
} |
549 |
} |
550 |
else { |
551 |
if(0 < grep /^$value$/, @subfield_values) { |
552 |
return 1; |
553 |
} |
554 |
} |
555 |
return 0; |
556 |
} |
557 |
|
558 |
|
519 |
=head2 ModOAISetsBiblios |
559 |
=head2 ModOAISetsBiblios |
520 |
|
560 |
|
521 |
my $oai_sets_biblios = { |
561 |
my $oai_sets_biblios = { |