Minor - format code.

1.9.x
Julio Montoya 10 years ago
parent c988f89212
commit e70ff9e0f6
  1. 55
      main/exercice/exercise.class.php
  2. 11
      main/exercice/exercise.lib.php
  3. 37
      main/exercice/exercise_result.php
  4. 14
      main/exercice/exercise_show.php
  5. 24
      main/exercice/exercise_submit.php
  6. 23
      main/exercice/global_multiple_answer.class.php

@ -1,17 +1,17 @@
<?php
/* For licensing terms, see /license.txt */
define('ALL_ON_ONE_PAGE', 1);
define('ONE_PER_PAGE', 2);
define('ALL_ON_ONE_PAGE', 1);
define('ONE_PER_PAGE', 2);
define('EXERCISE_FEEDBACK_TYPE_END', 0); //Feedback - show score and expected answers
define('EXERCISE_FEEDBACK_TYPE_DIRECT', 1); //DirectFeedback - Do not show score nor answers
define('EXERCISE_FEEDBACK_TYPE_EXAM', 2); //NoFeedback - Show score only
define('EXERCISE_FEEDBACK_TYPE_END', 0); //Feedback - show score and expected answers
define('EXERCISE_FEEDBACK_TYPE_DIRECT', 1); //DirectFeedback - Do not show score nor answers
define('EXERCISE_FEEDBACK_TYPE_EXAM', 2); //NoFeedback - Show score only
define('RESULT_DISABLE_SHOW_SCORE_AND_EXPECTED_ANSWERS', 0); //show score and expected answers
define('RESULT_DISABLE_NO_SCORE_AND_EXPECTED_ANSWERS', 1); //Do not show score nor answers
define('RESULT_DISABLE_SHOW_SCORE_ONLY', 2); //Show score only
define('RESULT_DISABLE_SHOW_FINAL_SCORE_ONLY_WITH_CATEGORIES', 3); //Show final score only with categories
define('RESULT_DISABLE_SHOW_SCORE_AND_EXPECTED_ANSWERS', 0); //show score and expected answers
define('RESULT_DISABLE_NO_SCORE_AND_EXPECTED_ANSWERS', 1); //Do not show score nor answers
define('RESULT_DISABLE_SHOW_SCORE_ONLY', 2); //Show score only
define('RESULT_DISABLE_SHOW_FINAL_SCORE_ONLY_WITH_CATEGORIES', 3); //Show final score only with categories
define('EXERCISE_MAX_NAME_SIZE', 80);
@ -2362,25 +2362,26 @@ class Exercise
case GLOBAL_MULTIPLE_ANSWER:
if ($from_database) {
$choice = array();
$queryans = "SELECT answer FROM $TBL_TRACK_ATTEMPT WHERE exe_id = '".$exeId."' AND question_id= '".$questionId."'";
$resultans = Database::query($queryans);
$sql = "SELECT answer FROM $TBL_TRACK_ATTEMPT
WHERE exe_id = '".$exeId."' AND question_id= '".$questionId."'";
$resultans = Database::query($sql);
while ($row = Database::fetch_array($resultans)) {
$ind = $row['answer'];
$choice[$ind] = 1;
}
$studentChoice = $choice[$numAnswer];
$studentChoice = isset($choice[$numAnswer]) ? $choice[$numAnswer] : null;
$real_answers[$answerId] = (bool)$studentChoice;
if ($studentChoice) {
$questionScore +=$answerWeighting;
$questionScore +=$answerWeighting;
}
} else {
$studentChoice = $choice[$numAnswer];
$studentChoice = isset($choice[$numAnswer]) ? $choice[$numAnswer] : null;
if (isset($studentChoice)) {
$questionScore += $answerWeighting;
$questionScore += $answerWeighting;
}
$real_answers[$answerId] = (bool)$studentChoice;
}
$totalScore += $answerWeighting;
$totalScore += $answerWeighting;
if ($debug) error_log("studentChoice: $studentChoice");
break;
case MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE:
@ -3338,11 +3339,12 @@ class Exercise
}
//Fixes multiple answer question in order to be exact
if ($answerType == MULTIPLE_ANSWER || $answerType == GLOBAL_MULTIPLE_ANSWER) {
//if ($answerType == MULTIPLE_ANSWER || $answerType == GLOBAL_MULTIPLE_ANSWER) {
/* if ($answerType == GLOBAL_MULTIPLE_ANSWER) {
$diff = @array_diff($answer_correct_array, $real_answers);
/*
* All good answers or nothing works like exact
// All good answers or nothing works like exact
$counter = 1;
$correct_answer = true;
foreach ($real_answers as $my_answer) {
@ -3352,20 +3354,21 @@ class Exercise
break;
}
$counter++;
}*/
}
if ($debug) error_log(" answer_correct_array: ".print_r($answer_correct_array, 1)."");
if ($debug) error_log(" real_answers: ".print_r($real_answers, 1)."");
//if ($debug) error_log(" correct_answer: ".$correct_answer);
if ($debug) error_log(" correct_answer: ".$correct_answer);
/*if ($correct_answer == false) {
if ($correct_answer == false) {
$questionScore = 0;
}*/
}
//This makes the result non exact
// This makes the result non exact
if (!empty($diff)) {
//$questionScore = 0;
$questionScore = 0;
}
}
}*/
$extra_data = array(
'final_overlap' => $final_overlap,

@ -2439,21 +2439,20 @@ function delete_chat_exercise_session($exe_id) {
*/
function display_question_list_by_attempt($objExercise, $exe_id, $save_user_result = false)
{
global $origin, $debug;
global $origin;
//Getting attempt info
// Getting attempt info
$exercise_stat_info = $objExercise->get_stat_track_exercise_info_by_exe_id($exe_id);
//Getting question list
// 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
// Try getting the question list only if save result is off
if ($save_user_result == false) {
$question_list = $objExercise->get_validated_question_list();
}
//error_log("Data tracking is empty! exe_id: $exe_id");
}
$counter = 1;
@ -2461,7 +2460,7 @@ function display_question_list_by_attempt($objExercise, $exe_id, $save_user_resu
$exercise_content = null;
//Hide results
// Hide results
$show_results = false;
$show_only_score = false;

@ -1,5 +1,6 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Exercise result
* This script gets information from the script "exercise_submit.php",
@ -60,14 +61,14 @@ if (empty($remind_list)) {
$exe_id = isset($_REQUEST['exe_id']) ? intval($_REQUEST['exe_id']) : 0;
if (empty($objExercise)) {
//Redirect to the exercise overview
//Check if the exe_id exists
$objExercise = new Exercise();
$exercise_stat_info = $objExercise->get_stat_track_exercise_info_by_exe_id($exe_id);
if (!empty($exercise_stat_info) && isset($exercise_stat_info['exe_exo_id'])) {
header("Location: overview.php?exerciseId=".$exercise_stat_info['exe_exo_id']);
exit;
}
// Redirect to the exercise overview
// Check if the exe_id exists
$objExercise = new Exercise();
$exercise_stat_info = $objExercise->get_stat_track_exercise_info_by_exe_id($exe_id);
if (!empty($exercise_stat_info) && isset($exercise_stat_info['exe_exo_id'])) {
header("Location: overview.php?exerciseId=".$exercise_stat_info['exe_exo_id']);
exit;
}
api_not_allowed();
}
@ -84,7 +85,7 @@ $nameTools = get_lang('Exercice');
$interbreadcrumb[]= array("url" => "exercice.php?gradebook=$gradebook","name" => get_lang('Exercices'));
if ($origin != 'learnpath') {
//so we are not in learnpath tool
// So we are not in learnpath tool
Display::display_header($nameTools,get_lang('Exercise'));
} else {
Display::display_reduced_header();
@ -104,7 +105,7 @@ $feedback_type = $objExercise->feedback_type;
$exercise_stat_info = $objExercise->get_stat_track_exercise_info_by_exe_id($exe_id);
if (!empty($exercise_stat_info['data_tracking'])) {
$question_list = explode(',', $exercise_stat_info['data_tracking']);
$question_list = explode(',', $exercise_stat_info['data_tracking']);
}
$learnpath_id = $exercise_stat_info['orig_lp_id'];
@ -125,9 +126,18 @@ $i = $total_score = $total_weight = 0;
//We check if the user attempts before sending to the exercise_result.php
if ($objExercise->selectAttempts() > 0) {
$attempt_count = get_attempt_count(api_get_user_id(), $objExercise->id, $learnpath_id, $learnpath_item_id, $learnpath_item_view_id);
$attempt_count = get_attempt_count(
api_get_user_id(),
$objExercise->id,
$learnpath_id,
$learnpath_item_id,
$learnpath_item_view_id
);
if ($attempt_count >= $objExercise->selectAttempts()) {
Display :: display_warning_message(sprintf(get_lang('ReachedMaxAttempts'), $objExercise->selectTitle(), $objExercise->selectAttempts()), false);
Display :: display_warning_message(
sprintf(get_lang('ReachedMaxAttempts'), $objExercise->selectTitle(), $objExercise->selectAttempts()),
false
);
if ($origin != 'learnpath') {
//we are not in learnpath tool
Display::display_footer();
@ -138,7 +148,7 @@ if ($objExercise->selectAttempts() > 0) {
Display :: display_normal_message(get_lang('Saved').'<br />',false);
// Display questions
// Display and save questions
display_question_list_by_attempt($objExercise, $exe_id, true);
//If is not valid
@ -153,7 +163,6 @@ if (isset($session_control_key) && !exercise_time_control_is_valid($objExercise-
//Unset session for clock time
exercise_time_control_delete($objExercise->id, $learnpath_id, $learnpath_item_id);
delete_chat_exercise_session($exe_id);
if ($origin != 'learnpath') {

@ -111,8 +111,8 @@ if (!empty($gradebook) && $gradebook=='view') {
$fromlink = '';
$interbreadcrumb[]= array("url" => "exercice.php?gradebook=$gradebook","name" => get_lang('Exercices'));
$interbreadcrumb[]= array("url" => "overview.php?exerciseId=".$exercise_id.'&id_session='.api_get_session_id(),"name" => $objExercise->name);
$interbreadcrumb[]= array("url" => "exercice.php?".api_get_cidreq(),"name" => get_lang('Exercices'));
$interbreadcrumb[]= array("url" => "overview.php?exerciseId=".$exercise_id.'&'.api_get_cidreq(),"name" => $objExercise->name);
$interbreadcrumb[]= array("url" => "#","name" => get_lang('Result'));
$this_section = SECTION_COURSES;
@ -591,7 +591,15 @@ foreach ($questionList as $questionId) {
}
}
//No category for this question!
// No category for this question!
if (!isset($category_list['none']['score'])) {
$category_list['none']['score'] = 0;
}
if (!isset($category_list['none']['total'])) {
$category_list['none']['total'] = 0;
}
if ($category_was_added_for_this_test == false) {
$category_list['none']['score'] += $my_total_score;
$category_list['none']['total'] += $my_total_weight;

@ -531,17 +531,6 @@ if ($formSent && isset($_POST)) {
header("Location: exercise_result.php?".api_get_cidreq()."&exe_id=$exe_id&origin=$origin&learnpath_id=$learnpath_id&learnpath_item_id=$learnpath_item_id&learnpath_item_view_id=$learnpath_item_view_id");
exit;
} else {
//Time control is only enabled for ONE PER PAGE
if (!empty($exe_id) && is_numeric($exe_id)) {
//Verify if the current test is fraudulent
if (exercise_time_control_is_valid($exerciseId, $learnpath_id, $learnpath_item_id)) {
$sql_exe_result = "";
if ($debug) { error_log('exercise_time_control_is_valid is valid'); }
} else {
$sql_exe_result = ", exe_result = 0";
if ($debug) { error_log('exercise_time_control_is_valid is NOT valid then exe_result = 0 '); }
}
}
if ($debug) { error_log('10. Redirecting to exercise_show.php'); }
header("Location: exercise_result.php?".api_get_cidreq()."&exe_id=$exe_id&origin=$origin&learnpath_id=$learnpath_id&learnpath_item_id=$learnpath_item_id&learnpath_item_view_id=$learnpath_item_view_id");
exit;
@ -600,19 +589,6 @@ if ($question_count != 0) {
}
}
} else {
//Time control is only enabled for ONE PER PAGE
if (!empty($exe_id) && is_numeric($exe_id)) {
//Verify if the current test is fraudulent
$check = exercise_time_control_is_valid($exerciseId, $learnpath_id, $learnpath_item_id);
if ($check) {
$sql_exe_result = "";
if ($debug) { error_log('12. exercise_time_control_is_valid is valid'); }
} else {
$sql_exe_result = ", exe_result = 0";
if ($debug) { error_log('12. exercise_time_control_is_valid is NOT valid then exe_result = 0 '); }
}
}
if ($objExercise->review_answers) {
header('Location: exercise_reminder.php?'.$params);
exit;

@ -22,7 +22,6 @@ class GlobalMultipleAnswer extends Question
/**
* function which redefines Question::createAnswersForm
* @param the FormValidator
* @param the answers number to display
*/
public function createAnswersForm($form)
{
@ -44,17 +43,11 @@ class GlobalMultipleAnswer extends Question
' . get_lang('Answer') . '
</th>';
// Espace entre l'entete et les reponses
$html .='<th>' . get_lang('Comment') . '</th>';
$html .='</tr>';
$form->addElement('label', get_lang('Answers') . '<br /> <img src="../img/fill_field.png">', $html);
/* Initialiation variable */
$defaults = array();
$correct = 0;
/* Mise en variable du nombre de reponse */
$answer = false;
if (!empty($this->id)) {
$answer = new Answer($this->id);
@ -96,10 +89,11 @@ class GlobalMultipleAnswer extends Question
}
//------------- Fin
//------------- Debut si un des scores par reponse est egal <EFBFBD> 0 : la coche vaut 1 (coch<EFBFBD>)
if ($scoreA == 0)
if ($scoreA == 0) {
$defaults['pts'] = 1;
else
} else {
$defaults['pts'] = 0;
}
$renderer = & $form->defaultRenderer();
@ -177,8 +171,7 @@ class GlobalMultipleAnswer extends Question
/**
* abstract function which creates the form to create / edit the answers of the question
* @param the formvalidator instance
* @param the answers number to display
* @param the FormValidator instance
*/
function processAnswersCreation($form)
{
@ -203,13 +196,11 @@ class GlobalMultipleAnswer extends Question
// Set score per answer
$nbr_corrects = $nbr_corrects == 0 ? 1 : $nbr_corrects;
$answer_score = $nbr_corrects == 0 ? 0 : $answer_score;
//echo('affiche1');var_dump($answer_score);echo('<br>');
$answer_score = ($answer_score / $nbr_corrects);
//echo('affiche2');var_dump($answer_score);echo('<br>');
//$answer_score <EFBFBD>quivaut <EFBFBD> la valeur d'une bonne r<EFBFBD>ponse
// cr<EFBFBD>ation variable pour r<EFBFBD>cuperer la valeur de la coche pour la prise en compte des n<EFBFBD>gatifs
$test = "";
$test = $form->getSubmitValue('pts');
for ($i = 1; $i <= $nb_answers; $i++) {
@ -222,8 +213,9 @@ class GlobalMultipleAnswer extends Question
} else {
if ($test == 1) {
$weighting = 0;
}else
} else {
$weighting = -abs($answer_score);
}
}
$objAnswer->createAnswer($answer, $goodAnswer, $comment, $weighting, $i);
@ -249,6 +241,7 @@ class GlobalMultipleAnswer extends Question
<th>' . get_lang("Answer") . '</th>';
$header .= '<th>' . get_lang("Comment") . '</th>';
$header .= '</tr>';
return $header;
}
}

Loading…
Cancel
Save