| @@ 71-101 (lines=31) @@ | ||
| 68 | *  | 
                                |
| 69 | * @return RedirectResponse  | 
                                |
| 70 | */  | 
                                |
| 71 | public function acceptAction($id)  | 
                                |
| 72 |     { | 
                                |
| 73 |         $pendingCompletion = $this->get('badger.game.repository.badge_completion') | 
                                |
| 74 | ->findOneBy(['id' => $id, 'pending' => 1]);  | 
                                |
| 75 | ||
| 76 |         if (null === $pendingCompletion) { | 
                                |
| 77 |             throw new NotFoundHttpException(sprintf('No pending BadgeCompletion entity with id %s', $id)); | 
                                |
| 78 | }  | 
                                |
| 79 | ||
| 80 | $user = $pendingCompletion->getUser();  | 
                                |
| 81 | $badge = $pendingCompletion->getBadge();  | 
                                |
| 82 | ||
| 83 | $pendingCompletion->setPending(false);  | 
                                |
| 84 | $pendingCompletion->setCompletionDate(new \DateTime());  | 
                                |
| 85 | ||
| 86 |         $errors = $this->get('validator')->validate($pendingCompletion); | 
                                |
| 87 | ||
| 88 |         if (0 === count($errors)) { | 
                                |
| 89 |             $this->get('badger.game.saver.badge_completion')->save($pendingCompletion); | 
                                |
| 90 | ||
| 91 |             $this->addFlash('notice', sprintf( | 
                                |
| 92 | '%s successfully unlocked the badge "%s"!',  | 
                                |
| 93 | $user->getUsername(),  | 
                                |
| 94 | $badge->getTitle()  | 
                                |
| 95 | ));  | 
                                |
| 96 |         } else { | 
                                |
| 97 |             $this->addFlash('error', (string) $errors); | 
                                |
| 98 | }  | 
                                |
| 99 | ||
| 100 |         return $this->redirectToRoute('admin_claimed_badge_index'); | 
                                |
| 101 | }  | 
                                |
| 102 | ||
| 103 | /**  | 
                                |
| 104 | * Give a badge to a user directly by creating a completed badge completion.  | 
                                |
| @@ 69-100 (lines=32) @@ | ||
| 66 | *  | 
                                |
| 67 | * @return RedirectResponse  | 
                                |
| 68 | */  | 
                                |
| 69 | public function acceptAction($id)  | 
                                |
| 70 |     { | 
                                |
| 71 |         $pendingCompletion = $this->get('badger.game.repository.quest_completion') | 
                                |
| 72 | ->findOneBy(['id' => $id, 'pending' => 1]);  | 
                                |
| 73 | ||
| 74 |         if (null === $pendingCompletion) { | 
                                |
| 75 |             throw new NotFoundHttpException(sprintf('No pending QuestCompletion entity with id %s', $id)); | 
                                |
| 76 | }  | 
                                |
| 77 | ||
| 78 | $user = $pendingCompletion->getUser();  | 
                                |
| 79 | $quest = $pendingCompletion->getQuest();  | 
                                |
| 80 | ||
| 81 | $pendingCompletion->setPending(false);  | 
                                |
| 82 | $pendingCompletion->setCompletionDate(new \DateTime());  | 
                                |
| 83 | ||
| 84 |         $errors = $this->get('validator')->validate($pendingCompletion); | 
                                |
| 85 | ||
| 86 |         if (0 === count($errors)) { | 
                                |
| 87 | $user->addNuts($quest->getReward());  | 
                                |
| 88 |             $this->get('badger.game.saver.quest_completion')->save($pendingCompletion); | 
                                |
| 89 | ||
| 90 |             $this->addFlash('notice', sprintf( | 
                                |
| 91 | '%s successfully completed the quest "%s"!',  | 
                                |
| 92 | $user->getUsername(),  | 
                                |
| 93 | $quest->getTitle()  | 
                                |
| 94 | ));  | 
                                |
| 95 |         } else { | 
                                |
| 96 |             $this->addFlash('error', (string) $errors); | 
                                |
| 97 | }  | 
                                |
| 98 | ||
| 99 |         return $this->redirectToRoute('admin_claimed_quest_index'); | 
                                |
| 100 | }  | 
                                |
| 101 | }  | 
                                |
| 102 | ||