Move function to get session progress to GamificationUtils - refs BT#9901 #TMI

1.10.x
Angel Fernando Quiroz Campos 11 years ago
parent 02973c5fb0
commit 276ca06334
  1. 39
      main/inc/lib/GamificationUtils.php
  2. 34
      main/inc/lib/sessionmanager.lib.php
  3. 2
      main/inc/lib/userportal.lib.php

@ -36,8 +36,8 @@ class GamificationUtils
}
/**
* Get the achieved points for a user in a session
* @param int $sessionId The session id
* Get the achieved points for an user in a session
* @param int $sessionId The session ID
* @param int $userId The user ID
* @return int The count of points
*/
@ -80,4 +80,39 @@ class GamificationUtils
return $totalPoints / count($courses);
}
/**
* Get the calculated progress for an user in a session
* @param int $sessionId The session ID
* @param int $userId The user ID
* @return float The progress
*/
public static function getSessionProgress($sessionId, $userId)
{
$courses = SessionManager::get_course_list_by_session_id($sessionId);
$progress = 0;
if (empty($courses)) {
return 0;
}
foreach ($courses as $course) {
$courseProgress = Tracking::get_avg_student_progress(
$userId,
$course['code'],
[],
$sessionId,
false,
true
);
if ($courseProgress === false) {
continue;
}
$progress += $courseProgress;
}
return $progress / count($courses);
}
}

@ -7007,38 +7007,4 @@ class SessionManager
return $totalStars / count($courses);
}
/**
* Get the calculated progress for a session when gamification mode is activated
* @param int $sessionId The session id
* @return int The progress
*/
public static function getProgressFromGamification($sessionId)
{
$courses = SessionManager::get_course_list_by_session_id($sessionId);
$progress = 0;
if (empty($courses)) {
return 0;
}
foreach ($courses as $course) {
$courseProgress = Tracking::get_avg_student_progress(
api_get_user_id(),
$course['code'],
[],
$sessionId,
false,
true
);
if ($courseProgress === false) {
continue;
}
$progress += $courseProgress;
}
return $progress / count($courses);
}
}

@ -1263,7 +1263,7 @@ class IndexManager
if ($gamificationModeIsActive) {
$params['stars'] = SessionManager::getNumberOfStarsFromGamification($params['id']);
$params['progress'] = SessionManager::getProgressFromGamification($params['id']);
$params['progress'] = GamificationUtils::getSessionProgress($params['id'], $this->user_id);
$params['points'] = GamificationUtils::getSessionPoints($params['id'], $this->user_id);
}

Loading…
Cancel
Save