assertion.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Show information about a new assertion
  5. * @author Angel Fernando Quiroz Campos <angel.quiroz@beeznest.com>
  6. * @package chamilo.badge
  7. */
  8. header('Content-Type: application/json');
  9. require_once __DIR__.'/../inc/global.inc.php';
  10. $userId = isset($_GET['user']) ? intval($_GET['user']) : 0;
  11. $skillId = isset($_GET['skill']) ? intval($_GET['skill']) : 0;
  12. $courseId = isset($_GET['course']) ? intval($_GET['course']) : 0;
  13. $sessionId = isset($_GET['session']) ? intval($_GET['session']) : 0;
  14. if ($userId === 0 || $skillId === 0) {
  15. exit;
  16. }
  17. $objSkill = new Skill();
  18. if (!$objSkill->userHasSkill($userId, $skillId, $courseId, $sessionId)) {
  19. exit;
  20. }
  21. $objSkillRelUser = new SkillRelUser();
  22. $userSkill = $objSkillRelUser->getByUserAndSkill(
  23. $userId,
  24. $skillId,
  25. $courseId,
  26. $sessionId
  27. );
  28. if ($userSkill == false) {
  29. exit;
  30. }
  31. $user = api_get_user_info($userSkill['user_id']);
  32. $json = array(
  33. 'uid' => $userSkill['id'],
  34. 'recipient' => array(
  35. 'type' => 'email',
  36. 'hashed' => false,
  37. 'identity' => $user['email']
  38. ),
  39. 'issuedOn' => strtotime($userSkill['acquired_skill_at']),
  40. 'badge' => api_get_path(WEB_CODE_PATH)."badge/class.php?id=$skillId",
  41. 'verify' => array(
  42. 'type' => 'hosted',
  43. 'url' => api_get_path(WEB_CODE_PATH)."badge/assertion.php?".http_build_query(array(
  44. 'user' => $userId,
  45. 'skill' => $skillId,
  46. 'course' => $courseId,
  47. 'session' => $sessionId
  48. ))
  49. )
  50. );
  51. echo json_encode($json);