new: [API] Export warninglists to CSV

pull/7464/head
Jakub Onderka 2021-06-02 15:26:20 +02:00
parent e03d566c0d
commit b39dc5cd14
2 changed files with 12 additions and 1 deletions

View File

@ -102,7 +102,7 @@ class IndexFilterComponent extends Component
public function isCsv()
{
return $this->Controller->request->header('Accept') === 'text/csv' || $this->Controller->RequestHandler->prefers() === 'csv';
}
public function isXml()

View File

@ -337,6 +337,17 @@ class WarninglistsController extends AppController
if (empty($warninglist)) {
throw new NotFoundException(__('Warninglist not found.'));
}
if ($this->IndexFilter->isCsv()) {
$csv = [];
foreach ($warninglist['WarninglistEntry'] as $entry) {
$line = $entry['value'];
if ($entry['comment']) {
$line .= ';' . $entry['comment'];
}
$csv[] = $line;
}
return $this->RestResponse->viewData(implode("\n", $csv), 'csv');
}
if ($this->_isRest()) {
$warninglist['Warninglist']['WarninglistEntry'] = $warninglist['WarninglistEntry'];
$warninglist['Warninglist']['WarninglistType'] = $warninglist['WarninglistType'];