MCPcopy Create free account
hub / github.com/Rello/analytics / index

Method index

lib/Service/ReportService.php:86–130  ·  view source on GitHub ↗

* get all reports * * @return array * @throws PreConditionNotMetException */

()

Source from the content-addressed store, hash-verified

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

Callers 1

getOwnFavoriteReportsMethod · 0.45

Calls 5

getSharedItemsMethod · 0.80
getFavoritesMethod · 0.80
replaceTextVariablesMethod · 0.80
countFunction · 0.50
loadMethod · 0.45

Tested by

no test coverage detected