| 94 | } |
| 95 | |
| 96 | public function resolveReference(string $referenceText): ?IReference |
| 97 | { |
| 98 | if ($this->matchReference($referenceText)) { |
| 99 | preg_match('~/apps/analytics/(r|pa)/(\d+)(?:/(chart|table|content))?(?:[?#].*)?$~', $referenceText, $matches); |
| 100 | $itemId = (int)($matches[2] ?? 0); |
| 101 | $isPanorama = ($matches[1] ?? '') === 'pa'; |
| 102 | $renderMode = $matches[3] ?? 'link'; |
| 103 | $item = []; |
| 104 | if ($isPanorama) { |
| 105 | if ($itemId !== 0) { |
| 106 | // PanoramaService->read() already falls back to shared panoramas |
| 107 | $item = $this->PanoramaService->read($itemId); |
| 108 | } |
| 109 | $icon = 'panorama.svg'; |
| 110 | $type = $this->l10n->t('Panorama'); |
| 111 | } else { |
| 112 | if ($itemId !== 0) { |
| 113 | $item = $this->ReportService->read($itemId); |
| 114 | if (empty($item)) { |
| 115 | // fall back to reports shared with the current user |
| 116 | $item = $this->ShareService->getSharedReport($itemId); |
| 117 | } |
| 118 | } |
| 119 | $icon = 'report.svg'; |
| 120 | $type = $this->l10n->t('Report'); |
| 121 | } |
| 122 | if (!empty($item)) { |
| 123 | $imageUrl = $this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('analytics', $icon)); |
| 124 | $name = $this->l10n->t('Analytics') . ' ' . $type; |
| 125 | $subheader = $item['name']; |
| 126 | } else { |
| 127 | $imageUrl = $this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('analytics', 'noReport.svg')); |
| 128 | $name = $this->l10n->t('Report not found'); |
| 129 | $subheader = $this->l10n->t('This report was removed or is not shared with you'); |
| 130 | } |
| 131 | $reference = new Reference($referenceText); |
| 132 | $reference->setTitle($name); |
| 133 | $reference->setDescription($subheader); |
| 134 | $reference->setImageUrl($imageUrl); |
| 135 | $reference->setRichObject( |
| 136 | self::RICH_OBJECT_TYPE, |
| 137 | [ |
| 138 | 'name' => $name, |
| 139 | 'subheader' => $subheader, |
| 140 | 'url' => $referenceText, |
| 141 | 'image' => $imageUrl, |
| 142 | 'id' => $itemId, |
| 143 | 'item_type' => $isPanorama ? 'panorama' : 'report', |
| 144 | 'render_mode' => $renderMode, |
| 145 | 'found' => !empty($item) |
| 146 | ] |
| 147 | ); |
| 148 | return $reference; |
| 149 | } |
| 150 | return null; |
| 151 | } |
| 152 | |
| 153 | public function getCachePrefix(string $referenceId): string |