get_badges.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. if (api_get_setting('skill.allow_skills_tool') !== 'true') {
  9. api_not_allowed(true);
  10. }
  11. $userId = isset($_GET['user']) ? intval($_GET['user']) : 0;
  12. $courseId = api_get_course_int_id();
  13. $sessionId = api_get_session_id();
  14. if ($userId === 0) {
  15. exit;
  16. }
  17. $objSkillRelUser = new SkillRelUser();
  18. $userSkills = $objSkillRelUser->get_user_skills($userId, $courseId, $sessionId);
  19. if (empty($userSkills)) {
  20. exit;
  21. }
  22. $assertions = array();
  23. foreach ($userSkills as $skill) {
  24. $skillId = current($skill);
  25. $assertionUrl = api_get_path(WEB_CODE_PATH) . "badge/assertion.php?";
  26. $assertionUrl .= http_build_query(array(
  27. 'user' => $userId,
  28. 'skill' => $skillId,
  29. 'course' => $courseId,
  30. 'session' => $sessionId
  31. ));
  32. $assertions[] = $assertionUrl;
  33. }
  34. $backpack = 'https://backpack.openbadges.org/';
  35. $configBackpack = api_get_setting('gradebook.openbadges_backpack');
  36. if (strcmp($backpack, $configBackpack) !== 0) {
  37. $backpack = $configBackpack;
  38. }
  39. $htmlHeadXtra[] = '<script src="' . $backpack . 'issuer.js"></script>';
  40. //$tpl = new Template(get_lang('Badges'), false, false);
  41. echo
  42. "<script>"
  43. . "$(document).on('ready', function (){ OpenBadges.issue_no_modal(" . json_encode($assertions) . "); });"
  44. . "</script>"
  45. ;