Пример #1
0
 /**
  * @Route("/claim", name="icap_badge_claim_badge")
  * @ParamConverter("user", options={"authenticatedUser" = true})
  * @Template()
  */
 public function claimAction(Request $request, User $user)
 {
     $badgeClaim = new BadgeClaim();
     $badgeClaim->setUser($user);
     $form = $this->createForm($this->get('icap_badge.form.claimBadge'), $badgeClaim);
     if ($request->isMethod('POST')) {
         $form->handleRequest($request);
         $flashBag = $this->get('session')->getFlashBag();
         if ($form->isValid()) {
             $translator = $this->get('translator');
             try {
                 $entityManager = $this->getDoctrine()->getManager();
                 $badge = $form->get('badge')->getData();
                 if (null !== $badge) {
                     /** @var \Claroline\CoreBundle\Manager\BadgeManager $badgeManager */
                     $badgeManager = $this->get('icap_badge.manager.badge');
                     $badgeManager->makeClaim($badge, $user);
                     $flashBag->add('success', $translator->trans('badge_claim_success_message', array(), 'icap_badge'));
                 } else {
                     $flashBag->add('warning', $translator->trans('badge_claim_nothing_selected_warning_message', array(), 'icap_badge'));
                 }
             } catch (\Exception $exception) {
                 $flashBag->add('error', $translator->trans($exception->getMessage(), array(), 'icap_badge'));
             }
             return $this->redirect($this->generateUrl('icap_badge_profile_view_badges'));
         }
     }
     return array('form' => $form->createView());
 }
 /**
  * @Route("/my_badges/claim/{badge_id}", name="icap_badge_workspace_tool_claim_badge")
  * @ParamConverter(
  *     "workspace",
  *     class="ClarolineCoreBundle:Workspace\Workspace",
  *     options={"id" = "workspaceId"}
  * )
  * @ParamConverter("user", options={"authenticatedUser" = true})
  * @ParamConverter("badge", class="IcapBadgeBundle:Badge", options={"id" = "badge_id"})
  * @Template()
  */
 public function claimAction(Workspace $workspace, User $user, Badge $badge)
 {
     $badgeClaim = new BadgeClaim();
     $badgeClaim->setUser($user);
     try {
         $flashBag = $this->get('session')->getFlashBag();
         $translator = $this->get('translator');
         /** @var \Icap\BadgeBundle\Manager\BadgeManager $badgeManager */
         $badgeManager = $this->get('icap_badge.manager.badge');
         $badgeManager->makeClaim($badge, $user);
         $flashBag->add('success', $translator->trans('badge_claim_success_message', array(), 'icap_badge'));
     } catch (\Exception $exception) {
         $flashBag->add('error', $translator->trans($exception->getMessage(), array(), 'icap_badge'));
     }
     return $this->redirect($this->generateUrl('icap_badge_workspace_tool_my_badges', array('workspaceId' => $workspace->getId())));
 }
 /**
  * @Route("/claim/manage/{id}/{validate}", name="icap_badge_workspace_tool_manage_claim")
  * @ParamConverter(
  *     "workspace",
  *     class="ClarolineCoreBundle:Workspace\Workspace",
  *     options={"id" = "workspaceId"}
  * )
  * @Template
  */
 public function manageClaimAction(Workspace $workspace, BadgeClaim $badgeClaim, $validate = false)
 {
     if (null === $badgeClaim->getBadge()->getWorkspace()) {
         throw $this->createNotFoundException('No badge found.');
     }
     $this->checkUserIsAllowed($workspace);
     /** @var \Symfony\Component\Translation\TranslatorInterface $translator */
     $translator = $this->get('translator');
     $successMessage = $translator->trans('badge_reject_award_success_message', array(), 'icap_badge');
     $errorMessage = $translator->trans('badge_reject_award_error_message', array(), 'icap_badge');
     try {
         if ($validate) {
             $successMessage = $translator->trans('badge_validate_award_success_message', array(), 'icap_badge');
             $errorMessage = $translator->trans('badge_validate_award_error_message', array(), 'icap_badge');
             /** @var \Icap\BadgeBundle\Manager\BadgeManager $badgeManager */
             $badgeManager = $this->get('icap_badge.manager.badge');
             $awardedBadge = $badgeManager->addBadgeToUser($badgeClaim->getBadge(), $badgeClaim->getUser());
             if (!$awardedBadge) {
                 $successMessage = $translator->trans('badge_already_award_info_message', array(), 'icap_badge');
             }
         }
         $entityManager = $this->getDoctrine()->getManager();
         $entityManager->remove($badgeClaim);
         $entityManager->flush();
         $this->get('session')->getFlashBag()->add('success', $successMessage);
     } catch (\Exception $exception) {
         $this->get('session')->getFlashBag()->add('error', $errorMessage);
     }
     return $this->redirect($this->generateUrl('icap_badge_workspace_tool_badges', array('workspaceId' => $workspace->getId())));
 }
Пример #4
0
 public function makeClaim(Badge $badge, User $user)
 {
     $userBadge = $this->entityManager->getRepository('IcapBadgeBundle:UserBadge')->findOneByBadgeAndUser($badge, $user);
     if (null !== $userBadge) {
         throw new \Exception('badge_already_award_message');
     }
     $badgeClaim = $this->entityManager->getRepository('IcapBadgeBundle:BadgeClaim')->findOneByBadgeAndUser($badge, $user);
     if (null !== $badgeClaim) {
         throw new \Exception('badge_already_claim_message');
     }
     $badgeClaim = new BadgeClaim();
     $badgeClaim->setUser($user)->setBadge($badge);
     try {
         $this->entityManager->persist($badgeClaim);
         $this->entityManager->flush();
     } catch (\Exception $exception) {
         throw new \Exception('badge_claim_error_message', 0, $exception);
     }
 }