Browse Source

fix wfd data fetching

master
o.moresis 2 years ago
parent
commit
0c39b98ce9
  1. 1
      src/Controllers/InterfaceController.php
  2. 1
      src/Services/API.php
  3. 19
      src/Services/WfdAPI.php

1
src/Controllers/InterfaceController.php

@ -60,7 +60,6 @@ class InterfaceController { @@ -60,7 +60,6 @@ class InterfaceController {
$readJSONFile = file_get_contents($url);
echo $readJSONFile;
/* header($_SERVER['SERVER_PROTOCOL'].'404 Not Found'); */
break;
}
}

1
src/Services/API.php

@ -35,6 +35,7 @@ class API @@ -35,6 +35,7 @@ class API
curl_setopt($this->curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($this->curl, CURLOPT_MAXREDIRS, 10);
curl_setopt($this->curl, CURLOPT_TIMEOUT, 30);
curl_setopt($this->curl, CURLOPT_VERBOSE, true);
if (!empty($this->headers["Authorization"])) {
curl_setopt($this->curl, CURLOPT_HTTPHEADER, $this::convert_headers($this->headers));
}

19
src/Services/WfdAPI.php

@ -55,7 +55,10 @@ class WfdAPI extends API { @@ -55,7 +55,10 @@ class WfdAPI extends API {
public function getStationSamples($station_id) {
$endpoint = "/coastal-trans-samples";
$endpoint = "coastal-trans-samples";
$this->headers["Authorization"] = "Bearer {$this->accessToken}";
$this->headers["Accept"] = "application/json";
$data = array(
"coastalTransStationId.equals" => $station_id
);
@ -68,13 +71,21 @@ class WfdAPI extends API { @@ -68,13 +71,21 @@ class WfdAPI extends API {
* Fetches data for a specific station according to the sample sampleIds
*
*/
public function getData($parameter_ids) {
public function getData($parameter_ids, $data_category='all') {
$this->headers["Authorization"] = "Bearer {$this->accessToken}";
$this->headers["Accept"] = "application/json";
$res = [];
$data = array(
"coastalTransSampleId.in" => implode(",", $parameter_ids)
);
$endpoint = "coastal-trans-abiotics";
$res = json_decode($this->get($endpoint, $data));
if ($data_category === 'all')
$endpoints = array("coastal-trans-abiotics","coastal-trans-macrofaunas", "coastal-trans-phytoplanktons", "coastal-trans-angiosperms");
foreach ($endpoints as $endpoint) {
array_push($res, json_decode($this->get($endpoint, $data)));
}
return $res;
}

Loading…
Cancel
Save