= " . $this->dateToJD($time_min)); if($time_max) array_push($filter, "time_max <= " . $this->dateToJD($time_max)); return (count($filter) > 0 ? ' WHERE ' . join(' AND ', $filter) : ''); } public 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; } /* filter order: product type, target name, time min, time max */ public function getGranules($table_name, $access_url, $filter, $limit, $offset) { $query = "SELECT TOP {$limit} * FROM {$table_name} " . $this->createFilter($filter[0], $filter[1], $filter[2], $filter[3]) . " OFFSET {$offset}"; $result = $this->request($access_url, $query); $result_path = EpnTapDataPath . "test_result.json"; $servicesJsonFile = fopen($result_path, "w"); if(array_key_exists("error", $result)) { return $result; } $columns_with_empty_results = Array(); for ($i = 0 ; $i < count($result) ; $i++) { $result[$i]['num'] = $i + $offset + 1; $result[$i]['time_min'] = $this->JDTodate($result[$i]['time_min']); $result[$i]['time_max'] = $this->JDTodate($result[$i]['time_max']); foreach($result[$i] as $key => $value) { if($value === '' || $value === 'NAN') { if(!array_key_exists($key, $columns_with_empty_results)) { array_push($columns_with_empty_results, $key); } } elseif(array_key_exists($key, $columns_with_empty_results)) { unset($columns_with_empty_results[$key]); } } } // TODO: maybe is it better to have a array of booleans, like {"target_name": true, "c1min", false}, to apply an array_map() ? for($i = 0 ; $i < count($result) ; $i++) { foreach($result[$i] as $key => $value) { if(in_array($key, $columns_with_empty_results)) { unset($result[$i][$key]); } } } return $result; } /* Return the list of available services by querying some usual registries. */ public 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; $irequest($registriesURL[$i], $getServicesQuery); if(! array_key_exists("error", $services)) { for($j=0; $jgenerateServiceId($services[$j]); } return $services; } else if($i === count($registriesURL)-1) { error_log("Can not access any of these services : " . implode(', ', $registriesURL) . "."); return; } } } /* Generate a unique service identifier from the service ivoid and the table name. */ public function generateServiceId($service) { return str_replace(['ivo://', '.epn_core'], '', $service['ivoid'] . '/' . $service['table_name']); } /* filter order: product type, target name, time min, time max */ public function getNbRows($table_name, $access_url, $filter) { $query = "SELECT COUNT(*) AS nb_rows FROM {$table_name} " . $this->createFilter($filter[0], $filter[1], $filter[2], $filter[3]); $result = $this->request($access_url, $query)[0]['nb_rows']; return $result; } } ?>