Adding pass_percentage funcionality in exercises see #4541

skala
Julio Montoya 14 years ago
parent 7880f49799
commit dafd37e8bf
  1. 132
      main/exercice/exercise.class.php
  2. 16
      main/exercice/exercise.lib.php
  3. 7
      main/exercice/exercise_result.php
  4. 5
      main/exercice/result.php
  5. 5
      main/inc/lib/add_course.lib.inc.php
  6. 11
      main/install/migrate-db-1.8.8-1.9.0-pre.sql

@ -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','<div id="timercontrol" style="display:none;">');
}
$form->addElement('text', 'enabletimercontroltotalminutes',get_lang('ExerciseTotalDurationInMinutes'),array('style' => 'width : 35px','id' => 'enabletimercontroltotalminutes'));
$form->addElement('html','</div>');
//$form->addElement('text', 'enabletimercontroltotalminutes',get_lang('ExerciseTotalDurationInMinutes'),array('style' => 'width : 35px','id' => 'enabletimercontroltotalminutes'));
$form->addElement('html','</div>');
//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');

@ -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;
}

@ -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').'<br />',false);
Display :: display_normal_message(get_lang('Saved').'<br />',false);
// Display text when test is finished #4074
// Don't display the text when finished message if we are from a LP #4227
@ -161,6 +161,8 @@ if (!empty($end_of_message) && ($origin != 'learnpath')) {
}
$counter = 1;
$total_score = $total_weight = 0;
// Loop over all question to show results for each of them, one by one
if (!empty($question_list)) {
foreach ($question_list as $questionId) {
@ -200,7 +202,7 @@ if ($origin != 'learnpath') {
if ($objExercise->selectPropagateNeg() == 0 && $total_score < 0) {
$total_score = 0;
}
echo show_score($total_score, $total_weight, false);
echo show_score($total_score, $total_weight, false, true, true, $objExercise->selectPassPercentage());
echo '</div>';
}
/* <button type="submit" class="save"><?php echo get_lang('Finish');?></button> */
@ -217,7 +219,6 @@ 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(), $safe_lp_id, $safe_lp_item_id, $safe_lp_item_view_id, $quiz_duration, $question_list, '');
}
//If is not valid
$session_control_key = get_session_time_control_key($objExercise->id);
if (isset($session_control_key) && !exercise_time_control_is_valid($objExercise->id)) {

@ -341,8 +341,7 @@ if (!empty($question_list)) {
echo '<b>'.get_lang('Feedback').'</b>';
echo '<div id="question_feedback">'.$comnt.'</div>';
}
}
}
$my_total_score = $questionScore;
$my_total_weight = $questionWeighting;
@ -370,7 +369,7 @@ if ($show_results || $show_only_total_score) {
if ($objExercise->selectPropagateNeg() == 0 && $my_total_score_temp < 0) {
$my_total_score_temp = 0;
}
echo show_score($my_total_score_temp, $totalWeighting, false);
echo show_score($my_total_score_temp, $totalWeighting, false, true, true, $objExercise->selectPassPercentage());
echo '</div>';
}

@ -705,7 +705,7 @@ function update_Db_course($course_db_name = null) {
random smallint(6) NOT NULL default 0,
random_answers tinyint unsigned NOT NULL default 0,
active tinyint NOT NULL default 0,
results_disabled TINYINT UNSIGNED NOT NULL DEFAULT 0,
results_disabled INT UNSIGNED NOT NULL DEFAULT 0,
access_condition TEXT DEFAULT NULL,
max_attempt int NOT NULL default 0,
start_time datetime NOT NULL default '0000-00-00 00:00:00',
@ -717,7 +717,8 @@ function update_Db_course($course_db_name = null) {
review_answers INT NOT NULL DEFAULT 0,
random_by_category INT NOT NULL DEFAULT 0,
text_when_finished TEXT default NULL,
display_category_name TINYINT NOT NULL DEFAULT 1,
display_category_name INT NOT NULL DEFAULT 1,
pass_percentage INT DEFAULT NULL,
PRIMARY KEY (c_id, id)
)" . $charset_clause;
Database::query($sql);

@ -183,13 +183,14 @@ ALTER TABLE track_e_attempt ADD COLUMN filename VARCHAR(255) DEFAULT NULL;
-- xxUSERxx
-- xxCOURSExx
ALTER TABLE lp ADD COLUMN hide_toc_frame TINYINT NOT NULL DEFAULT 0;
ALTER TABLE lp ADD COLUMN seriousgame_mode TINYINT NOT NULL DEFAULT 0;
ALTER TABLE lp ADD COLUMN hide_toc_frame INT NOT NULL DEFAULT 0;
ALTER TABLE lp ADD COLUMN seriousgame_mode INT NOT NULL DEFAULT 0;
ALTER TABLE lp_item_view modify column suspend_data longtext;
INSERT INTO course_setting(variable,value,category) VALUES ('course_grading_model','','gradebook');
INSERT INTO course_setting(variable, value, category) VALUES ('course_grading_model','','gradebook');
ALTER TABLE quiz ADD COLUMN review_answers INT NOT NULL DEFAULT 0;
ALTER TABLE student_publication ADD COLUMN contains_file INTEGER NOT NULL DEFAULT 1;
ALTER TABLE student_publication ADD COLUMN allow_text_assignment INTEGER NOT NULL DEFAULT 0;
ALTER TABLE quiz ADD COLUMN random_by_category INT NOT NULL DEFAULT 0;
ALTER TABLE quiz ADD text_when_finished TEXT default NULL;
ALTER TABLE quiz ADD display_category_name TINYINT NOT NULL DEFAULT 1;
ALTER TABLE quiz ADD COLUMN text_when_finished TEXT DEFAULT NULL;
ALTER TABLE quiz ADD COLUMN display_category_name INT NOT NULL DEFAULT 1;
ALTER TABLE quiz ADD COLUMN pass_percentage INT DEFAULT NULL;
Loading…
Cancel
Save