assertion.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Show information about a new assertion.
  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. $skillId = isset($_GET['skill']) ? (int) $_GET['skill'] : 0;
  13. $courseId = isset($_GET['course']) ? (int) $_GET['course'] : 0;
  14. $sessionId = isset($_GET['session']) ? (int) $_GET['session'] : 0;
  15. if ($userId === 0 || $skillId === 0) {
  16. exit;
  17. }
  18. $objSkill = new Skill();
  19. if (!$objSkill->userHasSkill($userId, $skillId, $courseId, $sessionId)) {
  20. exit;
  21. }
  22. $objSkillRelUser = new SkillRelUser();
  23. $userSkill = $objSkillRelUser->getByUserAndSkill(
  24. $userId,
  25. $skillId,
  26. $courseId,
  27. $sessionId
  28. );
  29. if ($userSkill == false) {
  30. exit;
  31. }
  32. $user = api_get_user_info($userSkill['user_id']);
  33. $json = [
  34. 'uid' => $userSkill['id'],
  35. 'recipient' => [
  36. 'type' => 'email',
  37. 'hashed' => false,
  38. 'identity' => $user['email'],
  39. ],
  40. 'issuedOn' => strtotime($userSkill['acquired_skill_at']),
  41. 'badge' => api_get_path(WEB_CODE_PATH)."badge/class.php?id=$skillId",
  42. 'verify' => [
  43. 'type' => 'hosted',
  44. 'url' => api_get_path(WEB_CODE_PATH)."badge/assertion.php?".http_build_query([
  45. 'user' => $userId,
  46. 'skill' => $skillId,
  47. 'course' => $courseId,
  48. 'session' => $sessionId,
  49. ]),
  50. ],
  51. ];
  52. header('Content-Type: application/json');
  53. echo json_encode($json);