* Get the data from backend; * pre-evaluation of valid datasetId within read & readPublic is trusted here * also used in Pagecontroller-indexPublicMin ToDo: make this private * * @param $reportMetadata * @return array * @throws Exception */
($reportMetadata)
| 272 | * @throws Exception |
| 273 | */ |
| 274 | #[NoAdminRequired] |
| 275 | public function getData($reportMetadata) { |
| 276 | $datasource = (int)$reportMetadata['type']; |
| 277 | $datasetId = (int)$reportMetadata['dataset']; |
| 278 | |
| 279 | $filterOptions = $reportMetadata['filteroptions']; // need to remember the filter with original text variables |
| 280 | $reportMetadata = $this->VariableService->replaceFilterVariables($reportMetadata); // replace %xx% dynamic variables |
| 281 | |
| 282 | if ($datasource === DatasourceController::DATASET_TYPE_INTERNAL_DB) { |
| 283 | // Internal data |
| 284 | if ($datasetId !== 0) { |
| 285 | $result = $this->StorageService->read($datasetId, $reportMetadata); |
| 286 | } else { |
| 287 | $result['error'] = 'inconsistent report'; |
| 288 | } |
| 289 | } else { |
| 290 | // Realtime data |
| 291 | $result = $this->DatasourceController->read($datasource, $reportMetadata); |
| 292 | $result = DatasourceResultSanitizer::sanitize($result); |
| 293 | if (isset($result['filteroptions']) && is_string($result['filteroptions'])) { |
| 294 | $reportMetadata['filteroptions'] = $result['filteroptions']; |
| 295 | $filterOptions = $result['filteroptions']; |
| 296 | unset($result['filteroptions']); |
| 297 | } |
| 298 | |
| 299 | // datasource confirmed a stable cache key and no change |
| 300 | if (isset($result['cache']['notModified']) && $result['cache']['notModified'] === true) { |
| 301 | return $result; |
| 302 | } |
| 303 | } |
| 304 | |
| 305 | // sort the data by a given column |
| 306 | if ($filterOptions && isset($result['data'])) { |
| 307 | $result['data'] = $this->sortByColumn($result['data'], $filterOptions); |
| 308 | } |
| 309 | |
| 310 | unset($reportMetadata['parent'], $reportMetadata['user_id'], $reportMetadata['link'], $reportMetadata['dimension1'], $reportMetadata['dimension2'], $reportMetadata['dimension3'], $reportMetadata['value'], $reportMetadata['password'], $reportMetadata['dataset'], $reportMetadata['cacheKey']); |
| 311 | |
| 312 | $result['filterApplied'] = $reportMetadata['filteroptions']; |
| 313 | $reportMetadata['filteroptions'] = $filterOptions; // keep the original filters |
| 314 | |
| 315 | // there can be different values for no options. null during creation; empty after removal; => harmonize them |
| 316 | if (array_key_exists('chartoptions', $reportMetadata)) { |
| 317 | $reportMetadata['chartoptions'] = ($reportMetadata['chartoptions'] === '' || $reportMetadata['chartoptions'] === 'null') ? null : $reportMetadata['chartoptions']; |
| 318 | } |
| 319 | |
| 320 | if (array_key_exists('dataoptions', $reportMetadata)) { |
| 321 | $reportMetadata['dataoptions'] = ($reportMetadata['dataoptions'] === '' || $reportMetadata['dataoptions'] === 'null') ? null : $reportMetadata['dataoptions']; |
| 322 | } |
| 323 | $result['options'] = $reportMetadata; |
| 324 | $result['thresholds'] = $this->ThresholdService->read($reportMetadata['id']); |
| 325 | return $result; |
| 326 | } |
| 327 | |
| 328 | /** |
| 329 | * get the data when requested from public page |
no test coverage detected