get_badges.php 1.5 KB

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