diff --git a/main/exercice/exercise.class.php b/main/exercice/exercise.class.php index 2074eaf644..7df0f976bb 100644 --- a/main/exercice/exercise.class.php +++ b/main/exercice/exercise.class.php @@ -49,10 +49,11 @@ class Exercise { public $course; public $course_id; public $propagate_neg; - public $review_answers; // + public $review_answers; public $randomByCat; - public $text_when_finished; // - public $display_category_name; // + public $text_when_finished; + public $display_category_name; + public $pass_percentage; /** @@ -79,7 +80,8 @@ class Exercise { $this->review_answers = false; $this->randomByCat = 0; // $this->text_when_finished = ""; // - $this->display_category_name = 0; // + $this->display_category_name = 0; + $this->pass_percentage = null; if (!empty($course_id)) { $course_info = api_get_course_info_by_id($course_id); @@ -109,23 +111,24 @@ class Exercise { $result = Database::query($sql); // if the exercise has been found - if ($object=Database::fetch_object($result)) { - $this->id = $id; - $this->exercise = $object->title; - $this->name = cut($object->title, EXERCISE_MAX_NAME_SIZE); - $this->description = $object->description; - $this->sound = $object->sound; - $this->type = $object->type; - $this->random = $object->random; - $this->random_answers = $object->random_answers; - $this->active = $object->active; - $this->results_disabled = $object->results_disabled; - $this->attempts = $object->max_attempt; - $this->feedbacktype = $object->feedback_type; - $this->propagate_neg = $object->propagate_neg; - $this->randomByCat = $object->random_by_category; // - $this->text_when_finished = $object->text_when_finished; // - $this->display_category_name = $object->display_category_name; // + if ($object = Database::fetch_object($result)) { + $this->id = $id; + $this->exercise = $object->title; + $this->name = cut($object->title, EXERCISE_MAX_NAME_SIZE); + $this->description = $object->description; + $this->sound = $object->sound; + $this->type = $object->type; + $this->random = $object->random; + $this->random_answers = $object->random_answers; + $this->active = $object->active; + $this->results_disabled = $object->results_disabled; + $this->attempts = $object->max_attempt; + $this->feedbacktype = $object->feedback_type; + $this->propagate_neg = $object->propagate_neg; + $this->randomByCat = $object->random_by_category; + $this->text_when_finished = $object->text_when_finished; + $this->display_category_name = $object->display_category_name; + $this->pass_percentage = $object->pass_percentage; $this->review_answers = (isset($object->review_answers) && $object->review_answers == 1) ? true : false; @@ -253,6 +256,10 @@ class Exercise { function selectDisplayCategoryName() { return $this->display_category_name; } + + function selectPassPercentage() { + return $this->pass_percentage; + } /** * @author - hubert borderiou 30-11-11 @@ -263,7 +270,6 @@ class Exercise { $this->display_category_name = $in_txt; } - /** * @author - hubert borderiou 28-11-11 * @return - html text : the text to display ay the end of the test. @@ -524,9 +530,14 @@ class Exercise { function updatePropagateNegative($value) { $this->propagate_neg = $value; } + function updateReviewAnswers($value) { $this->review_answers = (isset($value) && $value) ? true : false; } + + function updatePassPercentage($value) { + $this->pass_percentage = $value; + } /** * changes the exercise sound file @@ -634,27 +645,25 @@ class Exercise { function save($type_e = '') { global $_course; $TBL_EXERCICES = Database::get_course_table(TABLE_QUIZ_TEST); - $TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION); - $TBL_QUIZ_QUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION); - - $id = $this->id; - $exercise = $this->exercise; - $description = $this->description; - $sound = $this->sound; - $type = $this->type; - $attempts = $this->attempts; - $feedbacktype = $this->feedbacktype; - $random = $this->random; - $random_answers = $this->random_answers; - $active = $this->active; - $propagate_neg = $this->propagate_neg; - $review_answers = (isset($this->review_answers) && $this->review_answers) ? 1 : 0; - $randomByCat = $this->randomByCat; - - $text_when_finished = $this->text_when_finished; - $display_category_name = intval($this->display_category_name); // - $session_id = api_get_session_id(); + $id = $this->id; + $exercise = $this->exercise; + $description = $this->description; + $sound = $this->sound; + $type = $this->type; + $attempts = $this->attempts; + $feedbacktype = $this->feedbacktype; + $random = $this->random; + $random_answers = $this->random_answers; + $active = $this->active; + $propagate_neg = $this->propagate_neg; + $review_answers = (isset($this->review_answers) && $this->review_answers) ? 1 : 0; + $randomByCat = $this->randomByCat; + $text_when_finished = $this->text_when_finished; + $display_category_name = intval($this->display_category_name); + $pass_percentage = intval($this->pass_percentage); + + $session_id = api_get_session_id(); //If direct we do not show results if ($feedbacktype == EXERCISE_FEEDBACK_TYPE_DIRECT) { @@ -698,6 +707,7 @@ class Exercise { random_by_category='".Database::escape_string($randomByCat)."', text_when_finished = '".Database::escape_string($text_when_finished)."', display_category_name = '".Database::escape_string($display_category_name)."', + pass_percentage = '".Database::escape_string($pass_percentage)."', results_disabled='".Database::escape_string($results_disabled)."'"; } $sql .= " WHERE c_id = ".$this->course_id." AND id='".Database::escape_string($id)."'"; @@ -711,7 +721,9 @@ class Exercise { } } else { // creates a new exercise - $sql = "INSERT INTO $TBL_EXERCICES (c_id, start_time, end_time, title, description, sound, type, random, random_answers, active, results_disabled, max_attempt, feedback_type, expired_time, session_id, review_answers, random_by_category, text_when_finished, display_category_name) + $sql = "INSERT INTO $TBL_EXERCICES (c_id, start_time, end_time, title, description, sound, type, random, random_answers, active, + results_disabled, max_attempt, feedback_type, expired_time, session_id, review_answers, random_by_category, + text_when_finished, display_category_name, pass_percentage) VALUES( ".$this->course_id.", '$start_time','$end_time', @@ -730,12 +742,13 @@ class Exercise { '".Database::escape_string($review_answers)."', '".Database::escape_string($randomByCat)."', '".Database::escape_string($text_when_finished)."', - '".Database::escape_string($display_category_name)."' + '".Database::escape_string($display_category_name)."', + '".Database::escape_string($pass_percentage)."' )"; Database::query($sql); $this->id = Database::insert_id(); + // insert into the item_property table - api_item_property_update($this->course, TOOL_QUIZ, $this->id,'QuizAdded',api_get_user_id()); if (api_get_setting('search_enabled')=='true' && extension_loaded('xapian')) { $this->search_engine_save(); @@ -1040,11 +1053,16 @@ class Exercise { $form->addElement('html','
'); - //$form->addElement('text', 'enabletimercontroltotalminutes',get_lang('ExerciseTotalDurationInMinutes'),array('style' => 'width : 35px','id' => 'enabletimercontroltotalminutes')); - - $form->addElement('html',''); + //Pass percentage + $options = array('' => '-'); + for ($i = 0; $i <= 20 ; $i++) { + $options[$i*5] = $i*5; + } + $form->addElement('select', 'pass_percentage', array(get_lang('PassPercentage'), null, '%'), $options, array('id' => 'pass_percentage', 'class' => 'chzn-select')); + //$form->addElement('text', 'exerciseAttempts', get_lang('ExerciseAttempts').' : ',array('size'=>'2')); // add the text_when_finished textbox @@ -1088,7 +1106,8 @@ class Exercise { $form->addElement('style_submit_button', 'submitExercise', $text, 'class="save"'); $form->addRule('exerciseTitle', get_lang('GiveExerciseName'), 'required'); - if($type=='full') { + + if ($type=='full') { // rules $form->addRule('exerciseAttempts', get_lang('Numeric'), 'numeric'); $form->addRule('start_time', get_lang('InvalidDate'), 'date'); @@ -1105,7 +1124,7 @@ class Exercise { $defaults['randomQuestions'] = $this->random; } - $defaults['randomAnswers'] = $this ->selectRandomAnswers(); + $defaults['randomAnswers'] = $this->selectRandomAnswers(); $defaults['exerciseType'] = $this->selectType(); $defaults['exerciseTitle'] = $this->selectTitle(); $defaults['exerciseDescription'] = $this->selectDescription(); @@ -1116,7 +1135,8 @@ class Exercise { $defaults['review_answers'] = $this->review_answers; $defaults['randomByCat'] = $this->selectRandomByCat(); // $defaults['text_when_finished'] = $this->selectTextWhenFinished(); // - $defaults['display_category_name'] = $this->selectDisplayCategoryName(); // + $defaults['display_category_name'] = $this->selectDisplayCategoryName(); // + $defaults['pass_percentage'] = $this->selectPassPercentage(); if (($this->start_time!='0000-00-00 00:00:00')) $defaults['activate_start_date_check'] = 1; @@ -1146,6 +1166,7 @@ class Exercise { $defaults['start_time'] = date('Y-m-d 12:00:00'); $defaults['display_category_name'] = 1; // $defaults['end_time'] = date('Y-m-d 12:00:00',time()+84600); + $defaults['pass_percentage'] = ''; } } else { $defaults['exerciseTitle'] = $this->selectTitle(); @@ -1173,10 +1194,11 @@ class Exercise { $this->updateResultsDisabled($form->getSubmitValue('results_disabled')); $this->updateExpiredTime($form->getSubmitValue('enabletimercontroltotalminutes')); $this->updatePropagateNegative($form->getSubmitValue('propagate_neg')); - $this->updateRandomByCat($form->getSubmitValue('randomByCat')); // - $this->updateTextWhenFinished($form->getSubmitValue('text_when_finished')); // - $this->updateDisplayCategoryName($form->getSubmitValue('display_category_name')); // - $this->updateReviewAnswers($form->getSubmitValue('review_answers')); + $this->updateRandomByCat($form->getSubmitValue('randomByCat')); + $this->updateTextWhenFinished($form->getSubmitValue('text_when_finished')); + $this->updateDisplayCategoryName($form->getSubmitValue('display_category_name')); + $this->updateReviewAnswers($form->getSubmitValue('review_answers')); + $this->updatePassPercentage($form->getSubmitValue('pass_percentage')); if ($form->getSubmitValue('activate_start_date_check') == 1) { $start_time = $form->getSubmitValue('start_time'); diff --git a/main/exercice/exercise.lib.php b/main/exercice/exercise.lib.php index 5b19fb925e..a6b5829150 100644 --- a/main/exercice/exercise.lib.php +++ b/main/exercice/exercise.lib.php @@ -1187,7 +1187,7 @@ function get_exam_results_data($from, $number_of_items, $column, $direction, $ex * @param bool use or not the platform settings * @return string an html with the score modified */ -function show_score($score, $weight, $show_percentage = true, $use_platform_settings = true) { +function show_score($score, $weight, $show_percentage = true, $use_platform_settings = true, $show_success_message = false, $pass_percentage = null) { if (is_null($score) && is_null($weight)) { return '-'; } @@ -1205,15 +1205,25 @@ function show_score($score, $weight, $show_percentage = true, $use_platform_sett } $weight = $max_note; } - } + } $score_rounded = float_format($score, 1); $weight = float_format($weight, 1); + + $percentage = float_format(($score / ($weight != 0 ? $weight : 1)) * 100, 1); if ($show_percentage) { $parent = '(' . $score_rounded . ' / ' . $weight . ')'; - $html = float_format(($score / ($weight != 0 ? $weight : 1)) * 100, 1) . "% $parent"; + $html = $percentage." % $parent"; } else { $html = $score_rounded . ' / ' . $weight; } + + if ($show_success_message && isset($pass_percentage) && $pass_percentage != '') { + if ($percentage >= $pass_percentage) { + $html .= Display::return_message(get_lang('CongratulationsYouPassedTheTest'), 'success'); + } else { + $html .= Display::return_message(get_lang('YouDidNotReachTheMinimumScore'), 'warning'); + } + } return $html; } diff --git a/main/exercice/exercise_result.php b/main/exercice/exercise_result.php index 29c9fbe1c9..27795d5958 100644 --- a/main/exercice/exercise_result.php +++ b/main/exercice/exercise_result.php @@ -149,7 +149,7 @@ if ($show_results || $show_only_score) { echo $exercise_header = $objExercise->show_exercise_result_header(api_get_person_name($user_info['firstName'], $user_info['lastName'])); } -Display :: display_confirmation_message(get_lang('Saved').'