* Read data from the storage backend * * @NoAdminRequired * @param $datasetId * @param $reportMetadata * @return array * @throws Exceptionx */
($datasetId, $reportMetadata)
| 51 | * @throws Exceptionx |
| 52 | */ |
| 53 | public function read($datasetId, $reportMetadata) { |
| 54 | $dimensions = []; |
| 55 | $header = array(); |
| 56 | $resolved = $this->DatasetStorageResolver->resolve((int)$datasetId); |
| 57 | $datasetMetadata = $resolved['dataset']; |
| 58 | if ($resolved['mode'] === DatasetStorageResolver::FLEXIBLE_SHARED) { |
| 59 | return $this->FlexibleStorageService->queryForReport((int)$datasetId, is_array($reportMetadata) ? $reportMetadata : null); |
| 60 | } |
| 61 | if ($reportMetadata && $reportMetadata['filteroptions'] !== null) { |
| 62 | $options = json_decode($reportMetadata['filteroptions'], true); |
| 63 | } else { |
| 64 | $options = null; |
| 65 | } |
| 66 | |
| 67 | if (!empty($datasetMetadata)) { |
| 68 | if (is_array($options) && isset($options['transformations'])) { |
| 69 | return [ |
| 70 | 'header' => [$datasetMetadata['dimension1'], $datasetMetadata['dimension2'], $datasetMetadata['value']], |
| 71 | 'columnRefs' => ['dimension1', 'dimension2', 'value'], |
| 72 | 'sourceColumns' => [ |
| 73 | ['ref' => 'dimension1', 'name' => $datasetMetadata['dimension1'], 'role' => 'dimension'], |
| 74 | ['ref' => 'dimension2', 'name' => $datasetMetadata['dimension2'], 'role' => 'dimension'], |
| 75 | ['ref' => 'value', 'name' => $datasetMetadata['value'], 'role' => 'measure', 'defaultAggregation' => 'sum'], |
| 76 | ], |
| 77 | 'dimensions' => ['dimension1' => $datasetMetadata['dimension1'], 'dimension2' => $datasetMetadata['dimension2']], |
| 78 | 'keyFigures' => [$datasetMetadata['value']], |
| 79 | 'data' => $this->StorageMapper->readRaw((int)$datasetId, $options), |
| 80 | 'error' => 0, |
| 81 | ]; |
| 82 | } |
| 83 | // output the dimensions available for filtering of this dataset |
| 84 | // this needs to map the technical name to its display name in the report |
| 85 | $dimensions['dimension1'] = $datasetMetadata['dimension1']; |
| 86 | $dimensions['dimension2'] = $datasetMetadata['dimension2']; |
| 87 | PanoramaFilterService::validateDimensions($reportMetadata['panoramaMappings'] ?? [], $dimensions); |
| 88 | |
| 89 | // return the header texts of the data being transferred according to the current drill down state selected by user |
| 90 | // if the dimension is not part of the drill down filter, it is not hidden => to be displayed |
| 91 | if (!isset($options['drilldown']['dimension1'])) $header[0] = $datasetMetadata['dimension1']; |
| 92 | if (!isset($options['drilldown']['dimension2'])) $header[1] = $datasetMetadata['dimension2']; |
| 93 | $header = array_values($header); |
| 94 | |
| 95 | $data = $this->StorageMapper->read($datasetMetadata['id'], $options); |
| 96 | $data = array_values($data); |
| 97 | foreach ($data as $key => $value) { |
| 98 | $data[$key] = array_values($value); |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | $keyFigures = [ |
| 103 | $datasetMetadata['value'] |
| 104 | ]; |
| 105 | |
| 106 | return empty($data) ? [ |
| 107 | 'header' => [...$header, ...$keyFigures], |
| 108 | 'sourceColumns' => [ |
| 109 | ['ref' => 'dimension1', 'name' => $datasetMetadata['dimension1'], 'role' => 'dimension'], |
| 110 | ['ref' => 'dimension2', 'name' => $datasetMetadata['dimension2'], 'role' => 'dimension'], |
nothing calls this directly
no test coverage detected