* get all reports * * @return array * @throws PreConditionNotMetException */
()
| 85 | * @throws PreConditionNotMetException |
| 86 | */ |
| 87 | public function index(): array { |
| 88 | $ownReports = $this->ReportMapper->index(); |
| 89 | $sharedReports = $this->ShareService->getSharedItems(ShareService::SHARE_ITEM_TYPE_REPORT); |
| 90 | $keysToKeep = array( |
| 91 | 'id', |
| 92 | 'name', |
| 93 | 'dataset', |
| 94 | 'favorite', |
| 95 | 'parent', |
| 96 | 'type', |
| 97 | 'item_type', |
| 98 | 'isShare', |
| 99 | 'shareId', |
| 100 | 'version' |
| 101 | ); |
| 102 | |
| 103 | // get shared reports and remove duplicates |
| 104 | $existingIds = array_flip(array_column($ownReports, 'id')); |
| 105 | foreach ($sharedReports as $sharedReport) { |
| 106 | if (!isset($existingIds[$sharedReport['id']])) { |
| 107 | // just keep the necessary fields |
| 108 | $ownReports[] = $sharedReport; |
| 109 | $existingIds[$sharedReport['id']] = true; |
| 110 | } |
| 111 | } |
| 112 | if (count($ownReports) === 0) return $ownReports; |
| 113 | |
| 114 | $favorites = $this->tagManager->load('analytics')->getFavorites(); |
| 115 | foreach ($ownReports as &$ownReport) { |
| 116 | $hasTag = 0; |
| 117 | if (is_array($favorites) and in_array($ownReport['id'], $favorites)) { |
| 118 | $hasTag = 1; |
| 119 | } |
| 120 | $ownReport['favorite'] = $hasTag; |
| 121 | $ownReport['item_type'] = ShareService::SHARE_ITEM_TYPE_REPORT; |
| 122 | $ownReport = $this->VariableService->replaceTextVariables($ownReport); |
| 123 | } |
| 124 | |
| 125 | // Final column filter |
| 126 | foreach ($ownReports as &$ownReport) { |
| 127 | $ownReport = array_intersect_key($ownReport, array_flip($keysToKeep)); |
| 128 | } |
| 129 | |
| 130 | return $ownReports; |
| 131 | } |
| 132 | |
| 133 | /** |
| 134 | * get own report details |
no test coverage detected