new: [API] added count returnformat for the REST api, fixes #6233

- simply counts the number of attributes/events found (on each respective scope)
pull/6258/head
iglocska 2020-08-31 12:32:28 +02:00
parent 8f806c4f1b
commit f82e10d1fb
No known key found for this signature in database
GPG Key ID: BEA224F1FEF113AC
3 changed files with 38 additions and 0 deletions

View File

@ -0,0 +1,36 @@
<?php
// You can count on me. Raiders roll.
class CountExport
{
public $additional_params = array(
'flatten' => 1
);
private $__count = 0;
public $non_restrictive_export = true;
public function handler($data, $options = array())
{
if ($options['scope'] === 'Attribute') {
$this->__count++;
}
if ($options['scope'] === 'Event') {
$this->__count++;
}
return '';
}
public function header($options = array())
{
return '';
}
public function footer()
{
return $this->__count;
}
public function separator()
{
return "";
}
}

View File

@ -420,6 +420,7 @@ class Attribute extends AppModel
public $validFormats = array(
'attack-sightings' => array('json', 'AttackSightingsExport', 'json'),
'cache' => array('txt', 'CacheExport', 'cache'),
'count' => array('txt', 'CountExport', 'txt'),
'csv' => array('csv', 'CsvExport', 'csv'),
'hashes' => array('txt', 'HashesExport', 'txt'),
'json' => array('json', 'JsonExport', 'json'),

View File

@ -176,6 +176,7 @@ class Event extends AppModel
'attack' => array('html', 'AttackExport', 'html'),
'attack-sightings' => array('json', 'AttackSightingsExport', 'json'),
'cache' => array('txt', 'CacheExport', 'cache'),
'count' => array('txt', 'CountExport', 'txt'),
'csv' => array('csv', 'CsvExport', 'csv'),
'hashes' => array('txt', 'HashesExport', 'txt'),
'json' => array('json', 'JsonExport', 'json'),