EpnTapMgr.php
3.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
/** @class EpnTapMgr
* @brief Manager to communicates with EPN-TAP services.
*/
class EpnTapMgr {
public function call($function_name, $args) {
switch($function_name) {
case 'getServiceNbResults':
if(count($args) == 6)
return $this->getServiceNbResults($args[0], $args[1], $args[2], $args[3], $args[4], $args[5]);
break;
case 'getGranules':
if(count($args) == 6)
return $this->getGranules($args[0], $args[1], $args[2], $args[3], $args[4], $args[5]);
break;
default:
return array('success' => false, 'message' => $function_name.' is an unknown function.');
break;
}
return array('success' => false, 'message' => 'The function do not have the required number of arguments');
}
// dc.zah.uni-heidelberg.de/tap/sync?FORMAT=votable&LANG=ADQL&QUERY=SELECT DISTINCT table_name WHERE standard_id='ivo://ivoa.net/std/tap' AND intf_type='vs:paramhttp' AND detail_xpath='/capability/dataModel/@ivo-id' FROM&REQUEST=doQuery
// select distinct target_name from xxx.epn_core
private function date2JD($date) {
list($month, $day, $year) = split('[/.-]', $date);
if($month == 1 || $month == 2) {
$yearp = $year - 1;
$monthp = $month + 12;
} else {
$yearp = $year;
$monthp = $month;
}
# this checks where we are in relation to October 15, 1582, the beginning
# of the Gregorian calendar.
if (($year < 1582) ||
($year == 1582 && $month < 10) ||
($year == 1582 && $month == 10 && $day < 15))
$j_day = 0;
else
$j_day = 2 - (int)($yearp / 100.0) + (int)((int)($yearp / 100.0) / 4.0);
$j_day += $yearp < 0 ? (int)((365.25 * $yearp) - 0.75) : (int)(365.25 * $yearp);
$j_day += (int)(30.6001 * ($monthp + 1)) + $day + 1720994.5;
return $j_day;
}
private function getServiceNbResults($table_name, $access_url, $target_name, $dataproduct_type, $time_min, $time_max) {
$filter = array();
if($target_name)
array_push($filter, "target_name = '$target_name'");
if($dataproduct_type)
array_push($filter, "dataproduct_type = '$dataproduct_type'");
if($time_min)
array_push($filter, "time_min >= " . $this->date2JD($time_min));
if($time_max)
array_push($filter, "time_max >= " . $this->date2JD($time_max));
$query = "SELECT COUNT(granule_uid) AS nb_results FROM $table_name"
. ($filter.length > 0 ? ' WHERE ' . join(' AND ', $filter) : '');
$votMgr = new VOTableMgr;
$params = 'FORMAT=votable&LANG=ADQL&REQUEST=doQuery';
$url = $access_url . '/sync?' . $params . '&QUERY=' . urlencode($query);
$votMgr->load($url);
return $votMgr->isValidSchema() ? $votMgr->getSimpleInteger() : 0;
}
static function getGranules($table_name, $access_url) {
$filter = array();
if($target_name)
array_push($filter, "target_name = '$target_name'");
if($dataproduct_type)
array_push($filter, "dataproduct_type = '$dataproduct_type'");
if($time_min)
array_push($filter, "time_min >= " . $this->date2JD($time_min));
if($time_max)
array_push($filter, "time_max >= " . $this->date2JD($time_max));
$query = "SELECT dataproduct_type, target_name, time_min, time_max FROM $table_name"
. ($filter.length > 0 ? ' WHERE ' . join(' AND ', $filter) : '');
$votMgr = new VOTableMgr;
$params = 'FORMAT=votable&LANG=ADQL&REQUEST=doQuery';
$url = $access_url . '/sync?' . $params . '&QUERY=' . urlencode($query);
$votMgr->load($url);
if($votMgr->isValidSchema()) {
return false;
} else {
return true;
}
}
}
?>