Merge pull request #778 from AngelFQC/BT9886

Fix calculate stars and points - refs BT#9886 #TMI
1.10.x
Angel Fernando Quiroz Campos 9 years ago
commit 0e6e7e458e
  1. 12
      main/gamification/my_progress.php
  2. 16
      main/inc/lib/GamificationUtils.php
  3. 88
      main/newscorm/learnpath.class.php
  4. 32
      main/newscorm/lp_view.php
  5. 8
      main/template/default/gamification/my_progress.tpl
  6. 29
      main/template/default/learnpath/view.tpl

@ -34,11 +34,15 @@ $sessionList = [];
foreach ($sessionCourseSubscriptions as $subscription) {
$session = $subscription->getSession();
if (array_key_exists($session->getId(), $sessionList)) {
continue;
}
if ($currentSession && $currentSession->getId() === $session->getId()) {
$allowAccess = true;
}
$sessionList[] = $session;
$sessionList[$session->getId()] = $session;
}
if ($currentSession && !$allowAccess) {
@ -53,15 +57,15 @@ $template->assign(
);
$template->assign(
'gamification_stars',
GamificationUtils::getTotalUserStars($user->getId(), $user->getStatus())
GamificationUtils::getTotalUserStars($user->getId(), $user->getStatus())
);
$template->assign(
'gamification_points',
GamificationUtils::getTotalUserPoints($user->getId(), $user->getStatus())
GamificationUtils::getTotalUserPoints($user->getId(), $user->getStatus())
);
$template->assign(
'gamification_progress',
GamificationUtils::getTotalUserProgress($user->getId(), $user->getStatus())
GamificationUtils::getTotalUserProgress($user->getId(), $user->getStatus())
);
$template->assign('sessions', $sessionList);
$template->assign('current_session', $currentSession);

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

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

@ -32,6 +32,7 @@ $show_learnpath = true;
api_protect_course_script();
$lp_id = intval($_GET['lp_id']);
$sessionId = api_get_session_id();
// Check if the learning path is visible for student - (LP requisites)
@ -51,7 +52,7 @@ $visibility = api_get_item_visibility(
$lp_id,
$action,
api_get_user_id(),
api_get_session_id()
$sessionId
);
if (!api_is_allowed_to_edit(false, true, false, false) && intval($visibility) == 0) {
api_not_allowed(true);
@ -390,6 +391,12 @@ if (api_get_course_setting('lp_return_link') == 1) {
$buttonHomeText = get_lang('LearningPathList');
}
$lpPreviewImagePath = 'unknown_250_100.jpg';
if ($_SESSION['oLP']->get_preview_image()) {
$lpPreviewImagePath = $_SESSION['oLP']->get_preview_image_path();
}
$template = new Template('title', false, false, true, true, false);
$template->assign('glossary_extra_tools', api_get_setting('show_glossary_in_extra_tools'));
$template->assign(
@ -409,12 +416,33 @@ $template->assign('button_home_url', $buttonHomeUrl);
$template->assign('button_home_text', $buttonHomeText);
$template->assign('navigation_bar', $navigation_bar);
$template->assign('progress_bar', $progress_bar);
$template->assign('oLP', $_SESSION['oLP']);
$template->assign('show_audio_player', $show_audioplayer);
$template->assign('media_player', $mediaplayer);
$template->assign('toc_list', $get_toc_list);
$template->assign('iframe_src', $src);
$template->assign('navigation_bar_bottom', $navigation_bar_bottom);
$template->assign(
'gamification_stars',
$_SESSION['oLP']->getCalculateStars($sessionId)
);
$template->assign(
'gamification_points',
$_SESSION['oLP']->getCalculateScore($sessionId)
);
$template->assign(
'lp_preview_image',
Display::return_icon(
$lpPreviewImagePath,
null,
['height' => 96, 'width' => 104]
)
);
$template->assign('lp_author', $_SESSION['oLP']->get_author());
$template->assign('lp_mode', $_SESSION['oLP']->mode);
$template->assign(
'lp_html_toc',
$_SESSION['oLP']->get_html_toc($get_toc_list)
);
$content = $template->fetch('default/learnpath/view.tpl');

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

@ -13,21 +13,20 @@
{% if gamification_mode == 1 %}
<div class="row">
<div class="col-xs-8">
{% set lp_stars = oLP.getCalculateStars() %}
{% if lp_stars > 0%}
{% for i in 1..lp_stars %}
{% if gamification_stars > 0 %}
{% for i in 1..gamification_stars %}
<i class="fa fa-star fa-2x"></i>
{% endfor %}
{% endif %}
{% if lp_stars < 4 %}
{% for i in 1..4 - lp_stars %}
{% if gamification_stars < 4 %}
{% for i in 1..4 - gamification_stars %}
<i class="fa fa-star-o fa-2x"></i>
{% endfor %}
{% endif %}
</div>
<div class="col-xs-4 text-right">
{{ "XPoints"|get_lang|format(oLP.getCalculateScore()) }}
{{ "XPoints"|get_lang|format(gamification_points) }}
</div>
</div>
{% else %}
@ -44,13 +43,7 @@
<i class="fa fa-home"></i> {{ button_home_text }}
</a>
<div class="image-avatar">
{% if oLP.get_preview_image() %}
<img src="{{ oLP.get_preview_image_path() }}" width="104" height="96">
{% else %}
<img src="{{ "unknown_250_100.jpg"|icon }}" width="104" height="96">
{% endif %}
</div>
<div class="image-avatar">{{ lp_preview_image }}</div>
<div id="lp_navigation_elem" class="navegation-bar">
{{ navigation_bar }}
@ -60,9 +53,7 @@
</div>
</div>
<div class="description-autor">
{{ oLP.get_author() }}
</div>
<div class="description-autor">{{ lp_author }}</div>
{% if show_audio_player %}
<div id="lp_media_file">
@ -75,9 +66,7 @@
{# TOC layout #}
<div id="toc_id" name="toc_name">
<div id="learning_path_toc" class="scorm-list">
{{ oLP.get_html_toc(toc_list) }}
</div>
<div id="learning_path_toc" class="scorm-list">{{ lp_html_toc }}</div>
</div>
{# end TOC layout #}
@ -88,7 +77,7 @@
{# right zone #}
<div id="learning_path_right_zone" style="height:100%" class="content-scorm">
{% if oLP.mode == 'fullscreen' %}
{% if lp_mode == 'fullscreen' %}
<iframe id="content_id_blank" name="content_name_blank" src="blank.php" border="0" frameborder="0" style="width: 100%; height: 100%" allowfullscreen="true" webkitallowfullscreen="true" mozallowfullscreen="true"></iframe>
{% else %}
<iframe id="content_id" name="content_name" src="{{ iframe_src }}" border="0" frameborder="0" style="display: block; width: 100%; height: 100%" allowfullscreen="true" webkitallowfullscreen="true" mozallowfullscreen="true"></iframe>

Loading…
Cancel
Save