my_progress.php 3.9 KB

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