mirror of https://github.com/MISP/MISP
fix: [sightings/api] now support json output format
parent
99e5f560a8
commit
01cba114f2
|
@ -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)
|
||||||
|
|
|
@ -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) {
|
||||||
|
|
|
@ -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') {
|
||||||
|
|
|
@ -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.');
|
||||||
|
|
Loading…
Reference in New Issue