C4::OAI::Sets - OAI Sets management functions
C4::OAI::Sets contains functions for managing storage and editing of OAI Sets.
OAI Set description can be found here
$oai_sets = GetOAISets;
GetOAISets return a array reference of hash references describing the sets. The hash references looks like this:
    {
        'name'         => 'set name',
        'spec'         => 'set spec',
        'descriptions' => [
            'description 1',
            'description 2',
            ...
        ]
    }
$set = GetOAISet($set_id);
GetOAISet returns a hash reference describing the set with the given set_id.
See GetOAISets to see what the hash looks like.
my $set = GetOAISetBySpec($setSpec);
Returns a hash describing the set whose spec is $setSpec
    my $set = {
        'id' => $set_id,                 # mandatory
        'spec' => $spec,                 # mandatory
        'name' => $name,                 # mandatory
        'descriptions => \@descriptions, # optional, [] to remove descriptions
    };
    ModOAISet($set);
ModOAISet modify a set in the database.
DelOAISet($set_id);
DelOAISet remove the set with the given set_id
    my $set = {
        'id' => $set_id,                 # mandatory
        'spec' => $spec,                 # mandatory
        'name' => $name,                 # mandatory
        'descriptions => \@descriptions, # optional
    };
    my $set_id = AddOAISet($set);
AddOAISet adds a new set and returns its id, or undef if something went wrong.
my $mappings = GetOAISetsMappings;
GetOAISetsMappings returns mappings for all OAI Sets.
Mappings define how biblios are categorized in sets. 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
    }
If defined in a set mapping, a biblio which have at least one 'Y' subfield of one 'XXX' field equal to 'zzzz' will belong to this set. If multiple mappings are defined in a set, the biblio will belong to this set if at least one condition is matched.
GetOAISetsMappings returns a hashref of arrayrefs of hashrefs. The first hashref keys are the sets IDs, so it looks like this:
    $mappings = {
        '1' => [
            {
                marcfield => 'XXX',
                marcsubfield => 'Y',
                operator => 'A',
                marcvalue => 'zzzz'
            },
            {
                ...
            },
            ...
        ],
        '2' => [...],
        ...
    };
my $set_mappings = GetOAISetMappings($set_id);
Return mappings for the set with given set_id. It's an arrayref of hashrefs
    my $mappings = [
        {
            marcfield => 'XXX',
            marcsubfield => 'Y',
            operator => 'A',
            marcvalue => 'zzzz'
        },
        ...
    ];
    ModOAISetMappings($set_id, $mappings);
ModOAISetMappings modifies mappings of a given set.
$oai_sets = GetOAISetsBiblio($biblionumber);
Return the OAI sets where biblio appears.
Return value is an arrayref of hashref where each element of the array is a set. Keys of hash are id, spec and name
DelOAISetsBiblio($biblionumber);
Remove a biblio from all sets
my @sets = CalcOAISetsBiblio($record, $oai_sets_mappings);
Return a list of set ids the record belongs to. $record must be a MARC::Record and $oai_sets_mappings (optional) must be a hashref returned by GetOAISetsMappings
    my $oai_sets_biblios = {
        '1' => [1, 3, 4],   # key is the set_id, and value is an array ref of biblionumbers
        '2' => [],
        ...
    };
    ModOAISetsBiblios($oai_sets_biblios);
ModOAISetsBiblios truncate oai_sets_biblios table and call AddOAISetsBiblios. This table is then used in opac/oai.pl.
UpdateOAISetsBiblio($biblionumber, $record);
Update OAI sets for one biblio. The two parameters are mandatory. $record is a MARC::Record.
    my $oai_sets_biblios = {
        '1' => [1, 3, 4],   # key is the set_id, and value is an array ref of biblionumbers
        '2' => [],
        ...
    };
    ModOAISetsBiblios($oai_sets_biblios);
AddOAISetsBiblios insert given infos in oai_sets_biblios table. This table is then used in opac/oai.pl.