my_progress.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * See the progress for a user when the gamification mode is active
  5. * @author Angel Fernando Quiroz Campos <angel.quiroz@beeznest.com>
  6. * @package chamilo.gamification
  7. */
  8. $cidReset = true;
  9. require_once '../inc/global.inc.php';
  10. $this_section = SECTION_TRACKING;
  11. $nameTools = get_lang('MyProgress');
  12. api_block_anonymous_users();
  13. if (api_get_setting('gamification_mode') == '0') {
  14. api_not_allowed(true);
  15. }
  16. $userId = api_get_user_id();
  17. $sessionId = isset($_GET['session_id']) ? intval($_GET['session_id']) : 0;
  18. $allowAccess = false;
  19. $userManager = UserManager::getManager();
  20. $entityManager = Database::getManager();
  21. $user = $userManager->findUserBy(['id' => $userId]);
  22. if (empty($sessionId)) {
  23. $trackCourseAccessRepository = $entityManager->getRepository(
  24. 'ChamiloCoreBundle:TrackECourseAccess'
  25. );
  26. $lastCourseAccess = $trackCourseAccessRepository->getLastAccessByUser($user);
  27. if (!empty($lastCourseAccess)) {
  28. $urlWithSession = api_get_self() . '?' . http_build_query([
  29. 'session_id' => $lastCourseAccess->getSessionId()
  30. ]);
  31. header("Location: $urlWithSession");
  32. exit;
  33. }
  34. }
  35. $sessionCourseSubscriptions = $user->getSessionCourseSubscriptions();
  36. $currentSession = $entityManager->find('ChamiloCoreBundle:Session', $sessionId);
  37. $sessionList = [];
  38. foreach ($sessionCourseSubscriptions as $subscription) {
  39. $session = $subscription->getSession();
  40. if (array_key_exists($session->getId(), $sessionList)) {
  41. continue;
  42. }
  43. if ($currentSession && $currentSession->getId() === $session->getId()) {
  44. $allowAccess = true;
  45. }
  46. $sessionList[$session->getId()] = $session;
  47. }
  48. if ($currentSession && !$allowAccess) {
  49. api_not_allowed(true);
  50. }
  51. $template = new Template($nameTools);
  52. $template->assign('user', $user);
  53. $template->assign(
  54. 'user_avatar',
  55. SocialManager::show_social_avatar_block('home', 0, $user->getId())
  56. );
  57. $template->assign(
  58. 'gamification_stars',
  59. GamificationUtils::getTotalUserStars($user->getId(), $user->getStatus())
  60. );
  61. $template->assign(
  62. 'gamification_points',
  63. GamificationUtils::getTotalUserPoints($user->getId(), $user->getStatus())
  64. );
  65. $template->assign(
  66. 'gamification_progress',
  67. GamificationUtils::getTotalUserProgress($user->getId(), $user->getStatus())
  68. );
  69. $template->assign('sessions', $sessionList);
  70. $template->assign('current_session', $currentSession);
  71. if ($currentSession) {
  72. $sessionData = [];
  73. $sessionCourses = $currentSession->getCourses();
  74. foreach ($sessionCourses as $sessionCourse) {
  75. $course = $sessionCourse->getCourse();
  76. $courseData = [
  77. 'title' => $course->getTitle(),
  78. 'stats' => []
  79. ];
  80. $learningPathList = new LearnpathList($user->getId(), $course->getCode(), $currentSession->getId());
  81. foreach ($learningPathList->list as $learningPathId => $learningPath) {
  82. $courseData['stats'][] = [
  83. $learningPath['lp_name'],
  84. 'newscorm/lp_controller.php?' . http_build_query([
  85. 'action' => 'stats',
  86. 'cidReq' => $course->getCode(),
  87. 'id_session' => $currentSession->getId(),
  88. 'gidReq' => 0,
  89. 'lp_id' => $learningPathId
  90. ]) . api_get_cidreq()
  91. ];
  92. }
  93. $sessionData[$course->getId()] = $courseData;
  94. }
  95. $template->assign('session_data', $sessionData);
  96. }
  97. $layout = $template->get_template('gamification/my_progress.tpl');
  98. $template->assign('header', $nameTools);
  99. $template->assign('content', $template->fetch($layout));
  100. $template->display_one_col_template();