From e70ff9e0f683ffaf2340940014b3b47d33ba017c Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Thu, 23 Oct 2014 08:44:33 +0200 Subject: [PATCH] Minor - format code. --- main/exercice/exercise.class.php | 55 ++++++++++--------- main/exercice/exercise.lib.php | 11 ++-- main/exercice/exercise_result.php | 37 ++++++++----- main/exercice/exercise_show.php | 14 ++++- main/exercice/exercise_submit.php | 24 -------- .../exercice/global_multiple_answer.class.php | 23 +++----- 6 files changed, 76 insertions(+), 88 deletions(-) diff --git a/main/exercice/exercise.class.php b/main/exercice/exercise.class.php index 5e57ca6d01..6ae1c889b1 100755 --- a/main/exercice/exercise.class.php +++ b/main/exercice/exercise.class.php @@ -1,17 +1,17 @@ $final_overlap, diff --git a/main/exercice/exercise.lib.php b/main/exercice/exercise.lib.php index b26f3e98b0..46b8f4191f 100755 --- a/main/exercice/exercise.lib.php +++ b/main/exercice/exercise.lib.php @@ -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; diff --git a/main/exercice/exercise_result.php b/main/exercice/exercise_result.php index 1706a01a6f..19b84f8f7c 100755 --- a/main/exercice/exercise_result.php +++ b/main/exercice/exercise_result.php @@ -1,5 +1,6 @@ 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').'
',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') { diff --git a/main/exercice/exercise_show.php b/main/exercice/exercise_show.php index 72942b3e6a..2e94d01fc0 100755 --- a/main/exercice/exercise_show.php +++ b/main/exercice/exercise_show.php @@ -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; diff --git a/main/exercice/exercise_submit.php b/main/exercice/exercise_submit.php index f469accb7d..d7d11051c0 100755 --- a/main/exercice/exercise_submit.php +++ b/main/exercice/exercise_submit.php @@ -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; diff --git a/main/exercice/global_multiple_answer.class.php b/main/exercice/global_multiple_answer.class.php index a645442b08..02148ef364 100755 --- a/main/exercice/global_multiple_answer.class.php +++ b/main/exercice/global_multiple_answer.class.php @@ -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') . ' '; - // Espace entre l'entete et les reponses $html .='' . get_lang('Comment') . ''; $html .=''; - $form->addElement('label', get_lang('Answers') . '
', $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 � 0 : la coche vaut 1 (coch�) - 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('
'); $answer_score = ($answer_score / $nbr_corrects); - //echo('affiche2');var_dump($answer_score);echo('
'); + //$answer_score �quivaut � la valeur d'une bonne r�ponse // cr�ation variable pour r�cuperer la valeur de la coche pour la prise en compte des n�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 ' . get_lang("Answer") . ''; $header .= '' . get_lang("Comment") . ''; $header .= ''; + return $header; } }