feat: add listsets callback method
feat: add set arg for listRecords method
This commit is contained in:
parent
230dd07376
commit
b07400bdb7
49
index.php
49
index.php
|
@ -31,6 +31,7 @@ require __DIR__.'/Configuration/Main.php';
|
|||
|
||||
// Get all available records and their respective status and timestamps
|
||||
$records = [];
|
||||
$setsrecords = [];
|
||||
$deleted = [];
|
||||
$timestamps = [];
|
||||
$earliest = time();
|
||||
|
@ -45,10 +46,36 @@ foreach ($config['metadataPrefix'] as $prefix => $uris) {
|
|||
$earliest = filemtime($file);
|
||||
}
|
||||
}
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue