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. * @author Angel Fernando Quiroz Campos <angel.quiroz@beeznest.com>
  6. * @package chamilo.badge
  7. */
  8. require_once '../inc/global.inc.php';
  9. if (api_get_setting('allow_skills_tool') !== 'true') {
  10. api_not_allowed(true);
  11. }
  12. $userId = isset($_GET['user']) ? intval($_GET['user']) : 0;
  13. $courseId = api_get_course_int_id();
  14. $sessionId = api_get_session_id();
  15. if ($userId === 0) {
  16. exit;
  17. }
  18. $objSkillRelUser = new SkillRelUser();
  19. $userSkills = $objSkillRelUser->get_user_skills($userId, $courseId, $sessionId);
  20. if (empty($userSkills)) {
  21. exit;
  22. }
  23. $assertions = array();
  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(array(
  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. . "$(document).on('ready', function (){ OpenBadges.issue_no_modal(" . json_encode($assertions) . "); });"
  46. . "</script>"
  47. );
  48. $tpl->display_one_col_template();