fix: [sightings/api] now support json output format

pull/3789/head
Sami Mokaddem 2018-10-23 12:17:54 +02:00
parent 99e5f560a8
commit 01cba114f2
4 changed files with 12 additions and 6 deletions

View File

@ -244,12 +244,11 @@ class SightingsController extends AppController
throw new MethodNotAllowedException(_('An id must be provided if the context is set.')); throw new MethodNotAllowedException(_('An id must be provided if the context is set.'));
} }
$sightings = $this->Sighting->getSightingsForTime($this->Auth->user(), $returnFormat, $filters); $sightings = $this->Sighting->restSearch($this->Auth->user(), $returnFormat, $filters);
$validFormats = $this->Sighting->validFormats; $validFormats = $this->Sighting->validFormats;
$responseType = $validFormats[$returnFormat][0]; $responseType = $validFormats[$returnFormat][0];
return $this->RestResponse->viewData($sightings, $responseType, false, true); return $this->RestResponse->viewData($sightings, $responseType, false, true);
//return $this->RestResponse->viewData($sightings);
} }
public function listSightings($id, $context = 'attribute', $org_id = false) public function listSightings($id, $context = 'attribute', $org_id = false)

View File

@ -48,8 +48,8 @@ class CsvExport
return $this->__addLine($attribute, $options); return $this->__addLine($attribute, $options);
} }
private function __sightingsHandler($sighting, $options) private function __sightingsHandler($sighting, $options)
{ {
$lines = ''; $lines = '';
if (isset($sighting['Sighting']['Event'])) { if (isset($sighting['Sighting']['Event'])) {
foreach($sighting['Sighting']['Event'] as $k => $event_val) { foreach($sighting['Sighting']['Event'] as $k => $event_val) {

View File

@ -9,8 +9,10 @@ class JsonExport
{ {
if ($options['scope'] === 'Attribute') { if ($options['scope'] === 'Attribute') {
return $this->__attributeHandler($data, $options); return $this->__attributeHandler($data, $options);
} else { } else if($options['scope'] === 'Event') {
return $this->__eventHandler($data, $options); return $this->__eventHandler($data, $options);
} else if($options['scope'] === 'Sighting') {
return $this->__sightingsHandler($data, $options);
} }
} }
@ -47,6 +49,11 @@ class JsonExport
return json_encode($attribute); return json_encode($attribute);
} }
private function __sightingsHandler($sighting, $options = array())
{
return json_encode($sighting);
}
public function header($options = array()) public function header($options = array())
{ {
if ($options['scope'] === 'Attribute') { if ($options['scope'] === 'Attribute') {

View File

@ -463,7 +463,7 @@ class Sighting extends AppModel
return $sightingsRearranged; return $sightingsRearranged;
} }
public function getSightingsForTime($user, $returnFormat, $filters) public function restSearch($user, $returnFormat, $filters)
{ {
if (!isset($this->validFormats[$returnFormat][1])) { if (!isset($this->validFormats[$returnFormat][1])) {
throw new NotFoundException('Invalid output format.'); throw new NotFoundException('Invalid output format.');