my_progress.php 4.0 KB

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