authorizedGroupService = $authorizedGroupService; } /** * @throws NotFoundException * @throws Exception */ public function saveSettings(array $newGroups, string $class): DataResponse { $currentGroups = $this->authorizedGroupService->findExistingGroupsForClass($class); foreach ($currentGroups as $group) { /** @var AuthorizedGroup $group */ $removed = true; foreach ($newGroups as $groupData) { if ($groupData['gid'] === $group->getGroupId()) { $removed = false; break; } } if ($removed) { $this->authorizedGroupService->delete($group->getId()); } } foreach ($newGroups as $groupData) { $added = true; foreach ($currentGroups as $group) { /** @var AuthorizedGroup $group */ if ($groupData['gid'] === $group->getGroupId()) { $added = false; break; } } if ($added) { $this->authorizedGroupService->create($groupData['gid'], $class); } } return new DataResponse(['valid' => true]); } }