* get the data when requested from a panorama * Special checks are performed to ensure, that the report is really part of the shared panorama * If-None-Match and eTags are being handled * * @param int $reportId * @param int|null $panoramaId * @param array|string|null $variables * @return DataResponse|NotFoundResponse * @throws Exception */
(int $reportId, ?int $panoramaId = null, $variables = null)
| 126 | * @throws Exception |
| 127 | */ |
| 128 | #[NoAdminRequired] |
| 129 | public function readPanorama(int $reportId, ?int $panoramaId = null, $variables = null) { |
| 130 | if ($panoramaId !== null) { |
| 131 | $panorama = $this->PanoramaService->read($panoramaId); |
| 132 | $metadata = []; |
| 133 | if ($panorama && $this->PanoramaService->isOwn($panoramaId)) { |
| 134 | $metadata = $this->ReportService->read($reportId); |
| 135 | } elseif ($panorama) { |
| 136 | $metadata = $this->ShareService->getSharedPanoramaReport($reportId, $panoramaId); |
| 137 | } |
| 138 | $pages = json_decode($panorama['pages'] ?? '[]', true) ?: []; |
| 139 | $member = false; |
| 140 | foreach ($pages as $page) { |
| 141 | foreach ($page['reports'] ?? [] as $report) { |
| 142 | if ((int)($report['type'] ?? -1) === 0 && (int)$report['value'] === $reportId) $member = true; |
| 143 | } |
| 144 | } |
| 145 | if (!$panorama || !$metadata || !$member) return new NotFoundResponse(); |
| 146 | try { |
| 147 | $filters = PanoramaFilterService::normalize($panorama['filters'] ?? [], $pages); |
| 148 | $metadata = PanoramaFilterService::apply($metadata, $filters, $variables ?? []); |
| 149 | if (!empty($metadata['panoramaMappings'])) { |
| 150 | // Temporary filters never reuse the unfiltered datasource validator or response cache. |
| 151 | unset($metadata['cacheKey']); |
| 152 | return $this->returnDataWithCacheableHeader($metadata, $metadata['filteroptions']); |
| 153 | } |
| 154 | } catch (\InvalidArgumentException $e) { |
| 155 | return new DataResponse(['error' => $e->getMessage()], Http::STATUS_BAD_REQUEST); |
| 156 | } |
| 157 | } elseif ($variables !== null) { |
| 158 | return new DataResponse(['error' => 'Panorama context is required'], Http::STATUS_BAD_REQUEST); |
| 159 | } |
| 160 | $reportMetadata = $panoramaId !== null ? $metadata : $this->ReportService->read($reportId); |
| 161 | if ($panoramaId === null && empty($reportMetadata)) $reportMetadata = $this->ShareService->getSharedPanoramaReport($reportId); |
| 162 | |
| 163 | if (!empty($reportMetadata)) { |
| 164 | $reportMetadata['cacheKey'] = $this->getDatasourceCacheKey( |
| 165 | $reportMetadata, |
| 166 | $this->getRequestCacheKey() |
| 167 | ); |
| 168 | |
| 169 | // internal storage reports are validated directly against version |
| 170 | if ((int)$reportMetadata['type'] === DatasourceController::DATASET_TYPE_INTERNAL_DB) { |
| 171 | $response = $this->evaluateIfNoneMatch($reportMetadata); |
| 172 | if ($response instanceof DataResponse) { |
| 173 | return $response; |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | // external datasource caching is evaluated by datasource specific logic |
| 178 | return $this->returnDataWithCacheableHeader($reportMetadata, null); |
| 179 | } else { |
| 180 | return new NotFoundResponse(); |
| 181 | } |
| 182 | } |
| 183 | |
| 184 | private function returnDataWithCacheableHeader($reportMetadata, $filteroptions) { |
| 185 | $result = $this->getData($reportMetadata); |
nothing calls this directly
no test coverage detected