my_progress.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. $sessionCourseSubscriptions = $user->getSessionCourseSubscriptions();
  23. $currentSession = $entityManager->find('ChamiloCoreBundle:Session', $sessionId);
  24. $sessionList = [];
  25. foreach ($sessionCourseSubscriptions as $subscription) {
  26. $session = $subscription->getSession();
  27. if ($currentSession && $currentSession->getId() === $session->getId()) {
  28. $allowAccess = true;
  29. }
  30. $sessionList[] = $session;
  31. }
  32. if ($currentSession && !$allowAccess) {
  33. api_not_allowed(true);
  34. }
  35. $template = new Template($nameTools);
  36. $template->assign('user', $user);
  37. $template->assign(
  38. 'user_avatar',
  39. SocialManager::show_social_avatar_block('home', 0, $user->getId())
  40. );
  41. $template->assign(
  42. 'gamification_stars',
  43. GamificationUtils::getTotalUserStars($user->getId(), $user->getStatus())
  44. );
  45. $template->assign(
  46. 'gamification_points',
  47. GamificationUtils::getTotalUserPoints($user->getId(), $user->getStatus())
  48. );
  49. $template->assign(
  50. 'gamification_progress',
  51. GamificationUtils::getSessionProgress($user->getId(), $user->getStatus())
  52. );
  53. $template->assign('sessions', $sessionList);
  54. $template->assign('current_session', $currentSession);
  55. if ($currentSession) {
  56. $sessionData = [];
  57. $sessionCourses = $currentSession->getCourses();
  58. foreach ($sessionCourses as $sessionCourse) {
  59. $course = $sessionCourse->getCourse();
  60. $courseData = [
  61. 'title' => $course->getTitle(),
  62. 'stats' => []
  63. ];
  64. $learningPathList = new LearnpathList($user->getId(), $course->getCode(), $currentSession->getId());
  65. foreach ($learningPathList->list as $learningPathId => $learningPath) {
  66. $courseData['stats'][] = [
  67. $learningPath['lp_name'],
  68. 'newscorm/lp_controller.php?' . http_build_query([
  69. 'action' => 'stats',
  70. 'cidReq' => $course->getCode(),
  71. 'id_session' => $currentSession->getId(),
  72. 'gidReq' => 0,
  73. 'lp_id' => $learningPathId
  74. ]) . api_get_cidreq()
  75. ];
  76. }
  77. $sessionData[$course->getId()] = $courseData;
  78. }
  79. $template->assign('session_data', $sessionData);
  80. }
  81. $layout = $template->get_template('gamification/my_progress.tpl');
  82. $template->assign('header', $nameTools);
  83. $template->assign('content', $template->fetch($layout));
  84. $template->display_one_col_template();