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