You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
137 lines
4.0 KiB
137 lines
4.0 KiB
![]()
10 years ago
|
<?php
|
||
|
/* For licensing terms, see /license.txt */
|
||
![]()
8 years ago
|
|
||
![]()
7 years ago
|
use Chamilo\CoreBundle\Repository\TrackECourseAccessRepository;
|
||
![]()
8 years ago
|
|
||
![]()
10 years ago
|
/**
|
||
![]()
8 years ago
|
* See the progress for a user when the gamification mode is active.
|
||
|
*
|
||
![]()
10 years ago
|
* @author Angel Fernando Quiroz Campos <angel.quiroz@beeznest.com>
|
||
![]()
8 years ago
|
*
|
||
![]()
10 years ago
|
* @package chamilo.gamification
|
||
|
*/
|
||
|
$cidReset = true;
|
||
![]()
9 years ago
|
require_once __DIR__.'/../inc/global.inc.php';
|
||
![]()
10 years ago
|
|
||
|
$this_section = SECTION_TRACKING;
|
||
![]()
6 years ago
|
$nameTools = get_lang('Progress');
|
||
![]()
10 years ago
|
|
||
|
api_block_anonymous_users();
|
||
|
|
||
|
if (api_get_setting('gamification_mode') == '0') {
|
||
|
api_not_allowed(true);
|
||
|
}
|
||
|
|
||
|
$userId = api_get_user_id();
|
||
|
$sessionId = isset($_GET['session_id']) ? intval($_GET['session_id']) : 0;
|
||
|
$allowAccess = false;
|
||
|
|
||
|
$entityManager = Database::getManager();
|
||
![]()
8 years ago
|
$user = api_get_user_entity($userId);
|
||
![]()
10 years ago
|
|
||
![]()
8 years ago
|
if (empty($sessionId) && $user) {
|
||
|
/** @var TrackECourseAccessRepository $trackCourseAccessRepository */
|
||
|
$trackCourseAccessRepository = $entityManager->getRepository('ChamiloCoreBundle:TrackECourseAccess');
|
||
![]()
10 years ago
|
$lastCourseAccess = $trackCourseAccessRepository->getLastAccessByUser($user);
|
||
![]()
10 years ago
|
$lastSessionId = 0;
|
||
![]()
10 years ago
|
if ($lastCourseAccess) {
|
||
|
$lastSessionId = $lastCourseAccess->getSessionId();
|
||
|
}
|
||
![]()
10 years ago
|
|
||
![]()
10 years ago
|
$UserIsSubscribedToSession = SessionManager::isUserSubscribedAsStudent($lastSessionId, $user->getId());
|
||
|
|
||
|
if (!empty($lastSessionId) && $UserIsSubscribedToSession) {
|
||
![]()
9 years ago
|
$urlWithSession = api_get_self().'?'.http_build_query([
|
||
![]()
8 years ago
|
'session_id' => $lastCourseAccess->getSessionId(),
|
||
![]()
10 years ago
|
]);
|
||
|
|
||
|
header("Location: $urlWithSession");
|
||
|
exit;
|
||
|
}
|
||
|
}
|
||
|
|
||
![]()
10 years ago
|
$sessionCourseSubscriptions = $user->getSessionCourseSubscriptions();
|
||
![]()
8 years ago
|
$currentSession = api_get_session_entity($sessionId);
|
||
![]()
10 years ago
|
|
||
|
$sessionList = [];
|
||
|
foreach ($sessionCourseSubscriptions as $subscription) {
|
||
|
$session = $subscription->getSession();
|
||
|
|
||
![]()
10 years ago
|
if (array_key_exists($session->getId(), $sessionList)) {
|
||
|
continue;
|
||
|
}
|
||
|
|
||
![]()
10 years ago
|
if ($currentSession && $currentSession->getId() === $session->getId()) {
|
||
|
$allowAccess = true;
|
||
|
}
|
||
|
|
||
![]()
10 years ago
|
$sessionList[$session->getId()] = $session;
|
||
![]()
10 years ago
|
}
|
||
|
|
||
|
if ($currentSession && !$allowAccess) {
|
||
|
api_not_allowed(true);
|
||
|
}
|
||
|
|
||
|
$template = new Template($nameTools);
|
||
|
$template->assign('user', $user);
|
||
|
$template->assign(
|
||
|
'user_avatar',
|
||
![]()
7 years ago
|
SocialManager::show_social_avatar_block('home', 0, $user->getId())
|
||
![]()
10 years ago
|
);
|
||
|
$template->assign(
|
||
|
'gamification_stars',
|
||
![]()
10 years ago
|
GamificationUtils::getTotalUserStars($user->getId(), $user->getStatus())
|
||
![]()
10 years ago
|
);
|
||
|
$template->assign(
|
||
|
'gamification_points',
|
||
![]()
10 years ago
|
GamificationUtils::getTotalUserPoints($user->getId(), $user->getStatus())
|
||
![]()
10 years ago
|
);
|
||
|
$template->assign(
|
||
|
'gamification_progress',
|
||
![]()
10 years ago
|
GamificationUtils::getTotalUserProgress($user->getId(), $user->getStatus())
|
||
![]()
10 years ago
|
);
|
||
|
$template->assign('sessions', $sessionList);
|
||
|
$template->assign('current_session', $currentSession);
|
||
|
|
||
|
if ($currentSession) {
|
||
|
$sessionData = [];
|
||
|
$sessionCourses = $currentSession->getCourses();
|
||
|
|
||
|
foreach ($sessionCourses as $sessionCourse) {
|
||
|
$course = $sessionCourse->getCourse();
|
||
|
|
||
|
$courseData = [
|
||
|
'title' => $course->getTitle(),
|
||
![]()
8 years ago
|
'stats' => [],
|
||
![]()
10 years ago
|
];
|
||
|
|
||
![]()
6 years ago
|
$courseInfo = api_get_course_info($course->getCode());
|
||
![]()
10 years ago
|
$learningPathList = new LearnpathList(
|
||
|
$user->getId(),
|
||
![]()
6 years ago
|
$courseInfo,
|
||
![]()
10 years ago
|
$currentSession->getId()
|
||
|
);
|
||
![]()
10 years ago
|
|
||
|
foreach ($learningPathList->list as $learningPathId => $learningPath) {
|
||
|
$courseData['stats'][] = [
|
||
|
$learningPath['lp_name'],
|
||
![]()
9 years ago
|
'lp/lp_controller.php?'.http_build_query([
|
||
![]()
10 years ago
|
'action' => 'stats',
|
||
|
'cidReq' => $course->getCode(),
|
||
|
'id_session' => $currentSession->getId(),
|
||
|
'gidReq' => 0,
|
||
![]()
8 years ago
|
'lp_id' => $learningPathId,
|
||
|
]).api_get_cidreq(),
|
||
![]()
10 years ago
|
];
|
||
|
}
|
||
|
$sessionData[$course->getId()] = $courseData;
|
||
|
}
|
||
|
$template->assign('session_data', $sessionData);
|
||
|
}
|
||
|
|
||
|
$layout = $template->get_template('gamification/my_progress.tpl');
|
||
|
|
||
|
$template->assign('header', $nameTools);
|
||
|
$template->assign('content', $template->fetch($layout));
|
||
|
$template->display_one_col_template();
|