CSV/JSON export: work with new query interfaces

NB: I do not like the fact that we have to do as follows:

  DataView->getQuery()->fetchWhatever();

Guess this is worth a few more proxy functions.
This commit is contained in:
Thomas Gelf 2014-06-21 00:09:11 +02:00
parent cb1ef78d2f
commit e2f7a1054e
2 changed files with 4 additions and 4 deletions

View File

@ -4,7 +4,7 @@
namespace Icinga\File;
use Icinga\Data\Fetchable;
use Icinga\Data\Browsable;
class Csv
{
@ -12,7 +12,7 @@ class Csv
protected function __construct() {}
public static function fromQuery(Fetchable $query)
public static function fromQuery(Browsable $query)
{
$csv = new Csv();
$csv->query = $query;
@ -29,7 +29,7 @@ class Csv
{
$first = true;
$csv = '';
foreach ($this->query->fetchAll() as $row) {
foreach ($this->query->getQuery()->fetchAll() as $row) {
if ($first) {
$csv .= implode(',', array_keys((array) $row)) . "\r\n";
$first = false;

View File

@ -76,7 +76,7 @@ class Controller extends ActionController
if ($this->_getParam('format') === 'json'
|| $this->_request->getHeader('Accept') === 'application/json') {
header('Content-type: application/json');
echo json_encode($query->fetchAll());
echo json_encode($query->getQuery()->fetchAll());
exit;
}
if ($this->_getParam('format') === 'csv'