simple-oai-pmh/listmetadataformats.php

69 lines
2.0 KiB
PHP
Raw Normal View History

<?php
/**
* \file
* \brief Response to Verb ListMetadataFormats
*
* The information of supported metadata formats :
* try database table $SQL['table']
* else try $METADATAFORMATS array from config-metadataformats.php
*/
/**
* Add a metadata format node to an ANDS_Response_XML
* \param &$outputObj
* type: ANDS_Response_XML. The ANDS_Response_XML object for output.
* \param $key
* type string. The name of new node.
* \param $val
* type: array. Values accessable through keywords 'schema' and 'metadataNamespace'.
*
*/
function addMetedataFormat(&$outputObj,$key,$val) {
2013-05-07 22:01:22 +02:00
$cmf = $outputObj->add2_verbNode("metadataFormat");
$outputObj->addChild($cmf,'metadataPrefix',$key);
$outputObj->addChild($cmf,'schema',$val['schema']);
$outputObj->addChild($cmf,'metadataNamespace',$val['metadataNamespace']);
}
if (isset($args['identifier'])) {
2013-05-07 22:01:22 +02:00
$identifier = $args['identifier'];
$query = 'select '.$SQL['metadataPrefix'].' FROM '.$SQL['table']. " WHERE ".$SQL['identifier']." = '".$id."'";
2013-05-07 22:01:22 +02:00
$res = $db->query($query);
if ($res==false) {
if (SHOW_QUERY_ERROR) {
echo __FILE__.','.__LINE__."<br />";
echo "Query: $query<br />\n";
die($db->errorInfo());
} else {
$errors[] = oai_error('idDoesNotExist','', $identifier);
}
} else {
$record = $res->fetch();
if($record===false) {
$errors[] = oai_error('idDoesNotExist', '', $identifier);
} else {
$mf = explode(",",$record[$SQL['metadataPrefix']]);
}
}
}
//break and clean up on error
if (!empty($errors)) {
oai_exit();
}
$outputObj = new ANDS_Response_XML($args);
if (isset($mf)) {
2013-05-07 22:01:22 +02:00
foreach($mf as $key) {
$val = $METADATAFORMATS[$key];
addMetedataFormat($outputObj,$key, $val);
}
} elseif (is_array($METADATAFORMATS)) {
2013-05-07 22:01:22 +02:00
foreach($METADATAFORMATS as $key=>$val) {
addMetedataFormat($outputObj,$key, $val);
}
} else { // a very unlikely event
$errors[] = oai_error('noMetadataFormats');
oai_exit();
}