From 6df8a37c9a52ebe446af276cc83fae7956995d02 Mon Sep 17 00:00:00 2001
From: Nathanael Jourdane <nathanael.jourdane@irap.omp.eu>
Date: Mon, 12 Jun 2017 12:33:57 +0200
Subject: [PATCH] getGranules only returns non-null columns.

---
 php/classes/EpnTapMgr.php | 35 ++++++++++++++++++++++++++++++-----
 1 file changed, 30 insertions(+), 5 deletions(-)

diff --git a/php/classes/EpnTapMgr.php b/php/classes/EpnTapMgr.php
index 7d4e8ae..3f95fd9 100644
--- a/php/classes/EpnTapMgr.php
+++ b/php/classes/EpnTapMgr.php
@@ -49,12 +49,37 @@ class EpnTapMgr {
 
 		$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);
-		if(! array_key_exists("error", $result)) {
 
-			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']);
+		$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]);
+				}
 			}
 		}
 
--
libgit2 0.21.2