Esempio n. 1
0
/**
 * Display the exercise results
 * @param Exercise $objExercise
 * @param int $exe_id
 * @param bool $save_user_result save users results (true) or just show the results (false)
 */
function display_question_list_by_attempt($objExercise, $exe_id, $save_user_result = false)
{
    global $origin;
    // Getting attempt info
    $exercise_stat_info = $objExercise->get_stat_track_exercise_info_by_exe_id($exe_id);
    // Getting question list
    $question_list = array();
    if (!empty($exercise_stat_info['data_tracking'])) {
        $question_list = explode(',', $exercise_stat_info['data_tracking']);
    } else {
        // Try getting the question list only if save result is off
        if ($save_user_result == false) {
            $question_list = $objExercise->get_validated_question_list();
        }
    }
    $counter = 1;
    $total_score = $total_weight = 0;
    $exercise_content = null;
    // Hide results
    $show_results = false;
    $show_only_score = false;
    if ($objExercise->results_disabled == RESULT_DISABLE_SHOW_SCORE_AND_EXPECTED_ANSWERS) {
        $show_results = true;
    }
    if (in_array($objExercise->results_disabled, array(RESULT_DISABLE_SHOW_SCORE_ONLY, RESULT_DISABLE_SHOW_FINAL_SCORE_ONLY_WITH_CATEGORIES))) {
        $show_only_score = true;
    }
    // Not display expected answer, but score, and feedback
    $show_all_but_expected_answer = false;
    if ($objExercise->results_disabled == RESULT_DISABLE_SHOW_SCORE_ONLY && $objExercise->feedback_type == EXERCISE_FEEDBACK_TYPE_END) {
        $show_all_but_expected_answer = true;
        $show_results = true;
        $show_only_score = false;
    }
    if ($show_results || $show_only_score) {
        $user_info = api_get_user_info($exercise_stat_info['exe_user_id']);
        //Shows exercise header
        echo $objExercise->show_exercise_result_header($user_info, api_convert_and_format_date($exercise_stat_info['start_date'], DATE_TIME_FORMAT_LONG), $exercise_stat_info['duration']);
    }
    // Display text when test is finished #4074 and for LP #4227
    $end_of_message = $objExercise->selectTextWhenFinished();
    if (!empty($end_of_message)) {
        Display::display_normal_message($end_of_message, false);
        echo "<div class='clear'>&nbsp;</div>";
    }
    $question_list_answers = array();
    $media_list = array();
    $category_list = array();
    // Loop over all question to show results for each of them, one by one
    if (!empty($question_list)) {
        foreach ($question_list as $questionId) {
            // creates a temporary Question object
            $objQuestionTmp = Question::read($questionId);
            // This variable came from exercise_submit_modal.php
            ob_start();
            // We're inside *one* question. Go through each possible answer for this question
            $result = $objExercise->manage_answer($exercise_stat_info['exe_id'], $questionId, null, 'exercise_result', array(), $save_user_result, true, $show_results, $objExercise->selectPropagateNeg(), array());
            if (empty($result)) {
                continue;
            }
            // In case of global score, make sure the calculated total score is integer
            /*if (!is_int($result['score'])) {
                  $result['score'] = round($result['score']);
              }*/
            $total_score += $result['score'];
            $total_weight += $result['weight'];
            $question_list_answers[] = array('question' => $result['open_question'], 'answer' => $result['open_answer'], 'answer_type' => $result['answer_type']);
            $my_total_score = $result['score'];
            $my_total_weight = $result['weight'];
            // Category report
            $category_was_added_for_this_test = false;
            if (isset($objQuestionTmp->category) && !empty($objQuestionTmp->category)) {
                $category_list[$objQuestionTmp->category]['score'] += $my_total_score;
                $category_list[$objQuestionTmp->category]['total'] += $my_total_weight;
                $category_was_added_for_this_test = true;
            }
            if (isset($objQuestionTmp->category_list) && !empty($objQuestionTmp->category_list)) {
                foreach ($objQuestionTmp->category_list as $category_id) {
                    $category_list[$category_id]['score'] += $my_total_score;
                    $category_list[$category_id]['total'] += $my_total_weight;
                    $category_was_added_for_this_test = true;
                }
            }
            // No category for this question!
            if ($category_was_added_for_this_test == false) {
                if (!isset($category_list['none']['score'])) {
                    $category_list['none']['score'] = 0;
                }
                if (!isset($category_list['none']['total'])) {
                    $category_list['none']['total'] = 0;
                }
                $category_list['none']['score'] += $my_total_score;
                $category_list['none']['total'] += $my_total_weight;
            }
            if ($objExercise->selectPropagateNeg() == 0 && $my_total_score < 0) {
                $my_total_score = 0;
            }
            $comnt = null;
            if ($show_results) {
                $comnt = get_comments($exe_id, $questionId);
                if (!empty($comnt)) {
                    echo '<b>' . get_lang('Feedback') . '</b>';
                    echo '<div id="question_feedback">' . $comnt . '</div>';
                }
            }
            if ($show_results) {
                $score = array('result' => get_lang('Score') . " : " . show_score($my_total_score, $my_total_weight, false, true), 'pass' => $my_total_score >= $my_total_weight ? true : false, 'score' => $my_total_score, 'weight' => $my_total_weight, 'comments' => $comnt);
            } else {
                $score = array();
            }
            $contents = ob_get_clean();
            $question_content = '<div class="question_row">';
            if ($show_results) {
                $show_media = false;
                /*if ($objQuestionTmp->parent_id != 0 && !in_array($objQuestionTmp->parent_id, $media_list)) {
                      $show_media = true;
                      $media_list[] = $objQuestionTmp->parent_id;
                  }*/
                //Shows question title an description
                $question_content .= $objQuestionTmp->return_header(null, $counter, $score);
            }
            $counter++;
            $question_content .= $contents;
            $question_content .= '</div>';
            $exercise_content .= $question_content;
        }
        // end foreach() block that loops over all questions
    }
    $total_score_text = null;
    if ($origin != 'learnpath') {
        if ($show_results || $show_only_score) {
            $total_score_text .= '<div class="question_row">';
            $total_score_text .= get_question_ribbon($objExercise, $total_score, $total_weight, true);
            $total_score_text .= '</div>';
        }
    }
    if (!empty($category_list) && ($show_results || $show_only_score)) {
        //Adding total
        $category_list['total'] = array('score' => $total_score, 'total' => $total_weight);
        echo Testcategory::get_stats_table_by_attempt($objExercise->id, $category_list);
    }
    if ($show_all_but_expected_answer) {
        $exercise_content .= "<div class='normal-message'>" . get_lang("ExerciseWithFeedbackWithoutCorrectionComment") . "</div>";
    }
    // Remove audio auto play from questions on results page - refs BT#7939
    $exercise_content = preg_replace('/autoplay[\\=\\".+\\"]+/', '', $exercise_content);
    echo $total_score_text;
    echo $exercise_content;
    if (!$show_only_score) {
        echo $total_score_text;
    }
    if ($save_user_result) {
        // Tracking of results
        $learnpath_id = $exercise_stat_info['orig_lp_id'];
        $learnpath_item_id = $exercise_stat_info['orig_lp_item_id'];
        $learnpath_item_view_id = $exercise_stat_info['orig_lp_item_view_id'];
        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(), $learnpath_id, $learnpath_item_id, $learnpath_item_view_id, $exercise_stat_info['exe_duration'], $question_list, '', array());
        }
        // Send notification ..
        if (!api_is_allowed_to_edit(null, true)) {
            if (api_get_course_setting('email_alert_manager_on_new_quiz') == 1) {
                $objExercise->send_mail_notification_for_exam($question_list_answers, $origin, $exe_id);
            }
            $objExercise->send_notification_for_open_questions($question_list_answers, $origin, $exe_id);
            $objExercise->send_notification_for_oral_questions($question_list_answers, $origin, $exe_id);
        }
    }
}
Esempio n. 2
0
//Total score
if ($origin != 'learnpath' || $origin == 'learnpath' && isset($_GET['fb_type'])) {
    if ($show_results || $show_only_total_score) {
        $total_score_text .= '<div class="question_row">';
        $my_total_score_temp = $totalScore;
        if ($objExercise->selectPropagateNeg() == 0 && $my_total_score_temp < 0) {
            $my_total_score_temp = 0;
        }
        $total_score_text .= get_question_ribbon($objExercise, $my_total_score_temp, $totalWeighting, true);
        $total_score_text .= '</div>';
    }
}
if (!empty($category_list) && ($show_results || $show_only_total_score)) {
    //Adding total
    $category_list['total'] = array('score' => $my_total_score_temp, 'total' => $totalWeighting);
    echo Testcategory::get_stats_table_by_attempt($objExercise->id, $category_list);
}
echo $total_score_text;
echo $exercise_content;
echo $total_score_text;
if (is_array($arrid) && is_array($arrmarks)) {
    $strids = implode(",", $arrid);
    $marksid = implode(",", $arrmarks);
}
if ($is_allowedToEdit && $locked == false && !api_is_drh()) {
    if (in_array($origin, array('tracking_course', 'user_course', 'correct_exercise_in_lp'))) {
        echo ' <form name="myform" id="myform" action="exercise_report.php?exerciseId=' . $exercise_id . '&filter=2&comments=update&exeid=' . $id . '&origin=' . $origin . '&details=true&course=' . Security::remove_XSS($_GET['cidReq']) . $fromlink . '" method="post">';
        echo '<input type = "hidden" name="lp_item_id"       value="' . $learnpath_id . '">';
        echo '<input type = "hidden" name="lp_item_view_id"  value="' . $lp_item_view_id . '">';
        echo '<input type = "hidden" name="student_id"       value="' . $student_id . '">';
        echo '<input type = "hidden" name="total_score"      value="' . $totalScore . '"> ';
 /**
  * Display the exercise results
  * @param int   attempt id (exe_id)
  * @param bool  save users results (true) or just show the results (false)
  * @param bool return array with exercise result info
  * @param mixed
  */
 public function displayQuestionListByAttempt($exe_id, $saveUserResult = false, $returnExerciseResult = false)
 {
     global $origin, $debug;
     //Getting attempt info
     $exercise_stat_info = $this->getStatTrackExerciseInfoByExeId($exe_id);
     //Getting question list
     $question_list = array();
     if (!empty($exercise_stat_info['data_tracking'])) {
         $question_list = explode(',', $exercise_stat_info['data_tracking']);
     } else {
         //Try getting the question list only if save result is off
         if ($saveUserResult == false) {
             $question_list = $this->selectQuestionList();
         }
         error_log("Data tracking is empty! exe_id: {$exe_id}");
     }
     $counter = 1;
     $total_score = 0;
     $total_weight = 0;
     $exercise_content = null;
     //Hide results
     $show_results = false;
     $show_only_score = false;
     if ($this->results_disabled == RESULT_DISABLE_SHOW_SCORE_AND_EXPECTED_ANSWERS) {
         $show_results = true;
     }
     if (in_array($this->results_disabled, array(RESULT_DISABLE_SHOW_SCORE_ONLY, RESULT_DISABLE_SHOW_FINAL_SCORE_ONLY_WITH_CATEGORIES))) {
         $show_only_score = true;
     }
     if ($show_results || $show_only_score) {
         $user_info = api_get_user_info($exercise_stat_info['exe_user_id']);
         // Shows exercise header.
         echo $this->show_exercise_result_header($user_info['complete_name'], api_convert_and_format_date($exercise_stat_info['start_date'], DATE_TIME_FORMAT_LONG), $exercise_stat_info['duration']);
     }
     // Display text when test is finished #4074 and for LP #4227
     $end_of_message = $this->selectTextWhenFinished();
     if (!empty($end_of_message)) {
         Display::display_normal_message($end_of_message, false);
         echo "<div class='clear'>&nbsp;</div>";
     }
     $question_list_answers = array();
     $media_list = array();
     $category_list = array();
     $tempParentId = null;
     $mediaCounter = 0;
     $exerciseResultInfo = array();
     // Loop over all question to show results for each of them, one by one
     if (!empty($question_list)) {
         if ($debug) {
             error_log('Looping question_list ' . print_r($question_list, 1));
         }
         foreach ($question_list as $questionId) {
             // Creates a temporary Question object
             $objQuestionTmp = Question::read($questionId);
             // This variable commes from exercise_submit_modal.php
             ob_start();
             $hotspot_delineation_result = null;
             // We're inside *one* question. Go through each possible answer for this question
             $result = $this->manageAnswers($exercise_stat_info['exe_id'], $questionId, null, 'exercise_result', array(), $saveUserResult, true, $show_results, $hotspot_delineation_result);
             if (empty($result)) {
                 continue;
             }
             $total_score += $result['score'];
             $total_weight += $result['weight'];
             $question_list_answers[] = array('question' => $result['open_question'], 'answer' => $result['open_answer'], 'answer_type' => $result['answer_type']);
             $my_total_score = $result['score'];
             $my_total_weight = $result['weight'];
             // Category report
             $category_was_added_for_this_test = false;
             $categoryExerciseList = $this->getListOfCategoriesWithQuestionForTest();
             $category_list = array();
             if (isset($categoryExerciseList) && !empty($categoryExerciseList)) {
                 foreach ($categoryExerciseList as $category_id => $categoryInfo) {
                     if (!isset($category_list[$category_id])) {
                         $category_list[$category_id] = array();
                         $category_list[$category_id]['score'] = 0;
                         $category_list[$category_id]['total'] = 0;
                     }
                     $category_list[$category_id]['score'] += $my_total_score;
                     $category_list[$category_id]['total'] += $my_total_weight;
                     $category_was_added_for_this_test = true;
                 }
             }
             // No category for this question!
             if ($category_was_added_for_this_test == false) {
                 if (!isset($category_list['none'])) {
                     $category_list['none'] = array();
                     $category_list['none']['score'] = 0;
                     $category_list['none']['total'] = 0;
                 }
                 $category_list['none']['score'] += $my_total_score;
                 $category_list['none']['total'] += $my_total_weight;
             }
             if ($this->selectPropagateNeg() == 0 && $my_total_score < 0) {
                 $my_total_score = 0;
             }
             $comnt = null;
             if ($show_results) {
                 $comnt = get_comments($exe_id, $questionId);
                 if (!empty($comnt)) {
                     echo '<b>' . get_lang('Feedback') . '</b>';
                     echo '<div id="question_feedback">' . $comnt . '</div>';
                 }
             }
             $score = array();
             $score['result'] = get_lang('Score') . " : " . ExerciseLib::show_score($my_total_score, $my_total_weight, false, true);
             $score['pass'] = $my_total_score >= $my_total_weight ? true : false;
             $score['score'] = $my_total_score;
             $score['weight'] = $my_total_weight;
             $score['comments'] = $comnt;
             $exerciseResultInfo[$questionId]['score'] = $score;
             $exerciseResultInfo[$questionId]['details'] = $result;
             // If no results we hide the results
             if ($show_results == false) {
                 $score = array();
             }
             $contents = ob_get_clean();
             $question_content = '<div class="question_row">';
             if ($show_results) {
                 $show_media = false;
                 $counterToShow = $counter;
                 if ($objQuestionTmp->parent_id != 0) {
                     if (!in_array($objQuestionTmp->parent_id, $media_list)) {
                         $media_list[] = $objQuestionTmp->parent_id;
                         $show_media = true;
                     }
                     if ($tempParentId == $objQuestionTmp->parent_id) {
                         $mediaCounter++;
                     } else {
                         $mediaCounter = 0;
                     }
                     $counterToShow = chr(97 + $mediaCounter);
                     $tempParentId = $objQuestionTmp->parent_id;
                 }
                 // Shows question title an description.
                 $question_content .= $objQuestionTmp->return_header(null, $counterToShow, $score, $show_media, $this->getHideQuestionTitle());
                 // display question category, if any
                 $question_content .= Testcategory::getCategoryNamesForQuestion($questionId, null, true, $this->categoryMinusOne);
             }
             $counter++;
             $question_content .= $contents;
             $question_content .= '</div>';
             $exercise_content .= $question_content;
         }
         // end foreach() block that loops over all questions
     }
     $total_score_text = null;
     if ($returnExerciseResult) {
         return $exerciseResultInfo;
     }
     if ($origin != 'learnpath') {
         if ($show_results || $show_only_score) {
             $total_score_text .= '<div class="question_row">';
             $total_score_text .= $this->get_question_ribbon($total_score, $total_weight, true);
             $total_score_text .= '</div>';
         }
     }
     if (!empty($category_list) && ($show_results || $show_only_score)) {
         //Adding total
         $category_list['total'] = array('score' => $total_score, 'total' => $total_weight);
         echo Testcategory::get_stats_table_by_attempt($this->id, $category_list, $this->categoryMinusOne);
     }
     echo $total_score_text;
     echo $exercise_content;
     if (!$show_only_score) {
         echo $total_score_text;
     }
     if ($saveUserResult) {
         // Tracking of results
         $learnpath_id = $exercise_stat_info['orig_lp_id'];
         $learnpath_item_id = $exercise_stat_info['orig_lp_item_id'];
         $learnpath_item_view_id = $exercise_stat_info['orig_lp_item_view_id'];
         if (api_is_allowed_to_session_edit()) {
             update_event_exercise($exercise_stat_info['exe_id'], $this->selectId(), $total_score, $total_weight, api_get_session_id(), $learnpath_id, $learnpath_item_id, $learnpath_item_view_id, $exercise_stat_info['exe_duration'], '', array());
         }
         // Send notification.
         if (!api_is_allowed_to_edit(null, true)) {
             $this->sendCustomNotification($exe_id, $exerciseResultInfo);
             $this->sendNotificationForOpenQuestions($question_list_answers, $origin, $exe_id);
             $this->sendNotificationForOralQuestions($question_list_answers, $origin, $exe_id);
         }
     }
 }