/**
  * Get the correct answers in all attempts
  * @param int $learnPathId
  * @param int $learnPathItemId
  * @return array
  */
 public function getCorrectAnswersInAllAttempts($learnPathId = 0, $learnPathItemId = 0)
 {
     $attempts = Event::getExerciseResultsByUser(api_get_user_id(), $this->id, api_get_course_int_id(), api_get_session_id(), $learnPathId, $learnPathItemId, 'asc');
     $corrects = [];
     foreach ($attempts as $attempt) {
         foreach ($attempt['question_list'] as $answer) {
             $objAnswer = new Answer($answer['question_id']);
             $isCorrect = $objAnswer->isCorrectByAutoId($answer['answer']);
             if ($isCorrect) {
                 $corrects[$answer['question_id']][] = $answer;
             }
         }
     }
     return $corrects;
 }
 /**
  * Calculate the total points achieved for the current user in this learning path
  * @param int $sessionId Optional. The session Id
  * @return int
  */
 public function getCalculateScore($sessionId = 0)
 {
     // Calculate stars chapters evaluation
     $exercisesItems = $this->getExercisesItems();
     $finalEvaluationItem = $this->getFinalEvaluationItem();
     $totalExercisesResult = 0;
     $totalEvaluationResult = 0;
     if ($exercisesItems !== false) {
         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;
             foreach ($exerciseResultInfo as $result) {
                 $exerciseResult += $result['exe_result'];
             }
             $totalExercisesResult += $exerciseResult;
         }
     }
     if (!empty($finalEvaluationItem)) {
         $evaluationResultInfo = Event::getExerciseResultsByUser($this->user_id, $finalEvaluationItem->path, $this->course_int_id, $sessionId, $this->lp_id, $finalEvaluationItem->db_id);
         foreach ($evaluationResultInfo as $result) {
             $totalEvaluationResult += $result['exe_result'];
         }
     }
     return $totalExercisesResult + $totalEvaluationResult;
 }
Example #3
0
$_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
                $exercise_stat_info = Event::getExerciseResultsByUser($user_id, $exerciseId, api_get_course_id(), api_get_session_id());
                if (!empty($exercise_stat_info)) {
                    $max_exe_id = max(array_keys($exercise_stat_info));
                    $last_attempt_info = $exercise_stat_info[$max_exe_id];
                    $attempt_html .= Display::div(get_lang('Date') . ': ' . api_get_local_time($last_attempt_info['exe_date']), array('id' => ''));
                    $attempt_html .= Display::return_message(sprintf(get_lang('ReachedMaxAttempts'), $exercise_title, $objExercise->selectAttempts()), 'warning', false);
                    if (!empty($last_attempt_info['question_list'])) {
                        foreach ($last_attempt_info['question_list'] as $question_data) {
                            $question_id = $question_data['question_id'];
                            $marks = $question_data['marks'];
                            $question_info = Question::read($question_id);
                            $attempt_html .= Display::div($question_info->question, array('class' => 'question_title'));
                            $attempt_html .= Display::div(get_lang('Score') . ' ' . $marks, array('id' => 'question_question_titlescore'));
                        }
                    }
                    $score = ExerciseLib::show_score($last_attempt_info['exe_result'], $last_attempt_info['exe_weighting']);
Example #4
0
// 2. Exercise button
// Notice we not add there the lp_item_view_id because is not already generated
$exercise_url = api_get_path(WEB_CODE_PATH) . 'exercice/exercise_submit.php?' . api_get_cidreq() . '&exerciseId=' . $objExercise->id . '&origin=' . $origin . '&learnpath_id=' . $learnpath_id . '&learnpath_item_id=' . $learnpath_item_id . $extra_params;
$exercise_url_button = Display::url($label, $exercise_url, array('class' => 'btn btn-success btn-large'));
//3. Checking visibility of the exercise (overwrites the exercise button)
$visible_return = $objExercise->is_visible($learnpath_id, $learnpath_item_id, null, false);
// Exercise is not visible remove the button
if ($visible_return['value'] == false) {
    if ($is_allowed_to_edit) {
        $message = Display::return_message(get_lang('ThisItemIsInvisibleForStudentsButYouHaveAccessAsTeacher'), 'warning');
    } else {
        $message = $visible_return['message'];
        $exercise_url_button = null;
    }
}
$attempts = Event::getExerciseResultsByUser(api_get_user_id(), $objExercise->id, api_get_course_int_id(), api_get_session_id(), $learnpath_id, $learnpath_item_id, 'desc');
$counter = count($attempts);
$my_attempt_array = array();
$table_content = '';
/* Make a special case for IE, which doesn't seem to be able to handle the
 * results popup -> send it to the full results page */
$browser = new Browser();
$current_browser = $browser->getBrowser();
$url_suffix = '';
$btn_class = ' ';
if ($current_browser == 'Internet Explorer') {
    $url_suffix = '&show_headers=1';
    $btn_class = '';
}
if (!empty($attempts)) {
    $i = $counter;