* Preview the data (one row for column pickers, up to 20 for datasource previews) * * @param $type * @param $options * @return DataResponse|NotFoundResponse * @throws Exception */
(int $type, $options, int $limit = 1)
| 278 | * @throws Exception |
| 279 | */ |
| 280 | #[NoAdminRequired] |
| 281 | public function readPreview(int $type, $options, int $limit = 1) { |
| 282 | $reportMetadata = []; |
| 283 | try { |
| 284 | $reportMetadata['link'] = $this->DatasourceController->encodeOptionsForStorage($type, $options); |
| 285 | } catch (\InvalidArgumentException $e) { |
| 286 | return new DataResponse(['error' => $e->getMessage()], 400); |
| 287 | } |
| 288 | $reportMetadata['type'] = $type; |
| 289 | $reportMetadata['dataset'] = 0; |
| 290 | $reportMetadata['filteroptions'] = ''; |
| 291 | $reportMetadata['user_id'] = $this->userId; |
| 292 | $reportMetadata['id'] = 0; |
| 293 | |
| 294 | $result = $this->getData($reportMetadata); |
| 295 | unset($result['options'], $result['dimensions'], $result['filterApplied'], $result['thresholds']); |
| 296 | $result['data'] = array_slice($result['data'] ?? [], 0, max(1, min($limit, 20))); |
| 297 | |
| 298 | return new DataResponse($result, HTTP::STATUS_OK); |
| 299 | } |
| 300 | |
| 301 | |
| 302 | /** |
nothing calls this directly
no test coverage detected