get_badges.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Show the achieved badges by an user.
  5. *
  6. * @author Angel Fernando Quiroz Campos <angel.quiroz@beeznest.com>
  7. *
  8. * @package chamilo.badge
  9. */
  10. require_once __DIR__.'/../inc/global.inc.php';
  11. $userId = isset($_GET['user']) ? (int) $_GET['user'] : 0;
  12. if (empty($userId)) {
  13. api_not_allowed(true);
  14. }
  15. Skill::isAllowed($userId);
  16. $courseId = api_get_course_int_id();
  17. $sessionId = api_get_session_id();
  18. $objSkillRelUser = new SkillRelUser();
  19. $userSkills = $objSkillRelUser->getUserSkills($userId, $courseId, $sessionId);
  20. if (empty($userSkills)) {
  21. api_not_allowed(true);
  22. }
  23. $assertions = [];
  24. foreach ($userSkills as $skill) {
  25. $skillId = current($skill);
  26. $assertionUrl = api_get_path(WEB_CODE_PATH).'badge/assertion.php?';
  27. $assertionUrl .= http_build_query([
  28. 'user' => $userId,
  29. 'skill' => $skillId,
  30. 'course' => $courseId,
  31. 'session' => $sessionId,
  32. ]);
  33. $assertions[] = $assertionUrl;
  34. }
  35. $backpack = 'https://backpack.openbadges.org/';
  36. $configBackpack = api_get_setting('openbadges_backpack');
  37. if (strcmp($backpack, $configBackpack) !== 0) {
  38. $backpack = $configBackpack;
  39. }
  40. $htmlHeadXtra[] = '<script src="'.$backpack.'issuer.js"></script>';
  41. $tpl = new Template(get_lang('Badges'), false, false);
  42. $tpl->assign(
  43. 'content',
  44. "<script>
  45. $(function() {
  46. OpenBadges.issue_no_modal(".json_encode($assertions).");
  47. });
  48. </script>"
  49. );
  50. $tpl->display_one_col_template();