| @@ 14-121 (lines=108) @@ | ||
| 11 | * @author Adrien Pétremann <[email protected]> |
|
| 12 | * @license http://opensource.org/licenses/MIT The MIT License (MIT) |
|
| 13 | */ |
|
| 14 | class BadgeCompletionController extends Controller |
|
| 15 | { |
|
| 16 | /** |
|
| 17 | * Lists all pending badge completions. |
|
| 18 | * |
|
| 19 | * @return Response |
|
| 20 | */ |
|
| 21 | public function indexAction() |
|
| 22 | { |
|
| 23 | $pendingCompletions = $this->get('badger.game.repository.quest_completion') |
|
| 24 | ->findBy(['pending' => 1]); |
|
| 25 | ||
| 26 | return $this->render('@Game/claimed-quests/index.html.twig', [ |
|
| 27 | 'pendingCompletions' => $pendingCompletions |
|
| 28 | ]); |
|
| 29 | } |
|
| 30 | ||
| 31 | /** |
|
| 32 | * Reject a badge completion by removing it from the database. |
|
| 33 | * |
|
| 34 | * @param string $id |
|
| 35 | * |
|
| 36 | * @return RedirectResponse |
|
| 37 | */ |
|
| 38 | public function rejectAction($id) |
|
| 39 | { |
|
| 40 | $pendingCompletion = $this->get('badger.game.repository.quest_completion') |
|
| 41 | ->findOneBy(['id' => $id, 'pending' => 1]); |
|
| 42 | ||
| 43 | if (null === $pendingCompletion) { |
|
| 44 | throw new NotFoundHttpException(sprintf('No pending QuestCompletion entity with id %s', $id)); |
|
| 45 | } |
|
| 46 | ||
| 47 | $questTitle = $pendingCompletion->getQuest()->getTitle(); |
|
| 48 | $username = $pendingCompletion->getUser()->getUsername(); |
|
| 49 | ||
| 50 | $questCompletionRemover = $this->get('badger.game.remover.quest_completion'); |
|
| 51 | $questCompletionRemover->remove($pendingCompletion); |
|
| 52 | ||
| 53 | $this->addFlash('notice', sprintf( |
|
| 54 | 'Successfully rejected the claimed quest "%s" for %s!', |
|
| 55 | $questTitle, |
|
| 56 | $username |
|
| 57 | )); |
|
| 58 | ||
| 59 | return $this->redirectToRoute('admin_claimed_quest_index'); |
|
| 60 | } |
|
| 61 | ||
| 62 | /** |
|
| 63 | * Accept a badge completion. |
|
| 64 | * |
|
| 65 | * @param string $id |
|
| 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 | /** |
|
| 103 | * Give a badge to a user directly by creating a completed badge completion. |
|
| 104 | * |
|
| 105 | * @return RedirectResponse |
|
| 106 | */ |
|
| 107 | public function giveAction() |
|
| 108 | { |
|
| 109 | ||
| 110 | } |
|
| 111 | ||
| 112 | /** |
|
| 113 | * Remove a badge from a user by removing the badge completion. |
|
| 114 | * |
|
| 115 | * @return RedirectResponse |
|
| 116 | */ |
|
| 117 | public function removeAction() |
|
| 118 | { |
|
| 119 | ||
| 120 | } |
|
| 121 | } |
|
| 122 | ||
| @@ 14-101 (lines=88) @@ | ||
| 11 | * @author Adrien Pétremann <[email protected]> |
|
| 12 | * @license http://opensource.org/licenses/MIT The MIT License (MIT) |
|
| 13 | */ |
|
| 14 | class QuestCompletionController extends Controller |
|
| 15 | { |
|
| 16 | /** |
|
| 17 | * Lists all pending quest completions. |
|
| 18 | * |
|
| 19 | * @return Response |
|
| 20 | */ |
|
| 21 | public function indexAction() |
|
| 22 | { |
|
| 23 | $pendingCompletions = $this->get('badger.game.repository.quest_completion') |
|
| 24 | ->findBy(['pending' => 1]); |
|
| 25 | ||
| 26 | return $this->render('@Game/claimed-quests/index.html.twig', [ |
|
| 27 | 'pendingCompletions' => $pendingCompletions |
|
| 28 | ]); |
|
| 29 | } |
|
| 30 | ||
| 31 | /** |
|
| 32 | * Reject a quest completion by removing it from the database. |
|
| 33 | * |
|
| 34 | * @param string $id |
|
| 35 | * |
|
| 36 | * @return RedirectResponse |
|
| 37 | */ |
|
| 38 | public function rejectAction($id) |
|
| 39 | { |
|
| 40 | $pendingCompletion = $this->get('badger.game.repository.quest_completion') |
|
| 41 | ->findOneBy(['id' => $id, 'pending' => 1]); |
|
| 42 | ||
| 43 | if (null === $pendingCompletion) { |
|
| 44 | throw new NotFoundHttpException(sprintf('No pending QuestCompletion entity with id %s', $id)); |
|
| 45 | } |
|
| 46 | ||
| 47 | $questTitle = $pendingCompletion->getQuest()->getTitle(); |
|
| 48 | $username = $pendingCompletion->getUser()->getUsername(); |
|
| 49 | ||
| 50 | $questCompletionRemover = $this->get('badger.game.remover.quest_completion'); |
|
| 51 | $questCompletionRemover->remove($pendingCompletion); |
|
| 52 | ||
| 53 | $this->addFlash('notice', sprintf( |
|
| 54 | 'Successfully rejected the claimed quest "%s" for %s!', |
|
| 55 | $questTitle, |
|
| 56 | $username |
|
| 57 | )); |
|
| 58 | ||
| 59 | return $this->redirectToRoute('admin_claimed_quest_index'); |
|
| 60 | } |
|
| 61 | ||
| 62 | /** |
|
| 63 | * Accept a quest completion. |
|
| 64 | * |
|
| 65 | * @param string $id |
|
| 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 | ||