/**
  * Validates the time control key
  */
 public static function exercise_time_control_is_valid($exercise_id, $lp_id = 0, $lp_item_id = 0)
 {
     $course_id = api_get_course_int_id();
     $exercise_id = intval($exercise_id);
     $TBL_EXERCICES = Database::get_course_table(TABLE_QUIZ_TEST);
     $sql = "SELECT expired_time FROM {$TBL_EXERCICES} WHERE c_id = {$course_id} AND iid = {$exercise_id}";
     $result = Database::query($sql);
     $row = Database::fetch_array($result, 'ASSOC');
     if (!empty($row['expired_time'])) {
         $current_expired_time_key = ExerciseLib::get_time_control_key($exercise_id, $lp_id, $lp_item_id);
         if (isset($_SESSION['expired_time'][$current_expired_time_key])) {
             $current_time = time();
             $expired_time = api_strtotime($_SESSION['expired_time'][$current_expired_time_key], 'UTC');
             $total_time_allowed = $expired_time + 30;
             //error_log('expired time converted + 30: '.$total_time_allowed);
             //error_log('$current_time: '.$current_time);
             if ($total_time_allowed < $current_time) {
                 return false;
             }
             return true;
         } else {
             return false;
         }
     } else {
         return true;
     }
 }
示例#2
0
     }
 }
 // We're inside *one* question. Go through each possible answer for this question
 $result = $objExercise->manageAnswers($exe_id, $my_question_id, $my_choice, 'exercise_result', $hot_spot_coordinates, true, false, false, $hotspot_delineation_result);
 //Adding the new score
 $total_score += $result['score'];
 if ($debug) {
     error_log("total_score: {$total_score} ");
     error_log("total_weight: {$total_weight} ");
 }
 $duration = 0;
 $now = time();
 if ($type == 'all') {
     $exercise_stat_info = $objExercise->getStatTrackExerciseInfoByExeId($exe_id);
 }
 $key = ExerciseLib::get_time_control_key($exercise_id, $exercise_stat_info['orig_lp_id'], $exercise_stat_info['orig_lp_item_id']);
 /*$durationTime = array(
       'duration_time' => array(
           $key => time()
       )
   );*/
 $durationTime = Session::read('duration_time');
 if (isset($durationTime[$key]) && !empty($durationTime[$key])) {
     $duration = $now - $durationTime[$key];
     if (!empty($exercise_stat_info['exe_duration'])) {
         $duration += $exercise_stat_info['exe_duration'];
     }
     $duration = intval($duration);
 } else {
     if (!empty($exercise_stat_info['exe_duration'])) {
         $duration = $exercise_stat_info['exe_duration'];
示例#3
0
}
// If reminder ends we jump to the exercise_reminder
if ($objExercise->review_answers) {
    if ($remind_question_id == -1) {
        header('Location: exercise_reminder.php?origin=' . $origin . '&exerciseId=' . $exerciseId);
        exit;
    }
}
$current_timestamp = time();
$my_remind_list = array();
$time_control = false;
if ($objExercise->expired_time != 0) {
    $time_control = true;
}
// Generating the time control key for the user
$current_expired_time_key = ExerciseLib::get_time_control_key($objExercise->id, $learnpath_id, $learnpath_item_id);
$_SESSION['duration_time'][$current_expired_time_key] = $current_timestamp;
if ($time_control) {
    // Get the expired time of the current exercise in track_e_exercises
    $total_seconds = $objExercise->expired_time * 60;
}
$show_clock = true;
$user_id = api_get_user_id();
if ($objExercise->selectAttempts() > 0) {
    $attempt_html = '';
    $attempt_count = Event::get_attempt_count($user_id, $exerciseId, $learnpath_id, $learnpath_item_id, $learnpath_item_view_id);
    if ($attempt_count >= $objExercise->selectAttempts()) {
        $show_clock = false;
        if (!api_is_allowed_to_edit(null, true)) {
            if ($objExercise->results_disabled == 0 && $origin != 'learnpath') {
                // Showing latest attempt according with task BT#1628
示例#4
0
 /**
  * This function creates an empty Exercise in STATISTIC_TRACK_E_EXERCICES table.
  * After that in exercise_result.php we call the update_event_exercise() to update the exercise
  * @return int $id the last id registered, or false on error
  * @author Julio Montoya <*****@*****.**>
  * @desc Record result of user when an exercice was done
  * @deprecated this function seems to be deprecated
  */
 function createEventExercise($exo_id)
 {
     if (empty($exo_id) or intval($exo_id) != $exo_id) {
         return false;
     }
     $tbl_track_exe = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
     $tbl_exe = Database::get_course_table(TABLE_QUIZ_TEST);
     $uid = api_get_user_id();
     $course_id = api_get_course_int_id();
     // First, check the exercise exists
     $sql_exe_id = "SELECT exercises.id FROM {$tbl_exe} as exercises WHERE c_id = {$course_id} AND exercises.id={$exo_id}";
     $res_exe_id = Database::query($sql_exe_id);
     if ($res_exe_id === false) {
         return false;
     }
     //sql error
     if (Database::num_rows($res_exe_id) < 1) {
         return false;
     }
     //exe not found
     $row_exe_id = Database::fetch_row($res_exe_id);
     $exercise_id = intval($row_exe_id[0]);
     // Second, check if the record exists in the database (looking for incomplete records)
     $sql = "SELECT exe_id FROM {$tbl_track_exe}\n            WHERE exe_exo_id =   {$exo_id} AND\n            exe_user_id =  {$uid} AND c_id = '" . $course_id . "' AND " . "status = 'incomplete' AND " . "session_id = " . api_get_session_id();
     $res = Database::query($sql);
     if ($res === false) {
         return false;
     }
     if (Database::num_rows($res) > 0) {
         $row = Database::fetch_array($res);
         return $row['exe_id'];
     }
     // No record was found, so create one
     // get expire time to insert into the tracking record
     $current_expired_time_key = ExerciseLib::get_time_control_key($exercise_id);
     if (isset($_SESSION['expired_time'][$current_expired_time_key])) {
         //Only for exercice of type "One page"
         $expired_date = $_SESSION['expired_time'][$current_expired_time_key];
     } else {
         $expired_date = '0000-00-00 00:00:00';
     }
     $sql = "INSERT INTO {$tbl_track_exe} (exe_user_id, c_id, expired_time_control, exe_exo_id, session_id)\n                VALUES ({$uid},  '" . $course_id . "' ,'{$expired_date}','{$exo_id}','" . api_get_session_id() . "')";
     Database::query($sql);
     $id = Database::insert_id();
     return $id;
 }