my_progress.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. $this_section = SECTION_TRACKING;
  10. $nameTools = get_lang('MyProgress');
  11. api_block_anonymous_users();
  12. if (api_get_setting('platform.gamification_mode') == '0') {
  13. api_not_allowed(true);
  14. }
  15. $userId = api_get_user_id();
  16. $sessionId = isset($_GET['session_id']) ? intval($_GET['session_id']) : 0;
  17. $allowAccess = false;
  18. $userManager = UserManager::getManager();
  19. $entityManager = Database::getManager();
  20. $user = $userManager->findUserBy(['id' => $userId]);
  21. if (empty($sessionId)) {
  22. $trackCourseAccessRepository = $entityManager->getRepository(
  23. 'ChamiloCoreBundle:TrackECourseAccess'
  24. );
  25. $lastCourseAccess = $trackCourseAccessRepository->getLastAccessByUser($user);
  26. $lastSessionId = 0;
  27. if ($lastCourseAccess) {
  28. $lastSessionId = $lastCourseAccess->getSessionId();
  29. }
  30. $UserIsSubscribedToSession = SessionManager::isUserSubscribedAsStudent($lastSessionId, $user->getId());
  31. if (!empty($lastSessionId) && $UserIsSubscribedToSession) {
  32. $urlWithSession = api_get_self() . '?' . http_build_query([
  33. 'session_id' => $lastCourseAccess->getSessionId()
  34. ]);
  35. header("Location: $urlWithSession");
  36. exit;
  37. }
  38. }
  39. $sessionCourseSubscriptions = $user->getSessionCourseSubscriptions();
  40. $currentSession = $entityManager->find('ChamiloCoreBundle:Session', $sessionId);
  41. $sessionList = [];
  42. foreach ($sessionCourseSubscriptions as $subscription) {
  43. $session = $subscription->getSession();
  44. if (array_key_exists($session->getId(), $sessionList)) {
  45. continue;
  46. }
  47. if ($currentSession && $currentSession->getId() === $session->getId()) {
  48. $allowAccess = true;
  49. }
  50. $sessionList[$session->getId()] = $session;
  51. }
  52. if ($currentSession && !$allowAccess) {
  53. api_not_allowed(true);
  54. }
  55. $template = new Template($nameTools);
  56. $template->assign('user', $user);
  57. $template->assign(
  58. 'user_avatar',
  59. SocialManager::show_social_avatar_block('home', 0, $user->getId())
  60. );
  61. $template->assign(
  62. 'gamification_stars',
  63. GamificationUtils::getTotalUserStars($user->getId(), $user->getStatus())
  64. );
  65. $template->assign(
  66. 'gamification_points',
  67. GamificationUtils::getTotalUserPoints($user->getId(), $user->getStatus())
  68. );
  69. $template->assign(
  70. 'gamification_progress',
  71. GamificationUtils::getTotalUserProgress($user->getId(), $user->getStatus())
  72. );
  73. $template->assign('sessions', $sessionList);
  74. $template->assign('current_session', $currentSession);
  75. if ($currentSession) {
  76. $sessionData = [];
  77. $sessionCourses = $currentSession->getCourses();
  78. foreach ($sessionCourses as $sessionCourse) {
  79. $course = $sessionCourse->getCourse();
  80. $courseData = [
  81. 'title' => $course->getTitle(),
  82. 'stats' => []
  83. ];
  84. $learningPathList = new LearnpathList(
  85. $user->getId(),
  86. $course->getCode(),
  87. $currentSession->getId()
  88. );
  89. foreach ($learningPathList->list as $learningPathId => $learningPath) {
  90. $courseData['stats'][] = [
  91. $learningPath['lp_name'],
  92. 'lp/lp_controller.php?' . http_build_query([
  93. 'action' => 'stats',
  94. 'cidReq' => $course->getCode(),
  95. 'id_session' => $currentSession->getId(),
  96. 'gidReq' => 0,
  97. 'lp_id' => $learningPathId
  98. ]) . api_get_cidreq()
  99. ];
  100. }
  101. $sessionData[$course->getId()] = $courseData;
  102. }
  103. $template->assign('session_data', $sessionData);
  104. }
  105. $layout = $template->get_template('gamification/my_progress.tpl');
  106. $template->assign('header', $nameTools);
  107. $template->assign('content', $template->fetch($layout));
  108. $template->display_one_col_template();