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

Method index

lib/Service/ReportService.php:87–131  ·  view source on GitHub ↗

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

()

Source from the content-addressed store, hash-verified

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

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