From e3499250d3de764f3379538bb232944ac561296c Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Thu, 30 Dec 2010 15:14:41 +0100 Subject: [PATCH] Replacing exercise_min_note to exercise_min_score platform settings (same thing with the max score) --- main/exercice/admin.php | 2 +- main/exercice/exercise.class.php | 12 ++++--- main/exercice/exercise.lib.php | 23 ++++++++++--- main/exercice/exercise_show.php | 33 ++++++++++--------- .../multiple_answer_true_false.class.php | 13 ++++---- main/install/db_main.sql | 6 ++-- main/install/migrate-db-1.8.7-1.8.8-pre.sql | 4 +-- 7 files changed, 55 insertions(+), 38 deletions(-) diff --git a/main/exercice/admin.php b/main/exercice/admin.php index 9bc8578704..bcaef8daa5 100755 --- a/main/exercice/admin.php +++ b/main/exercice/admin.php @@ -488,7 +488,7 @@ if(!$newQuestion && !$modifyQuestion && !$editQuestion && !isset($_GET['hotspota Display::display_confirmation_message(get_lang('ExerciseEdited')); } if(api_get_setting('search_enabled')=='true' && !extension_loaded('xapian')) { - Display::display_error_message(get_lang('SearchXapianModuleNotInstaled')); + Display::display_error_message(get_lang('SearchXapianModuleNotInstaled')); } $form -> display (); echo '
'; diff --git a/main/exercice/exercise.class.php b/main/exercice/exercise.class.php index 1ed7256f3a..5a3d940a5f 100755 --- a/main/exercice/exercise.class.php +++ b/main/exercice/exercise.class.php @@ -1658,7 +1658,7 @@ class Exercise { $questionName = $objQuestionTmp->selectTitle(); $questionDescription = $objQuestionTmp->selectDescription(); - $questionWeighting = $objQuestionTmp->selectWeighting(); + $questionWeighting = $objQuestionTmp->selectWeighting(); $answerType = $objQuestionTmp->selectType(); $quesId = $objQuestionTmp->selectId(); $extra = $objQuestionTmp->extra; @@ -1697,7 +1697,7 @@ class Exercise { $real_answers = array(); $quiz_question_options = Question::readQuestionOption($questionId); - + for ($answerId = 1; $answerId <= $nbrAnswers; $answerId++) { $answer = $objAnswerTmp->selectAnswer($answerId); $answerComment = $objAnswerTmp->selectComment($answerId); @@ -1757,9 +1757,9 @@ class Exercise { $questionScore += $doubt_score; } } - $questionWeighting+=$true_score; + //$questionWeighting+=$true_score; $totalScore +=$true_score; - //echo $studentChoice.' - '.$answerCorrect.' '.$questionScore.'
'; + //echo $studentChoice.' - '.$answerCorrect.' '.$questionScore.' - '.$questionWeighting.'
'; break; case MULTIPLE_ANSWER : if ($from_database) { @@ -2408,7 +2408,9 @@ class Exercise { $sql_update = 'UPDATE ' . $stat_table . ' SET exe_result = exe_result + ' . (int) $totalScore . ',exe_weighting = exe_weighting + ' . (int) $totalWeighting . ' WHERE exe_id = ' . $exeId; Database::query($sql_update); } - return array('score'=>$questionScore, 'weight'=>$questionWeighting); + + $return_array = array('score'=>$questionScore, 'weight'=>$questionWeighting); + return $return_array; } //End function diff --git a/main/exercice/exercise.lib.php b/main/exercice/exercise.lib.php index 8fe5d13425..6da98839a9 100755 --- a/main/exercice/exercise.lib.php +++ b/main/exercice/exercise.lib.php @@ -1073,22 +1073,37 @@ function get_exam_results_data($from, $number_of_items, $column, $direction) { return $list_info; } +/** + * Transform the score with exercise_max_note and exercise_min_score the platform settings + * @param float score + * @param float weight + * @param bool show porcentage or not + * @return string an html with the score modified + */ function show_score($score, $weight, $show_porcentage = true) { $html = ''; $score_rounded = $score; if ($score != '' && $weight != '') { - $max_note = api_get_setting('exercise_max_note'); - $min_note = api_get_setting('exercise_min_note'); + $max_note = api_get_setting('exercise_max_score'); + $min_note = api_get_setting('exercise_min_score'); if ($max_note != '' && $min_note != '') { if (!empty($weight)) { - $score = $min_note + ($max_note - $min_note) * $score /$weight; + $score = $min_note + ($max_note - $min_note) * $score /$weight; } else { $score = $min_note; } $score_rounded = round($score, 2); $weight = $max_note; } - $html = round(($score / ($weight != 0 ? $weight : 1)) * 100, 2) . '% (' . $score_rounded . ' / ' . $weight . ')'; + if ($show_porcentage) { + $html = round(($score / ($weight != 0 ? $weight : 1)) * 100, 2) . '% (' . $score_rounded . ' / ' . $weight . ')'; + } else { + $html = $score_rounded . ' / ' . $weight; + } } return $html; } + + + + diff --git a/main/exercice/exercise_show.php b/main/exercice/exercise_show.php index e104ddaca2..5133c983cf 100755 --- a/main/exercice/exercise_show.php +++ b/main/exercice/exercise_show.php @@ -314,7 +314,13 @@ if ($show_results) { // for each question $counter=0; - //var_dump($exerciseResult); + + $total_weighting = 0; + foreach ($questionList as $questionId) { + $objQuestionTmp = Question::read($questionId); + $total_weighting +=$objQuestionTmp->selectWeighting(); + } + foreach ($questionList as $questionId) { $counter++; $choice=$exerciseResult[$questionId]; @@ -372,7 +378,7 @@ if ($show_results) { //var_dump($question_result); $questionScore = $question_result['score']; $totalScore += $question_result['score']; - $questionWeighting += $question_result['weight']; + //$questionWeighting += $question_result['weight']; echo ''; } elseif ($answerType == MULTIPLE_ANSWER_COMBINATION || $answerType == MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE) { @@ -393,8 +399,7 @@ if ($show_results) { manage_answer($id, $questionId, $choice,'exercise_show', array(), false, true); - + $question_result = $objExercise->manage_answer($id, $questionId, $choice,'exercise_show', array(), false, true); $questionScore = $question_result['score']; $totalScore += $question_result['score']; @@ -574,10 +579,11 @@ if ($show_results) { '; - echo get_lang('Score')." : $my_total_score/$my_total_weight"; + //echo get_lang('Score')." : $my_total_score/$my_total_weight"; + echo get_lang('Score')." : ".show_score($my_total_score,$total_weighting,false); echo ''; unset($objAnswerTmp); @@ -588,18 +594,14 @@ if ($show_results) { } //end of condition if $show_results if ($origin!='learnpath' || ($origin == 'learnpath' && isset($_GET['fb_type']))) { - if ($show_results) { - - echo '
'.get_lang('YourTotalScore')." "; + if ($show_results) { + echo '
'.get_lang('YourTotalScore').": "; if ($dsp_percent) { $my_result = number_format(($totalScore/$totalWeighting)*100,1,'.',''); $my_result = float_format($my_result,1); echo $my_result."%"; - } else { - - $my_total_score = float_format($totalScore,1); - $my_total_weight = float_format($totalWeighting,1); - echo $my_total_score."/".$my_total_weight; + } else { + echo show_score($my_total_score,$my_total_weight,false); } echo '
'; } @@ -611,8 +613,7 @@ if (is_array($arrid) && is_array($arrmarks)) { } if ($is_allowedToEdit) { - if (in_array($origin, array('tracking_course','user_course','correct_exercise_in_lp'))) { - + if (in_array($origin, array('tracking_course','user_course','correct_exercise_in_lp'))) { echo '
'; echo ' '; echo ''; diff --git a/main/exercice/multiple_answer_true_false.class.php b/main/exercice/multiple_answer_true_false.class.php index bcbf11e679..bdbf0188c5 100755 --- a/main/exercice/multiple_answer_true_false.class.php +++ b/main/exercice/multiple_answer_true_false.class.php @@ -240,20 +240,19 @@ class MultipleAnswerTrueFalse extends Question { } } + //Getting quiz_question_options (true, false, doubt) because it's possible that there are more options in the future $new_options = Question::readQuestionOption($this->id); $sorted_by_position = array(); foreach($new_options as $item) { $sorted_by_position[$item['position']] = $item; - } - + } - //Saving quiz_question.extra values + //Saving quiz_question.extra values that has the correct scores of the true, false, doubt options registered in this format XX:YY:ZZZ where XX is a float score value $extra_values = array(); for ($i=1 ; $i <= 3 ; $i++) { $score = trim($form -> getSubmitValue('option['.$i.']')); $extra_values[]= $score; - } - + } $this->setExtra(implode(':',$extra_values)); for ($i=1 ; $i <= $nb_answers ; $i++) { @@ -261,10 +260,10 @@ class MultipleAnswerTrueFalse extends Question { $comment = trim($form -> getSubmitValue('comment['.$i.']')); $goodAnswer = trim($form -> getSubmitValue('correct['.$i.']')); if (empty($options)) { - //new + //If this is the first time that the question is created when change the default values from the form 1 and 2 by the correct "option id" registered $goodAnswer = $sorted_by_position[$goodAnswer]['id']; } - $questionWeighting += $correct[1]; + $questionWeighting += $extra_values[0]; //By default 0 has the correct answers $objAnswer->createAnswer($answer, $goodAnswer, $comment,'',$i); } diff --git a/main/install/db_main.sql b/main/install/db_main.sql index 536b981a8d..68fef4e9c6 100755 --- a/main/install/db_main.sql +++ b/main/install/db_main.sql @@ -782,9 +782,9 @@ VALUES ('pdf_export_watermark_text', NULL,'textfield', 'Platform', '', 'PDFExportWatermarkTextTitle', 'PDFExportWatermarkTextComment', 'platform',NULL, 1), ('enabled_insertHtml', NULL,'radio', 'Editor', 'false','EnabledInsertHtmlTitle', 'EnabledInsertHtmlComment',NULL,NULL, 0), ('students_export2pdf', NULL,'radio', 'Tools', 'true', 'EnabledStudentExport2PDFTitle', 'EnabledStudentExport2PDFComment',NULL,NULL, 0), -('exercise_min_note', NULL,'textfield', 'Course', '', 'ExerciseMinNoteTitle', 'ExerciseMinNoteComment','platform',NULL, 1), -('exercise_max_note', NULL,'textfield', 'Course', '', 'ExerciseMaxNoteTitle', 'ExerciseMaxNoteComment','platform',NULL, 1), -('chamilo_database_version', NULL,'textfield', NULL, '1.8.8.13050','DokeosDatabaseVersion','', NULL, NULL, 0); +('exercise_min_score', NULL,'textfield', 'Course', '', 'ExerciseMinScoreTitle', 'ExerciseMinScoreComment','platform',NULL, 1), +('exercise_max_score', NULL,'textfield', 'Course', '', 'ExerciseMaxScoreTitle', 'ExerciseMaxScoreComment','platform',NULL, 1), +('chamilo_database_version', NULL,'textfield', NULL, '1.8.8.13174','DokeosDatabaseVersion','', NULL, NULL, 0); UNLOCK TABLES; diff --git a/main/install/migrate-db-1.8.7-1.8.8-pre.sql b/main/install/migrate-db-1.8.7-1.8.8-pre.sql index 437f33b328..af6a46a30f 100755 --- a/main/install/migrate-db-1.8.7-1.8.8-pre.sql +++ b/main/install/migrate-db-1.8.7-1.8.8-pre.sql @@ -94,8 +94,8 @@ INSERT INTO settings_current (variable, subkey, type, category, selected_value, INSERT INTO settings_options (variable, value, display_text) VALUES ('students_export2pdf', 'true', 'Yes'); INSERT INTO settings_options (variable, value, display_text) VALUES ('students_export2pdf', 'false', 'No'); -INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES ('exercise_min_note', NULL,'textfield', 'Course', '', 'ExerciseMinNoteTitle', 'ExerciseMinNoteComment','platform',NULL, 1); -INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES ('exercise_max_note', NULL,'textfield', 'Course', '', 'ExerciseMaxNoteTitle', 'ExerciseMaxNoteComment','platform',NULL, 1); +INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES ('exercise_min_score', NULL,'textfield', 'Course', '', 'ExerciseMinScoreTitle', 'ExerciseMinScoreComment','platform',NULL, 1); +INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES ('exercise_max_score', NULL,'textfield', 'Course', '', 'ExerciseMaxScoreTitle', 'ExerciseMaxScoreComment','platform',NULL, 1); -- xxSTATSxx