Fix calculate stars and points - refs BT#9886 #TMI

1.10.x
Angel Fernando Quiroz Campos 10 years ago
parent 2ca853b514
commit 11bd03b49b
  1. 6
      main/gamification/my_progress.php
  2. 16
      main/inc/lib/GamificationUtils.php
  3. 20
      main/newscorm/learnpath.class.php
  4. 4
      main/template/default/gamification/my_progress.tpl

@ -34,11 +34,15 @@ $sessionList = [];
foreach ($sessionCourseSubscriptions as $subscription) { foreach ($sessionCourseSubscriptions as $subscription) {
$session = $subscription->getSession(); $session = $subscription->getSession();
if (array_key_exists($session->getId(), $sessionList)) {
continue;
}
if ($currentSession && $currentSession->getId() === $session->getId()) { if ($currentSession && $currentSession->getId() === $session->getId()) {
$allowAccess = true; $allowAccess = true;
} }
$sessionList[] = $session; $sessionList[$session->getId()] = $session;
} }
if ($currentSession && !$allowAccess) { if ($currentSession && !$allowAccess) {

@ -13,7 +13,7 @@ class GamificationUtils
* Get the calculated points on session with gamification mode * Get the calculated points on session with gamification mode
* @param int $userId The user ID * @param int $userId The user ID
* @param int $userStatus The user Status * @param int $userStatus The user Status
* @return int * @return float
*/ */
public static function getTotalUserPoints($userId, $userStatus) public static function getTotalUserPoints($userId, $userStatus)
{ {
@ -32,7 +32,7 @@ class GamificationUtils
$points += self::getSessionPoints($session['id'], $userId); $points += self::getSessionPoints($session['id'], $userId);
} }
return $points; return round($points / count($sessions), 2);
} }
/** /**
@ -77,7 +77,7 @@ class GamificationUtils
$totalPoints += $score; $totalPoints += $score;
} }
return $totalPoints / count($courses); return round($totalPoints / count($courses), 2);
} }
/** /**
@ -112,7 +112,7 @@ class GamificationUtils
$progress += $courseProgress; $progress += $courseProgress;
} }
return $progress / count($courses); return round($progress / count($courses), 2);
} }
/** /**
@ -157,7 +157,7 @@ class GamificationUtils
$totalStars += $stars; $totalStars += $stars;
} }
return $totalStars / count($courses); return round($totalStars / count($courses));
} }
/** /**
@ -183,14 +183,14 @@ class GamificationUtils
$stars += self::getSessionStars($session['id'], $userId); $stars += self::getSessionStars($session['id'], $userId);
} }
return $stars; return round($stars / count($sessions));
} }
/** /**
* Get the total progress on sessions with gamification mode * Get the total progress on sessions with gamification mode
* @param int $userId The user ID * @param int $userId The user ID
* @param int $userStatus The user Status * @param int $userStatus The user Status
* @return int * @return float
*/ */
public static function getTotalUserProgress($userId, $userStatus) public static function getTotalUserProgress($userId, $userStatus)
{ {
@ -209,7 +209,7 @@ class GamificationUtils
$progress += self::getSessionProgress($session['id'], $userId); $progress += self::getSessionProgress($session['id'], $userId);
} }
return $progress; return round($progress / count($sessions), 2);
} }
} }

@ -10202,16 +10202,13 @@ EOD;
// Calculate stars chapters evaluation // Calculate stars chapters evaluation
$exercisesItems = $this->getExercisesItems(); $exercisesItems = $this->getExercisesItems();
if ($exercisesItems === false) { if (!empty($exercisesItems)) {
return $stars;
}
$totalResult = 0; $totalResult = 0;
foreach ($exercisesItems as $exerciseItem) { foreach ($exercisesItems as $exerciseItem) {
$exerciseResultInfo = Event::getExerciseResultsByUser( $exerciseResultInfo = Event::getExerciseResultsByUser(
$this->user_id, $this->user_id,
$exerciseItem->ref, $exerciseItem->path,
$this->course_int_id, $this->course_int_id,
$sessionId, $sessionId,
$this->lp_id, $this->lp_id,
@ -10238,17 +10235,15 @@ EOD;
if ($totalExerciseAverage >= 80) { if ($totalExerciseAverage >= 80) {
$stars++; $stars++;
} }
}
// Calculate star for final evaluation // Calculate star for final evaluation
$finalEvaluationItem = $this->getFinalEvaluationItem(); $finalEvaluationItem = $this->getFinalEvaluationItem();
if (empty($finalEvaluationItem)) { if (!empty($finalEvaluationItem)) {
return $stars;
}
$evaluationResultInfo = Event::getExerciseResultsByUser( $evaluationResultInfo = Event::getExerciseResultsByUser(
$this->user_id, $this->user_id,
$finalEvaluationItem->ref, $finalEvaluationItem->path,
$this->course_int_id, $this->course_int_id,
$sessionId, $sessionId,
$this->lp_id, $this->lp_id,
@ -10261,11 +10256,14 @@ EOD;
$evaluationResult += $result['exe_result'] * 100 / $result['exe_weighting']; $evaluationResult += $result['exe_result'] * 100 / $result['exe_weighting'];
} }
$evaluationAverage = $evaluationResult / (count($evaluationResultInfo) > 0 ? count($evaluationResultInfo) : 1); $averageDivisor = count($evaluationResultInfo) > 0 ? count($evaluationResultInfo) : 1;
$evaluationAverage = $evaluationResult / $averageDivisor;
if ($evaluationAverage >= 80) { if ($evaluationAverage >= 80) {
$stars++; $stars++;
} }
}
return $stars; return $stars;
} }

@ -14,9 +14,11 @@
{% endfor %} {% endfor %}
{% endif %} {% endif %}
{% for i in 1..(5 - gamification_stars) %} {% if 4 - gamification_stars > 0 %}
{% for i in 1..(4 - gamification_stars) %}
<i class="fa fa-star in"></i> <i class="fa fa-star in"></i>
{% endfor %} {% endfor %}
{% endif %}
</div> </div>
<div class="progress"> <div class="progress">

Loading…
Cancel
Save