loginHandler->isLoggedIn()) { throw new UnauthorizedException(); } $user = $this->loginHandler->getCurrentUser(); if (!$user->getPermission()->hasLevel(UserPermission::PROVIDER)) { throw new ForbiddenException(); } $body = $request->getQueryParams(); if (!array_key_exists('listid', $body)) { throw new BadRequestException(); } $list = $this->entityManager->getRepository(GamesList::class)->findOneBy([ 'owner' => $user, 'id' => $body['listid'] ]); if (!$list instanceof GamesList) { throw new BadRequestException(); } $keys = $this->entityManager->getRepository(Key::class)->findBy(['list' => $list]); $gameToKeyArray = []; foreach ($keys as $key) { $game = $key->getGame(); $id = $game->getId(); if (!array_key_exists($id, $gameToKeyArray)) { $gameToKeyArray[$id] = [ $game, [] ]; } $gameToKeyArray[$id][1][] = $key; } $result = []; foreach ($gameToKeyArray as [$game, $keys]) { $result[] = [ 'gamePicture' => '', 'name' => $game->getName(), 'keysAmount' => count($keys), 'igdbState' => 'not implermented', 'keys' => $keys, ]; } return new JsonResponse([ 'data' => $result ]); } }