mirror of https://github.com/MISP/MISP
new: [API] Add pagination related parameters to event index, fixes #4270
parent
aa2218846c
commit
f145f40057
|
@ -296,6 +296,7 @@ class EventsController extends AppController
|
|||
$passedArgsArray = array();
|
||||
$urlparams = "";
|
||||
$overrideAbleParams = array('all', 'attribute', 'published', 'eventid', 'datefrom', 'dateuntil', 'org', 'eventinfo', 'tag', 'tags', 'distribution', 'sharinggroup', 'analysis', 'threatlevel', 'email', 'hasproposal', 'timestamp', 'publishtimestamp', 'publish_timestamp', 'minimal');
|
||||
$paginationParams = array('limit', 'page', 'sort', 'direction', 'order');
|
||||
$passedArgs = $this->passedArgs;
|
||||
if (isset($this->request->data)) {
|
||||
if (isset($this->request->data['request'])) {
|
||||
|
@ -315,6 +316,11 @@ class EventsController extends AppController
|
|||
$passedArgs['search' . $oap] = $this->request->data[$oap];
|
||||
}
|
||||
}
|
||||
foreach ($paginationParams as $paginationParam) {
|
||||
if (isset($this->request->data[$paginationParam])) {
|
||||
$passedArgs[$paginationParam] = $this->request->data[$paginationParam];
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->set('passedArgs', json_encode($passedArgs));
|
||||
// check each of the passed arguments whether they're a filter (could also be a sort for example) and if yes, add it to the pagination conditions
|
||||
|
@ -705,12 +711,6 @@ class EventsController extends AppController
|
|||
} else {
|
||||
$rules['order'] = array('Event.id' => 'DESC');
|
||||
}
|
||||
if (isset($passedArgs['limit'])) {
|
||||
$rules['limit'] = intval($passedArgs['limit']);
|
||||
}
|
||||
if (isset($passedArgs['page'])) {
|
||||
$rules['page'] = intval($passedArgs['page']);
|
||||
}
|
||||
$rules['contain'] = $this->paginate['contain'];
|
||||
if (isset($this->paginate['conditions'])) {
|
||||
$rules['conditions'] = $this->paginate['conditions'];
|
||||
|
@ -720,6 +720,12 @@ class EventsController extends AppController
|
|||
$rules['recursive'] = -1;
|
||||
$rules['fields'] = array('id', 'timestamp', 'published', 'uuid');
|
||||
}
|
||||
$paginationRules = array('page', 'limit', 'sort', 'direction', 'order');
|
||||
foreach ($paginationRules as $paginationRule) {
|
||||
if (isset($passedArgs[$paginationRule])) {
|
||||
$rules[$paginationRule] = $passedArgs[$paginationRule];
|
||||
}
|
||||
}
|
||||
if (empty($rules['limit'])) {
|
||||
$events = array();
|
||||
$i = 1;
|
||||
|
|
Loading…
Reference in New Issue