* get all shares for an item (report or panorama) * * @param $item_type * @return array|false * @throws Exception */
($item_type)
| 156 | * @throws Exception |
| 157 | */ |
| 158 | public function getSharedItems($item_type) { |
| 159 | if ($item_type === self::SHARE_ITEM_TYPE_PANORAMA) { |
| 160 | $sharedReports = $this->ShareMapper->getAllSharedPanoramas(); |
| 161 | } else { |
| 162 | $sharedReports = $this->ShareMapper->getAllSharedReports(); |
| 163 | } |
| 164 | $groupsOfUser = $this->groupManager->getUserGroups($this->userSession->getUser()); |
| 165 | $reports = array(); |
| 166 | |
| 167 | foreach ($sharedReports as $sharedReport) { |
| 168 | // shared with a group? |
| 169 | if ((int)$sharedReport['shareType'] === self::SHARE_TYPE_GROUP) { |
| 170 | // is the current user part of this group? |
| 171 | $this->logger->debug('Shareservice: is group share'); |
| 172 | if (array_key_exists($sharedReport['shareUid_owner'], $groupsOfUser)) { |
| 173 | // was the report not yet added to the result? |
| 174 | if (!in_array($sharedReport["id"], array_column($reports, "id"))) { |
| 175 | unset($sharedReport['shareType']); |
| 176 | unset($sharedReport['shareUid_owner']); |
| 177 | $sharedReport['isShare'] = self::SHARE_TYPE_GROUP; |
| 178 | $reports[] = $sharedReport; |
| 179 | } |
| 180 | } |
| 181 | // shared with a user directly? |
| 182 | } elseif ((int)$sharedReport['shareType'] === self::SHARE_TYPE_USER) { |
| 183 | // current user matching? |
| 184 | if ($this->userSession->getUser()->getUID() === $sharedReport['shareUid_owner']) { |
| 185 | // was the report not yet added to the result? |
| 186 | $this->logger->debug('Shareservice: Share belongs to current user'); |
| 187 | if (!in_array($sharedReport["id"], array_column($reports, "id"))) { |
| 188 | $this->logger->debug('Shareservice: Share added to output'); |
| 189 | unset($sharedReport['shareType']); |
| 190 | unset($sharedReport['shareUid_owner']); |
| 191 | $sharedReport['isShare'] = self::SHARE_TYPE_USER; |
| 192 | $reports[] = $sharedReport; |
| 193 | } |
| 194 | } |
| 195 | } |
| 196 | } |
| 197 | |
| 198 | if ($item_type === self::SHARE_ITEM_TYPE_PANORAMA) { |
| 199 | foreach ($reports as $report) { |
| 200 | if ((int)$report['type'] === PanoramaService::REPORT_TYPE_GROUP) { |
| 201 | $subreport = $this->PanoramaMapper->getPanoramasByGroup($report['id'], $report['user_id']); |
| 202 | $subreport = array_map(function ($pano) { |
| 203 | $pano['isShare'] = self::SHARE_TYPE_GROUP; |
| 204 | return $pano; |
| 205 | }, $subreport); |
| 206 | |
| 207 | $reports = array_merge($reports, $subreport); |
| 208 | } |
| 209 | } |
| 210 | } else { |
| 211 | foreach ($reports as $report) { |
| 212 | if ((int)$report['type'] === ReportService::REPORT_TYPE_GROUP) { |
| 213 | $subreport = $this->ReportMapper->getReportsByGroup($report['id'], $report['user_id']); |
| 214 | $subreport = array_map(function ($report) { |
| 215 | $report['isShare'] = self::SHARE_TYPE_GROUP; |
no test coverage detected