logEpnTap = fopen(USERDATADIR."logEpnTap", "a"); $this->addLog("\n---\n"); } function addLog($msg) { fwrite($this->logEpnTap, date("h:i:s A") . $msg . "\n"); } 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'); } 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) { // $this->addLog("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.epn_core" . (count($filter) > 0 ? ' WHERE '.join(' AND ', $filter) : ''); $this->addLog("query: " . $query); $votMgr = new VOTableMgr; $params = 'FORMAT=votable&LANG=ADQL&REQUEST=doQuery'; $url = $access_url . '/sync?' . $params . '&QUERY=' . urlencode($query); $this->addLog("URL: " . $url); $votMgr->load($url); $res = $votMgr->isValidSchema() ? $votMgr->getStream() : "-"; return $res["nb_results"]; } private function getGranules($table_name, $access_url, $target_name, $dataproduct_type, $time_min, $time_max) { $this->addLog("getGranules(" . $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 dataproduct_type, target_name, time_min, time_max FROM $table_name.epn_core" . ($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); $res = $votMgr->isValidSchema() ? $votMgr->getStream() : "-"; return $res; } } ?>