feat: add listsets callback method
feat: add set arg for listRecords method
This commit is contained in:
parent
230dd07376
commit
b07400bdb7
65
index.php
65
index.php
|
@ -30,10 +30,11 @@ require __DIR__.'/vendor/autoload.php';
|
||||||
require __DIR__.'/Configuration/Main.php';
|
require __DIR__.'/Configuration/Main.php';
|
||||||
|
|
||||||
// Get all available records and their respective status and timestamps
|
// Get all available records and their respective status and timestamps
|
||||||
$records = [];
|
$records = [];
|
||||||
$deleted = [];
|
$setsrecords = [];
|
||||||
$timestamps = [];
|
$deleted = [];
|
||||||
$earliest = time();
|
$timestamps = [];
|
||||||
|
$earliest = time();
|
||||||
|
|
||||||
foreach ($config['metadataPrefix'] as $prefix => $uris) {
|
foreach ($config['metadataPrefix'] as $prefix => $uris) {
|
||||||
$files = glob(rtrim($config['dataDirectory'], '/').'/'.$prefix.'/*.xml');
|
$files = glob(rtrim($config['dataDirectory'], '/').'/'.$prefix.'/*.xml');
|
||||||
|
@ -45,10 +46,36 @@ foreach ($config['metadataPrefix'] as $prefix => $uris) {
|
||||||
$earliest = filemtime($file);
|
$earliest = filemtime($file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ksort($records[$prefix]);
|
if (isset($records[$prefix])) {
|
||||||
reset($records[$prefix]);
|
ksort($records[$prefix]);
|
||||||
ksort($timestamps[$prefix]);
|
reset($records[$prefix]);
|
||||||
reset($timestamps[$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
|
// 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;
|
global $records, $deleted, $timestamps;
|
||||||
$resultSet = [];
|
$resultSet = [];
|
||||||
foreach ($timestamps[$metadataPrefix] as $timestamp => $identifiers) {
|
foreach ($timestamps[$metadataPrefix] as $timestamp => $identifiers) {
|
||||||
|
@ -126,6 +153,26 @@ $oai2 = new Server(
|
||||||
} else {
|
} else {
|
||||||
return $config['metadataPrefix'];
|
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
|
$config
|
||||||
|
|
Loading…
Reference in New Issue