Fixing exercise duration see BT#4488

skala
Julio Montoya 13 years ago
parent 8680ced54e
commit 2c8c681d2d
  1. 2
      main/exercice/exercise.class.php
  2. 18
      main/exercice/exercise_result.php
  3. 18
      main/exercice/exercise_submit.php
  4. 31
      main/inc/ajax/exercise.ajax.php
  5. 26
      main/inc/lib/events.lib.inc.php

@ -19,7 +19,7 @@ define('EXERCISE_FEEDBACK_TYPE_EXAM', 2); //NoFeedback - Show score only
define('EXERCISE_MAX_NAME_SIZE', 80);
$debug = true; //All exercise scripts should depend in this debug variable
$debug = false; //All exercise scripts should depend in this debug variable
require_once dirname(__FILE__).'/../inc/lib/exercise_show_functions.lib.php';

@ -210,24 +210,8 @@ if ($origin != 'learnpath') {
// Tracking of results
// Updates the empty exercise
$quiz_duration = 0;
$end_date = api_get_utc_datetime();
if (isset($_SESSION['quizStartTime']) && !empty($_SESSION['quizStartTime'])) {
if (isset($_SESSION['quizStartTime'][$objExercise->selectId()])) {
$start_date = $_SESSION['quizStartTime'][$objExercise->selectId()];
$end_date_datetime = new DateTime($end_date);
$start_date_date_time = new DateTime($start_date);
$interval = $end_date_datetime->diff($start_date_date_time);
$hours = $interval->format('%h');
$minutes = $interval->format('%i');
$quiz_duration = $hours * 60 + $minutes;
}
}
if (api_is_allowed_to_session_edit()) {
update_event_exercice($exercise_stat_info['exe_id'], $objExercise->selectId(), $total_score, $total_weight, api_get_session_id(), $safe_lp_id, $safe_lp_item_id, $safe_lp_item_view_id, $quiz_duration, $question_list, '', array(), $end_date);
update_event_exercice($exercise_stat_info['exe_id'], $objExercise->selectId(), $total_score, $total_weight, api_get_session_id(), $safe_lp_id, $safe_lp_item_id, $safe_lp_item_view_id, $exercise_stat_info['exe_duration'], $question_list, '', array(), $end_date);
}
//If is not valid

@ -34,8 +34,6 @@ require_once 'exercise.class.php';
require_once 'question.class.php';
require_once 'answer.class.php';
$debug = 1; //debug value is set in the exercise.class.php file
// name of the language file that needs to be included
$language_file = 'exercice';
@ -145,7 +143,6 @@ if ($objExercise->review_answers) {
}
}
$current_timestamp = time();
$my_remind_list = array();
@ -154,12 +151,14 @@ if ($objExercise->expired_time != 0 && $origin != 'learnpath') {
$time_control = true;
}
//Generating the time control key for the user
$current_expired_time_key = generate_time_control_key($objExercise->id);
$_SESSION['duration_time'][$current_expired_time_key] = $current_timestamp;
if ($time_control) {
//Get the expired time of the current exercice in track_e_exercices
$total_seconds = $objExercise->expired_time*60;
//Generating the time control key for the user
$current_expired_time_key = generate_time_control_key($objExercise->id);
}
$show_clock = true;
@ -220,8 +219,6 @@ if ($objExercise->selectAttempts() > 0) {
}
}
if ($debug) { error_log("4. Setting the exe_id: $exe_id");} ;
//5. Getting user exercise info (if the user took the exam before) - generating exe_id
@ -369,9 +366,6 @@ if (!isset($_SESSION['questionList'])) {
if ($debug) error_log('8. Question list loaded '.print_r($questionList, 1));
$quizStartTime = array( $exerciseId => api_get_utc_datetime());
Session::write('quizStartTime', $quizStartTime);
//Real question count
$question_count = 0;
if (!empty($questionList)) {
@ -436,7 +430,7 @@ if ($formSent && isset($_POST)) {
// the script "exercise_result.php" will take the variable $exerciseResult from the session
Session::write('exerciseResult',$exerciseResult);
Session::write('remind_list',$remind_list);
Session::write('remind_list', $remind_list);
Session::write('exerciseResultCoordinates',$exerciseResultCoordinates);
// if all questions on one page OR if it is the last question (only for an exercise with one question per page)

@ -180,7 +180,9 @@ switch ($action) {
}
//Getting information of the current exercise
$exercise_stat_info = $objExercise->get_stat_track_exercise_info_by_exe_id($exe_id);
$exercise_stat_info = $objExercise->get_stat_track_exercise_info_by_exe_id($exe_id);
$exercise_id = $exercise_stat_info['exe_exo_id'];
$attempt_list = array();
@ -250,7 +252,7 @@ switch ($action) {
}
}
unset($objQuestionTmp);
unset($objQuestionTmp);
//Looping the question list
@ -309,7 +311,30 @@ switch ($action) {
if ($debug) error_log("total_score: $total_score ");
if ($debug) error_log("total_weight: $total_weight ");
update_event_exercice($exe_id, $objExercise->selectId(), $total_score, $total_weight, api_get_session_id(), $exercise_stat_info['orig_lp_id'], $exercise_stat_info['orig_lp_item_id'], $exercise_stat_info['orig_lp_item_view_id'], $exercise_stat_info['exe_duration'], $question_list, 'incomplete', $remind_list);
$key = get_time_control_key($exercise_id);
$duration = 0;
$now = time();
if (isset($_SESSION['duration_time'][$key]) && !empty($_SESSION['duration_time'][$key])) {
$duration = $now - $_SESSION['duration_time'][$key];
if (!empty($exercise_stat_info['exe_duration'])) {
$duration += $exercise_stat_info['exe_duration']*60;
}
$duration = intval(round($duration/60));
$_SESSION['duration_time'][$key] = 0;
} else {
if (!empty($exercise_stat_info['exe_duration'])) {
$duration = $exercise_stat_info['exe_duration'];
}
if ($type == 'all') {
$exercise_stat_info = $objExercise->get_stat_track_exercise_info_by_exe_id($exe_id);
$duration = $exercise_stat_info['exe_duration'];
}
}
update_event_exercice($exe_id, $objExercise->selectId(), $total_score, $total_weight, api_get_session_id(), $exercise_stat_info['orig_lp_id'], $exercise_stat_info['orig_lp_item_id'], $exercise_stat_info['orig_lp_item_view_id'], $duration, $question_list, 'incomplete', $remind_list);
// Destruction of the Question object
unset($objQuestionTmp);

@ -307,20 +307,24 @@ function event_link($link_id) {
/**
* Update the TRACK_E_EXERCICES exercises
*
* @param int exeid id of the attempt
* @param int exo_id exercise id
* @param mixed result score
* @param int weighting ( higher score )
* @param int duration ( duration of the attempt, in seconds )
* @param int session_id
* @param int learnpath_id (id of the learnpath)
* @param int learnpath_item_id (id of the learnpath_item)
* @param int exeid id of the attempt
* @param int exo_id exercise id
* @param mixed result score
* @param int weighting ( higher score )
* @param int duration ( duration of the attempt, in seconds )
* @param int session_id
* @param int learnpath_id (id of the learnpath)
* @param int learnpath_item_id (id of the learnpath_item)
*
* @author Sebastien Piraux <piraux_seb@hotmail.com>
* @author Julio Montoya Armas <gugli100@gmail.com> Reworked 2010
* @desc Record result of user when an exercice was done
*/
function update_event_exercice($exeid, $exo_id, $score, $weighting,$session_id,$learnpath_id=0, $learnpath_item_id=0, $learnpath_item_view_id = 0, $duration, $question_list, $status = '', $remind_list = array() , $end_date = null) {
function update_event_exercice($exeid, $exo_id, $score, $weighting, $session_id, $learnpath_id = 0, $learnpath_item_id = 0, $learnpath_item_view_id = 0, $duration = 0, $question_list = array(), $status = '', $remind_list = array() , $end_date = null) {
error_log('Called to update_event_exercice');
error_log('duration:' . $duration);
require_once api_get_path(SYS_CODE_PATH).'exercice/exercise.lib.php';
if ($exeid != '') {
// Validation in case of fraud with actived control time
@ -346,7 +350,9 @@ function update_event_exercice($exeid, $exo_id, $score, $weighting,$session_id,$
}
$TABLETRACK_EXERCICES = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
$question_list = array_map('intval', $question_list);
if (!empty($question_list)) {
$question_list = array_map('intval', $question_list);
}
if (!empty($remind_list)) {
$remind_list = array_map('intval', $remind_list);

Loading…
Cancel
Save