MCPcopy Create free account
hub / github.com/Rello/analytics / getData

Method getData

lib/Controller/OutputController.php:250–302  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

248 * @throws Exception
249 */
250 #[NoAdminRequired]
251 public function getData($reportMetadata) {
252 $datasource = (int)$reportMetadata['type'];
253 $datasetId = (int)$reportMetadata['dataset'];
254
255 $filterOptions = $reportMetadata['filteroptions']; // need to remember the filter with original text variables
256 $reportMetadata = $this->VariableService->replaceFilterVariables($reportMetadata); // replace %xx% dynamic variables
257
258 if ($datasource === DatasourceController::DATASET_TYPE_INTERNAL_DB) {
259 // Internal data
260 if ($datasetId !== 0) {
261 $result = $this->StorageService->read($datasetId, $reportMetadata);
262 } else {
263 $result['error'] = 'inconsistent report';
264 }
265 } else {
266 // Realtime data
267 $result = $this->DatasourceController->read($datasource, $reportMetadata);
268 $result = DatasourceResultSanitizer::sanitize($result);
269 if (isset($result['filteroptions']) && is_string($result['filteroptions'])) {
270 $reportMetadata['filteroptions'] = $result['filteroptions'];
271 $filterOptions = $result['filteroptions'];
272 unset($result['filteroptions']);
273 }
274
275 // datasource confirmed a stable cache key and no change
276 if (isset($result['cache']['notModified']) && $result['cache']['notModified'] === true) {
277 return $result;
278 }
279 }
280
281 // sort the data by a given column
282 if ($filterOptions && isset($result['data'])) {
283 $result['data'] = $this->sortByColumn($result['data'], $filterOptions);
284 }
285
286 unset($reportMetadata['parent'], $reportMetadata['user_id'], $reportMetadata['link'], $reportMetadata['dimension1'], $reportMetadata['dimension2'], $reportMetadata['dimension3'], $reportMetadata['value'], $reportMetadata['password'], $reportMetadata['dataset'], $reportMetadata['cacheKey']);
287
288 $result['filterApplied'] = $reportMetadata['filteroptions'];
289 $reportMetadata['filteroptions'] = $filterOptions; // keep the original filters
290
291 // there can be different values for no options. null during creation; empty after removal; => harmonize them
292 if (array_key_exists('chartoptions', $reportMetadata)) {
293 $reportMetadata['chartoptions'] = ($reportMetadata['chartoptions'] === '' || $reportMetadata['chartoptions'] === 'null') ? null : $reportMetadata['chartoptions'];
294 }
295
296 if (array_key_exists('dataoptions', $reportMetadata)) {
297 $reportMetadata['dataoptions'] = ($reportMetadata['dataoptions'] === '' || $reportMetadata['dataoptions'] === 'null') ? null : $reportMetadata['dataoptions'];
298 }
299 $result['options'] = $reportMetadata;
300 $result['thresholds'] = $this->ThresholdService->read($reportMetadata['id']);
301 return $result;
302 }
303
304 /**
305 * get the data when requested from public page

Callers 14

readPreviewMethod · 0.95
readPublicMethod · 0.95
report.jsFile · 0.45
sidebar.jsFile · 0.45
navigation.jsFile · 0.45
filter.jsFile · 0.45
dashboard.jsFile · 0.45
app.jsFile · 0.45
createFunction · 0.45
jspdf.umd.min.jsFile · 0.45
getChangesForVersionMethod · 0.45

Calls 4

sortByColumnMethod · 0.95
sanitizeMethod · 0.80
readMethod · 0.45

Tested by

no test coverage detected