Update gamification values on LP

1.10.x
Angel Fernando Quiroz Campos 10 years ago
parent 3af13467f7
commit 2164a489b7
  1. 18
      main/inc/ajax/lp.ajax.php
  2. 2
      main/newscorm/learnpath.class.php
  3. 1
      main/newscorm/lp_ajax_switch_item.php
  4. 20
      main/newscorm/scorm_api.php

@ -11,6 +11,7 @@ $action = $_REQUEST['a'];
$course_id = api_get_course_int_id();
$tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
$sessionId = api_get_session_id();
switch ($action) {
case 'get_documents';
@ -170,6 +171,23 @@ switch ($action) {
}
}
break;
case 'update_gamification':
$lp = isset($_SESSION['oLP']) ? $_SESSION['oLP'] : null;
$jsonGamification = [
'stars' => 0,
'score' => 0
];
if ($lp) {
$score = $lp->getCalculateScore($sessionId);
$jsonGamification['stars'] = $lp->getCalculateStars($sessionId);
$jsonGamification['score'] = sprintf(get_lang('XPoints'), $score);
}
echo json_encode($jsonGamification);
break;
default:
echo '';

@ -10178,7 +10178,7 @@ EOD;
$progress = self::getProgress($this->lp_id, $this->user_id, $this->course_int_id, $sessionId);
if ($progress > 50) {
if ($progress >= 50) {
$stars++;
}

@ -214,6 +214,7 @@ function switch_item_details($lp_id, $user_id, $view_id, $current_item, $next_it
"update_toc('highlight','".$new_item_id."');".
"update_toc('$mylesson_status','".$new_item_id."');".
"update_progress_bar('$mycomplete','$mytotal','$myprogress_mode');";
$return .= 'updateGamificationValues(); ';
$mylp->set_error_msg('');
$mylp->prerequisites_match(); // Check the prerequisites are all complete.

@ -1360,6 +1360,26 @@ function update_progress_bar(nbr_complete, nbr_total, mode) {
return true;
}
/**
* Update the gamification values (number of stars and score)
*/
function updateGamificationValues() {
var fetchValues = $.ajax('<?php echo api_get_path(WEB_AJAX_PATH) ?>lp.ajax.php', {
dataType: 'json',
data: {
a: 'update_gamification'
}
});
$.when(fetchValues).done(function (values) {
if (values.stars > 0) {
$('#scorm-gamification .fa-star:nth-child(' + values.stars + ')').addClass('level');
}
$('#scorm-gamification .col-xs-4').text(values.score);
});
}
/**
* Analyses the variables that have been modified through this SCO's life and
* put them into an array for later shipping to lp_ajax_save_item.php

Loading…
Cancel
Save