backend = Backend::createBackend($this->_getParam('backend')); $this->view->url = Url::fromRequest(); } protected function handleFormatRequest($query) { if ($this->compactView !== null && ($this->_getParam('view', false) === 'compact')) { $this->_helper->viewRenderer($this->compactView); } if ($this->_getParam('format') === 'sql') { echo '
'
. htmlspecialchars(wordwrap($query->dump()))
. '';
exit;
}
if ($this->_getParam('format') === 'json'
|| $this->_request->getHeader('Accept') === 'application/json') {
header('Content-type: application/json');
echo json_encode($query->getQuery()->fetchAll());
exit;
}
if ($this->_getParam('format') === 'csv'
|| $this->_request->getHeader('Accept') === 'text/csv') {
Csv::fromQuery($query)->dump();
exit;
}
}
/**
* Apply a restriction on the given data view
*
* @param string $restriction The name of restriction
* @param DataView $view The view to restrict
*
* @return DataView $view
*/
protected function applyRestriction($restriction, DataView $view)
{
foreach ($this->getRestrictions($restriction) as $filter) {
$view->applyFilter(Filter::fromQueryString($filter));
}
return $view;
}
}