' . join('
', $e['aliases']) . '';
$target = array('name' => $e['name'], 'type' => $e['type'], 'parent' => $e['parent'], 'aliases' => $aliases);
array_push($targets, $target);
}
return $targets;
}
/* Return the list of available services by querying some usual registries. */
function getServices() {
$registriesURL = ["http://registry.euro-vo.org/regtap/tap", "http://dc.zah.uni-heidelberg.de/tap", "http://gavo.aip.de/tap", "http://reg.g-vo.org/tap"];
$columns = ['short_name', 'res_title', 'ivoid', 'access_url', 'table_name', 'content_type', 'creator_seq', 'content_level', 'reference_url', 'created', 'updated'];
$getServicesQuery = "SELECT DISTINCT " . implode(', ', $columns) . " FROM rr.resource
NATURAL JOIN rr.res_schema NATURAL JOIN rr.res_table NATURAL JOIN rr.interface NATURAL JOIN rr.res_detail NATURAL JOIN rr.capability
WHERE standard_id='ivo://ivoa.net/std/tap' AND intf_type='vs:paramhttp' AND detail_xpath='/capability/dataModel/@ivo-id'
AND 1=ivo_nocasematch(detail_value, 'ivo://vopdc.obspm/std/EpnCore%') AND table_name LIKE '%.epn_core' ORDER BY short_name, table_name";
for($i=0; $i 1) {
return 'Too many returned raws.';
} else if(is_null($result[0])) {
return 'The returned raw is null.';
} else if(!array_key_exists("nb_rows", $result[0])) {
return 'cant find nb_rows.';
} else if(!is_numeric($result[0]['nb_rows'])) {
return 'The returned value is not a number.';
} else {
return (int)($result[0]['nb_rows']);
}
}
function getGranules() {
$url = filter_var($_GET['url'], FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW);
$tableName = filter_var($_GET['tableName'], FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW);
$targetName = filter_var($_GET['targetName'], FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW);
$productTypes = filter_var($_GET['productTypes'], FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW);
$timeMin = filter_var($_GET['timeMin'], FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW);
$timeMax = filter_var($_GET['timeMax'], FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW);
// TODO: make this more beatiful
// TODO find a way to handle 'non existing key errors' (and then add access_format)
$query = "SELECT dataproduct_type, target_name, time_min, time_max, granule_uid, access_estsize, access_url, thumbnail_url FROM $tableName" . createFilter($targetName, $productTypes, $timeMin, $timeMax);
$result = request($url, $query);
return $result;
}
// ----- utils -----
function request($access_url, $query) {
$votMgr = new VOTableMgr;
$params = 'FORMAT=votable&LANG=ADQL&REQUEST=doQuery';
$url = $access_url . '/sync?' . $params . '&QUERY=' . urlencode(preg_replace('/\s+/', ' ', $query)); // remove also multiple whitespaces
$votMgr->load($url);
$result = $votMgr->parseStream();
return $votMgr->getVotableError() ? array('error' => $votMgr->getVotableError()) : $result;
}
function createFilter($targetName, $productTypes, $timeMin, $timeMax) {
$filter = array();
if($targetName) {
array_push($filter, "target_name = '$targetName'");
}
if($productTypes) {
array_push($filter, "dataproduct_type IN ('" . join("', '", explode(';', $productTypes)) . "')");
}
if($timeMin) {
array_push($filter, "time_min >= " . dateToJD($timeMin));
}
if($timeMax) {
array_push($filter, "time_max <= " . dateToJD($timeMax));
}
return (count($filter) > 0 ? ' WHERE ' . join(' AND ', $filter) : '');
}
/* Generate a unique service identifier from the service ivoid and the table name. */
function generateServiceId($service) {
return str_replace(['ivo://', '.epn_core'], '', $service['ivoid'] . '/' . $service['table_name']);
}
function dateToJD($gregorian_date) {
list($day, $month, $year, $hours, $minutes, $seconds) = preg_split('/[\s\/:]+/', $gregorian_date);
return GregorianToJD($month, $day, $year) + $hours/24 + $minutes/(24*60) + $seconds/(24*60*60);
}
?>