@@ 229-257 (lines=29) @@ | ||
226 | * |
|
227 | * @return JsonResponse |
|
228 | */ |
|
229 | public function claimStepAction($id) |
|
230 | { |
|
231 | $user = $this->getUser(); |
|
232 | $step = $this->get('badger.game.repository.adventure_step')->find($id); |
|
233 | ||
234 | if (null === $step) { |
|
235 | return new JsonResponse('No step with this id.', 404); |
|
236 | } |
|
237 | ||
238 | if (!$this->get('security.authorization_checker')->isGranted('view', $step->getAdventure())) { |
|
239 | return new JsonResponse('No step with this id.', 404); |
|
240 | } |
|
241 | ||
242 | $stepCompletion = $this->get('badger.game.repository.adventure_step_completion')->findOneBy([ |
|
243 | 'user' => $user, |
|
244 | 'step' => $step |
|
245 | ]); |
|
246 | ||
247 | if (null !== $stepCompletion) { |
|
248 | return new JsonResponse('This step is already claimed.', 400); |
|
249 | } |
|
250 | ||
251 | $stepCompletionFactory = $this->get('badger.game.adventure_step_completion.factory'); |
|
252 | $stepCompletion = $stepCompletionFactory->create($user, $step); |
|
253 | ||
254 | $this->get('badger.game.saver.adventure_step_completion')->save($stepCompletion); |
|
255 | ||
256 | return new JsonResponse(); |
|
257 | } |
|
258 | ||
259 | /** |
|
260 | * @Route("/claim/quest/{id}", name="claimquest") |
|
@@ 265-293 (lines=29) @@ | ||
262 | * |
|
263 | * @return JsonResponse |
|
264 | */ |
|
265 | public function claimQuestAction($id) |
|
266 | { |
|
267 | $user = $this->getUser(); |
|
268 | $quest = $this->get('badger.game.repository.quest')->find($id); |
|
269 | ||
270 | if (null === $quest) { |
|
271 | return new JsonResponse('No quest with this id.', 400); |
|
272 | } |
|
273 | ||
274 | if (!$this->get('security.authorization_checker')->isGranted('view', $quest)) { |
|
275 | return new JsonResponse('No quest with this id.', 400); |
|
276 | } |
|
277 | ||
278 | $questCompletion = $this->get('badger.game.repository.quest_completion')->findOneBy([ |
|
279 | 'user' => $user, |
|
280 | 'quest' => $quest |
|
281 | ]); |
|
282 | ||
283 | if (null !== $questCompletion) { |
|
284 | return new JsonResponse('This quest is already claimed.', 400); |
|
285 | } |
|
286 | ||
287 | $questCompletionFactory = $this->get('badger.game.quest_completion.factory'); |
|
288 | $questCompletion = $questCompletionFactory->create($user, $quest); |
|
289 | ||
290 | $this->get('badger.game.saver.quest_completion')->save($questCompletion); |
|
291 | ||
292 | return new JsonResponse(); |
|
293 | } |
|
294 | ||
295 | /** |
|
296 | * @Route("/badges", name="badges") |