feat: add listsets callback method

feat: add set arg for listRecords method
This commit is contained in:
Matija Kancijan 2022-07-14 11:01:13 +02:00
parent 230dd07376
commit b07400bdb7
1 changed files with 56 additions and 9 deletions

View File

@ -30,10 +30,11 @@ require __DIR__.'/vendor/autoload.php';
require __DIR__.'/Configuration/Main.php';
// Get all available records and their respective status and timestamps
$records = [];
$deleted = [];
$timestamps = [];
$earliest = time();
$records = [];
$setsrecords = [];
$deleted = [];
$timestamps = [];
$earliest = time();
foreach ($config['metadataPrefix'] as $prefix => $uris) {
$files = glob(rtrim($config['dataDirectory'], '/').'/'.$prefix.'/*.xml');
@ -45,10 +46,36 @@ foreach ($config['metadataPrefix'] as $prefix => $uris) {
$earliest = filemtime($file);
}
}
ksort($records[$prefix]);
reset($records[$prefix]);
ksort($timestamps[$prefix]);
reset($timestamps[$prefix]);
if (isset($records[$prefix])) {
ksort($records[$prefix]);
reset($records[$prefix]);
ksort($timestamps[$prefix]);
reset($timestamps[$prefix]);
}
}
// get all set records.
foreach ($config['ListSets'] as $set => $setd) {
foreach ($config['metadataPrefix'] as $prefix => $uris) {
$path = rtrim($config['dataDirectory'], '/').'/sets/'.$set.'/'.$prefix.'/*.xml';
$files = glob(rtrim($config['dataDirectory'], '/').'/sets/'.$set.'/'.$prefix.'/*.xml');
foreach ($files as $file) {
$setsrecords[$set]['records'][$prefix][pathinfo($file, PATHINFO_FILENAME)] = $file;
$setsrecords[$set]['deleted'][$prefix][pathinfo($file, PATHINFO_FILENAME)] = !filesize($file);
$setsrecords[$set]['timestamps'][$prefix][filemtime($file)][] = pathinfo($file, PATHINFO_FILENAME);
if (filemtime($file) < $earliest) {
$earliest = filemtime($file);
}
}
if (isset($setsrecords[$set]['records'][$prefix])) {
ksort($setsrecords[$set]['records'][$prefix]);
reset($setsrecords[$set]['records'][$prefix]);
ksort($setsrecords[$set]['timestamps'][$prefix]);
reset($setsrecords[$set]['timestamps'][$prefix]);
}
}
}
// Get current base URL
@ -88,7 +115,7 @@ $oai2 = new Server(
];
}
},
'ListRecords' => function ($metadataPrefix, $from = null, $until = null, $count = false, $deliveredRecords = 0, $maxItems = 100) {
'ListRecords' => function ($metadataPrefix, $from = null, $until = null, $count = false, $deliveredRecords = 0, $maxItems = 100, $set = null) {
global $records, $deleted, $timestamps;
$resultSet = [];
foreach ($timestamps[$metadataPrefix] as $timestamp => $identifiers) {
@ -126,6 +153,26 @@ $oai2 = new Server(
} else {
return $config['metadataPrefix'];
}
},
'ListSets' => function ($identifier = '') {
global $config, $records, $setsrecords;
if (!empty($identifier)) {
$listsets = [];
foreach ($setsrecords as $set => $records) {
foreach ($records as $format => $record) {
if (!empty($record[$identifier])) {
$listsets[$set] = $config['ListSets'][$set];
}
}
}
if (!empty($listsets)) {
return $listsets;
} else {
throw new Exception('idDoesNotExist');
}
} else {
return $config['ListSets'];
}
}
],
$config