$previousTotalTimeTab[1] += $spentTime; $previousTotalTimeTab[0] += (int) ($previousTotalTimeTab[1] / 60); $previousTotalTimeTab[1] %= 60; $newTotalTime = ''; if ($previousTotalTimeTab[0] > 9999) { $newTotalTime = '9999:59:59'; } else { if ($previousTotalTimeTab[0] < 10) { $newTotalTime .= 0; } $newTotalTime .= $previousTotalTimeTab[0] . ':'; if ($previousTotalTimeTab[1] < 10) { $newTotalTime .= 0; } $newTotalTime .= $previousTotalTimeTab[1] . ':' . $previousTotalTimeTab[2]; } $tblUserModuleProgress = get_module_course_tbl(array('lp_user_module_progress'), $courseCode); Claroline::getDatabase()->exec("UPDATE `{$tblUserModuleProgress['lp_user_module_progress']}`\n SET total_time = " . Claroline::getDatabase()->quote($newTotalTime) . ",\n session_time = " . Claroline::getDatabase()->quote($sessionTime) . "\n WHERE user_module_progress_id = " . Claroline::getDatabase()->escape((int) $userModuleProgressId)); $documentTimeUpdateArgs = array('sessionTime' => $sessionTime, 'date' => $date, 'userId' => $userId, 'courseCode' => $courseCode, 'learnPathId' => $learnPathId, 'moduleId' => $moduleId); $documentTimeUpdateEvent = new Event('lp_document_time_update', $documentTimeUpdateArgs); EventManager::notify($documentTimeUpdateEvent); echo 'Document spent time updated'; } else { echo 'Wrong userId or wrong courseCode'; } } else { echo 'There is at least one null param'; } } else { echo 'User not authenticated'; }
function set_learning_path_progression($totalResult, $totalGrade, $timeToCompleteExe, $_uid) { $tbl_cdb_names = get_module_course_tbl(array('lp_rel_learnPath_module', 'lp_user_module_progress'), claro_get_current_course_id()); $tbl_lp_rel_learnPath_module = $tbl_cdb_names['lp_rel_learnPath_module']; $tbl_lp_user_module_progress = $tbl_cdb_names['lp_user_module_progress']; // update raw in DB to keep the best one, so update only if new raw is better AND if user NOT anonymous if ($_uid) { // exercices can have a negative score, but we don't accept that in LP // so if totalScore is negative use 0 as result $totalResult = max($totalResult, 0); if ($totalGrade != 0) { $newRaw = @round($totalResult / $totalGrade * 100); } else { $newRaw = 0; } $scoreMin = 0; $scoreMax = $totalGrade; $scormSessionTime = seconds_to_scorm_time($timeToCompleteExe); // need learningPath_module_id and raw_to_pass value $sql = "SELECT LPM.`raw_to_pass`, LPM.`learnPath_module_id`, UMP.`total_time`, UMP.`raw`\n FROM `" . $tbl_lp_rel_learnPath_module . "` AS LPM, `" . $tbl_lp_user_module_progress . "` AS UMP\n WHERE LPM.`learnPath_id` = '" . (int) $_SESSION['path_id'] . "'\n AND LPM.`module_id` = '" . (int) $_SESSION['module_id'] . "'\n AND LPM.`learnPath_module_id` = UMP.`learnPath_module_id`\n AND UMP.`user_id` = " . (int) $_uid; $lastProgression = claro_sql_query_get_single_row($sql); if ($lastProgression) { // build sql query $sql = "UPDATE `" . $tbl_lp_user_module_progress . "` SET "; // if recorded score is more than the new score => update raw, credit and status if ($lastProgression['raw'] < $totalResult) { // update raw $sql .= "`raw` = " . $totalResult . ","; // update credit and statut if needed ( score is better than raw_to_pass ) if ($newRaw >= $lastProgression['raw_to_pass']) { $sql .= " `credit` = 'CREDIT',\n `lesson_status` = 'PASSED',"; } else { $sql .= " `credit` = 'NO-CREDIT',\n `lesson_status` = 'FAILED',"; } } // else don't change raw, credit and lesson_status // default query statements $sql .= " `scoreMin` = " . (int) $scoreMin . ",\n `scoreMax` = " . (int) $scoreMax . ",\n `total_time` = '" . addScormTime($lastProgression['total_time'], $scormSessionTime) . "',\n `session_time` = '" . $scormSessionTime . "'\n WHERE `learnPath_module_id` = " . (int) $lastProgression['learnPath_module_id'] . "\n AND `user_id` = " . (int) $_uid . ""; // Generate an event to notify that the exercise has been completed $learnPathEventArgs = array('userId' => (int) $_uid, 'courseCode' => claro_get_current_course_id(), 'scoreRaw' => (int) $totalResult, 'scoreMin' => (int) $scoreMin, 'scoreMax' => (int) $scoreMax, 'sessionTime' => $scormSessionTime, 'learnPathModuleId' => (int) $lastProgression['learnPath_module_id'], 'type' => "update"); if ($newRaw >= $lastProgression['raw_to_pass']) { $learnPathEventArgs['status'] = "PASSED"; } else { $learnPathEventArgs['status'] = "FAILED"; } $learnPathEvent = new Event('lp_user_module_progress_modified', $learnPathEventArgs); EventManager::notify($learnPathEvent); return claro_sql_query($sql); } else { return false; } } }
if ($lesson_status_value == "COMPLETED" || $lesson_status_value == "PASSED") { if (strtoupper($_POST['credit']) == "CREDIT") { $credit_value = "CREDIT"; } } if (isScormTime($_POST['session_time'])) { $total_time_value = addScormTime($_POST['total_time'], $_POST['session_time']); } else { $total_time_value = $_POST['total_time']; } $sql = "UPDATE `" . $TABLEUSERMODULEPROGRESS . "` \n SET \n `lesson_location` = '" . claro_sql_escape($_POST['lesson_location']) . "',\n `lesson_status` = '" . claro_sql_escape($lesson_status_value) . "',\n `entry` = '" . claro_sql_escape($entry_value) . "',\n `raw` = '" . (int) $_POST['raw'] . "',\n `scoreMin` = '" . (int) $_POST['scoreMin'] . "',\n `scoreMax` = '" . (int) $_POST['scoreMax'] . "',\n `total_time` = '" . claro_sql_escape($total_time_value) . "',\n `session_time` = '" . claro_sql_escape($_POST['session_time']) . "',\n `suspend_data` = '" . claro_sql_escape($_POST['suspend_data']) . "',\n `credit` = '" . claro_sql_escape($credit_value) . "'\n WHERE `user_module_progress_id` = " . (int) $_POST['ump_id']; claro_sql_query($sql); // Generate an event to notify that the module tracking has been updated $learnPathEventArgs = array('userId' => (int) claro_get_current_user_id(), 'courseCode' => claro_get_current_course_id(), 'scoreRaw' => (int) $_POST['raw'], 'scoreMin' => (int) $_POST['scoreMin'], 'scoreMax' => (int) $_POST['scoreMax'], 'sessionTime' => claro_sql_escape($_POST['session_time']), 'userModuleProgressId' => (int) $_POST['ump_id'], 'type' => "update", 'status' => claro_sql_escape($lesson_status_value)); $learnPathEvent = new Event('lp_user_module_progress_modified', $learnPathEventArgs); EventManager::notify($learnPathEvent); } // display the form to accept new commit and // refresh TOC frame, has to be done here to show recorded progression as soon as it is recorded ?> <!-- API form --> <html> <head> <title>update progression</title> <?php if ($_POST['ump_id']) { ?> <script type="text/javascript"> <!--// parent.tocFrame.location.href="<?php
/** * notify the event manager for an event occurence * @access public * @param Event event the event that occurs; an instance of the event class */ public function sendEvent($event) { EventManager::notify($event); }