my_progress.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use Chamilo\CoreBundle\Entity\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('MyProgress');
  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. $learningPathList = new LearnpathList(
  87. $user->getId(),
  88. $course->getCode(),
  89. $currentSession->getId()
  90. );
  91. foreach ($learningPathList->list as $learningPathId => $learningPath) {
  92. $courseData['stats'][] = [
  93. $learningPath['lp_name'],
  94. 'lp/lp_controller.php?'.http_build_query([
  95. 'action' => 'stats',
  96. 'cidReq' => $course->getCode(),
  97. 'id_session' => $currentSession->getId(),
  98. 'gidReq' => 0,
  99. 'lp_id' => $learningPathId,
  100. ]).api_get_cidreq(),
  101. ];
  102. }
  103. $sessionData[$course->getId()] = $courseData;
  104. }
  105. $template->assign('session_data', $sessionData);
  106. }
  107. $layout = $template->get_template('gamification/my_progress.tpl');
  108. $template->assign('header', $nameTools);
  109. $template->assign('content', $template->fetch($layout));
  110. $template->display_one_col_template();