Commit 67a4e0daba0fa0a4c0eceeef98b97385dee1028b
1 parent
e7234e88
Exists in
master
and in
112 other branches
Add a function to count rows of a query result and improve date conversions.
Showing
3 changed files
with
25 additions
and
12 deletions
Show diff stats
php/classes/AmdaAction.php
... | ... | @@ -1355,8 +1355,12 @@ class AmdaAction { |
1355 | 1355 | return array('success' => true, 'alreadyUsed' => $alreadyUsed); |
1356 | 1356 | } |
1357 | 1357 | |
1358 | - public function epnTapGetGranules($table_name, $access_url, $filter, $select) { | |
1359 | - return (new EpnTapMgr)->getGranules($table_name, $access_url, $filter, $select); | |
1358 | + public function epnTapGetGranules($table_name, $access_url, $filter, $select, $limit, $offset) { | |
1359 | + return (new EpnTapMgr)->getGranules($table_name, $access_url, $filter, $select, $limit, $offset); | |
1360 | + } | |
1361 | + | |
1362 | + public function epnTapGetNbRows($table_name, $access_url, $filter) { | |
1363 | + return (new EpnTapMgr)->getNbRows($table_name, $access_url, $filter); | |
1360 | 1364 | } |
1361 | 1365 | } |
1362 | 1366 | ?> |
... | ... |
php/classes/EpnTapMgr.php
... | ... | @@ -18,13 +18,14 @@ class EpnTapMgr { |
18 | 18 | } |
19 | 19 | |
20 | 20 | private function dateToJD($gregorian_date) { |
21 | - list($month, $day, $year) = split('[/.-]', $gregorian_date); | |
22 | - return GregorianToJD($month, $day, $year); | |
21 | + list($day, $month, $year, $hours, $minutes, $seconds) = split('[/ :]', $gregorian_date); | |
22 | + return GregorianToJD($month, $day, $year) + $hours/24 + $minutes/(24*60) + $seconds/(24*60*60); | |
23 | 23 | } |
24 | 24 | |
25 | 25 | public function JDTodate($jd) { |
26 | 26 | list($month, $day, $year) = split('/', JDToGregorian($jd)); |
27 | - return "$day/$month/$year"; | |
27 | + $date = sprintf('%02d', $day) . '/' . sprintf('%02d', $month) . '/' . sprintf('%04d', $year); | |
28 | + return ($date == '00/00/0000') ? '' : $date; | |
28 | 29 | } |
29 | 30 | |
30 | 31 | public function createFilter($target_name, $dataproduct_type, $time_min, $time_max) { |
... | ... | @@ -37,7 +38,6 @@ class EpnTapMgr { |
37 | 38 | array_push($filter, "time_min <= " . $this->dateToJD($time_min)); |
38 | 39 | if($time_max) |
39 | 40 | array_push($filter, "time_max >= " . $this->dateToJD($time_max)); |
40 | - | |
41 | 41 | return (count($filter) > 0 ? ' WHERE ' . join(' AND ', $filter) : ''); |
42 | 42 | } |
43 | 43 | |
... | ... | @@ -49,18 +49,26 @@ class EpnTapMgr { |
49 | 49 | $this->addLog("Query URL: " . $url); |
50 | 50 | $votMgr->load($url); |
51 | 51 | $result = $votMgr->isValidSchema() ? $votMgr->parseStream() : NULL; |
52 | + return $result; | |
53 | + } | |
54 | + | |
55 | + /* filter order: $target_name, $time_min, $time_max, $table_name, $access_url */ | |
56 | + public function getGranules($table_name, $access_url, $filter, $select, $limit, $offset) { | |
57 | + $query = "SELECT TOP $limit " . join(', ', $select) . " FROM $table_name.epn_core " . $this->createFilter($filter[0], $filter[1], $filter[2], $filter[3]) . " OFFSET $offset"; | |
58 | + // return $query; | |
59 | + $result = $this->request($access_url, $query); | |
52 | 60 | for ($i = 0 ; $i < sizeof($result) ; $i++) { |
53 | - $result[$i]['time_min'] = JDToGregorian($result[$i]['time_min']);//$this->JDTodate($result[$i]['time_min']); | |
61 | + $result[$i]['time_min'] = $this->JDTodate($result[$i]['time_min']); | |
54 | 62 | $result[$i]['time_max'] = $this->JDTodate($result[$i]['time_max']); |
55 | 63 | } |
56 | 64 | return $result; |
57 | 65 | } |
58 | 66 | |
59 | - /* filtre order: $target_name, $time_min, $time_max, $table_name, $access_url */ | |
60 | - public function getGranules($table_name, $access_url, $filter, $select) { | |
61 | - $query = "SELECT " . join(', ', $select) . " FROM $table_name.epn_core" . $this->createFilter($filter[0], $filter[1], $filter[2], $filter[3]); | |
67 | + public function getNbRows($table_name, $access_url, $filter) { | |
68 | + $query = "SELECT COUNT(*) AS nb_rows FROM $table_name.epn_core " . $this->createFilter($filter[0], $filter[1], $filter[2], $filter[3]); | |
62 | 69 | // return $query; |
63 | - return $this->request($access_url, $query); | |
70 | + return $this->request($access_url, $query)[0]['nb_rows']; | |
64 | 71 | } |
72 | + | |
65 | 73 | } |
66 | 74 | ?> |
... | ... |
php/config.php