Adding propagate_neg feature

skala
Julio Montoya 15 years ago
parent ea4bacb44a
commit d53e9eb55b
  1. 32
      main/exercice/exercise.class.php
  2. 7
      main/exercice/exercise_result.php
  3. 7
      main/exercice/exercise_show.php

@ -39,6 +39,7 @@ class Exercise {
public $results_disabled; public $results_disabled;
public $expired_time; public $expired_time;
public $course; public $course;
public $propagate_neg;
/** /**
@ -61,6 +62,7 @@ class Exercise {
$this->start_time = '0000-00-00 00:00:00'; $this->start_time = '0000-00-00 00:00:00';
$this->results_disabled = 1; $this->results_disabled = 1;
$this->expired_time = '0000-00-00 00:00:00'; $this->expired_time = '0000-00-00 00:00:00';
$this->propagate_neg = 0;
if (!empty($course_id)) { if (!empty($course_id)) {
$this->course_id = intval($course_id); $this->course_id = intval($course_id);
@ -85,7 +87,7 @@ class Exercise {
$TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION,$this->course['db_name']); $TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION,$this->course['db_name']);
#$TBL_REPONSES = Database::get_course_table(TABLE_QUIZ_ANSWER); #$TBL_REPONSES = Database::get_course_table(TABLE_QUIZ_ANSWER);
$sql="SELECT title,description,sound,type,random, random_answers, active, results_disabled, max_attempt,start_time,end_time,feedback_type,expired_time FROM $TBL_EXERCICES WHERE id='".Database::escape_string($id)."'"; $sql="SELECT title,description,sound,type,random, random_answers, active, results_disabled, max_attempt,start_time,end_time,feedback_type,expired_time,propagate_neg FROM $TBL_EXERCICES WHERE id='".Database::escape_string($id)."'";
$result=Database::query($sql); $result=Database::query($sql);
// if the exercise has been found // if the exercise has been found
@ -101,6 +103,7 @@ class Exercise {
$this->results_disabled = $object->results_disabled; $this->results_disabled = $object->results_disabled;
$this->attempts = $object->max_attempt; $this->attempts = $object->max_attempt;
$this->feedbacktype = $object->feedback_type; $this->feedbacktype = $object->feedback_type;
$this->propagate_neg = $object->propagate_neg;
if ($object->end_time != '0000-00-00 00:00:00') { if ($object->end_time != '0000-00-00 00:00:00') {
$this->end_time = api_get_local_time($object->end_time); $this->end_time = api_get_local_time($object->end_time);
@ -110,6 +113,8 @@ class Exercise {
} }
$this->expired_time = $object->expired_time; //control time $this->expired_time = $object->expired_time; //control time
$sql="SELECT question_id, question_order FROM $TBL_EXERCICE_QUESTION, $TBL_QUESTIONS WHERE question_id=id AND exercice_id='".Database::escape_string($id)."' ORDER BY question_order"; $sql="SELECT question_id, question_order FROM $TBL_EXERCICE_QUESTION, $TBL_QUESTIONS WHERE question_id=id AND exercice_id='".Database::escape_string($id)."' ORDER BY question_order";
$result=Database::query($sql); $result=Database::query($sql);
@ -284,6 +289,10 @@ class Exercise {
return sizeof($this->questionList); return sizeof($this->questionList);
} }
function selectPropagateNeg() {
return $this->propagate_neg;
}
/** /**
* Selects questions randomly in the question list * Selects questions randomly in the question list
* *
@ -380,6 +389,10 @@ class Exercise {
$this->expired_time = $expired_time; $this->expired_time = $expired_time;
} }
function updatePropagateNegative($value) {
$this->propagate_neg = $value;
}
/** /**
* changes the exercise sound file * changes the exercise sound file
* *
@ -514,6 +527,7 @@ class Exercise {
$random = $this->random; $random = $this->random;
$random_answers = $this->random_answers; $random_answers = $this->random_answers;
$active = $this->active; $active = $this->active;
$propagate_neg = $this->propagate_neg;
$session_id = api_get_session_id(); $session_id = api_get_session_id();
if ($feedbacktype==1){ if ($feedbacktype==1){
@ -542,6 +556,7 @@ class Exercise {
start_time='$start_time',end_time='$end_time', start_time='$start_time',end_time='$end_time',
max_attempt='".Database::escape_string($attempts)."', max_attempt='".Database::escape_string($attempts)."',
expired_time='".Database::escape_string($expired_time)."', expired_time='".Database::escape_string($expired_time)."',
propagate_neg='".Database::escape_string($propagate_neg)."',
results_disabled='".Database::escape_string($results_disabled)."'"; results_disabled='".Database::escape_string($results_disabled)."'";
} }
$sql .= " WHERE id='".Database::escape_string($id)."'"; $sql .= " WHERE id='".Database::escape_string($id)."'";
@ -958,6 +973,9 @@ class Exercise {
$diplay = 'block'; $diplay = 'block';
} }
$form -> addElement('checkbox', 'propagate_neg',get_lang('PropagetNegativeResult'),null);
$form -> addElement('html','<div id="divtimecontrol" style="display:'.$diplay.';">'); $form -> addElement('html','<div id="divtimecontrol" style="display:'.$diplay.';">');
//Timer control //Timer control
@ -976,6 +994,9 @@ class Exercise {
$form -> addElement('html','</div>'); $form -> addElement('html','</div>');
//$form -> addElement('text', 'exerciseAttempts', get_lang('ExerciseAttempts').' : ',array('size'=>'2')); //$form -> addElement('text', 'exerciseAttempts', get_lang('ExerciseAttempts').' : ',array('size'=>'2'));
$form -> addElement('html','</div>'); //End advanced setting $form -> addElement('html','</div>'); //End advanced setting
$form -> addElement('html','</div>'); $form -> addElement('html','</div>');
@ -1036,6 +1057,7 @@ class Exercise {
$defaults['exerciseAttempts'] = $this->selectAttempts(); $defaults['exerciseAttempts'] = $this->selectAttempts();
$defaults['exerciseFeedbackType'] = $this->selectFeedbackType(); $defaults['exerciseFeedbackType'] = $this->selectFeedbackType();
$defaults['results_disabled'] = $this->selectResultsDisabled(); $defaults['results_disabled'] = $this->selectResultsDisabled();
$defaults['propagate_neg'] = $this->selectPropagateNeg();
if(($this -> start_time!='0000-00-00 00:00:00')||($this -> end_time!='0000-00-00 00:00:00')) if(($this -> start_time!='0000-00-00 00:00:00')||($this -> end_time!='0000-00-00 00:00:00'))
$defaults['enabletimelimit'] = 1; $defaults['enabletimelimit'] = 1;
@ -1091,6 +1113,8 @@ class Exercise {
$this -> updateResultsDisabled($form -> getSubmitValue('results_disabled')); $this -> updateResultsDisabled($form -> getSubmitValue('results_disabled'));
$this -> updateExpiredTime($form -> getSubmitValue('enabletimercontroltotalminutes')); $this -> updateExpiredTime($form -> getSubmitValue('enabletimercontroltotalminutes'));
$this -> updatePropagateNegative($form -> getSubmitValue('propagate_neg'));
if($form -> getSubmitValue('enabletimelimit')==1) { if($form -> getSubmitValue('enabletimelimit')==1) {
$start_time = $form -> getSubmitValue('start_time'); $start_time = $form -> getSubmitValue('start_time');
$this->start_time = $start_time['Y'].'-'.$start_time['F'].'-'.$start_time['d'].' '.$start_time['H'].':'.$start_time['i'].':00'; $this->start_time = $start_time['Y'].'-'.$start_time['F'].'-'.$start_time['d'].' '.$start_time['H'].':'.$start_time['i'].':00';
@ -1657,7 +1681,7 @@ class Exercise {
* @todo reduce parameters of this function * @todo reduce parameters of this function
* @return string html code * @return string html code
*/ */
function manage_answer($exeId, $questionId, $choice, $from = 'exercise_show', $exerciseResultCoordinates = array(), $saved_results = true, $from_database = false, $show_result = true) { function manage_answer($exeId, $questionId, $choice, $from = 'exercise_show', $exerciseResultCoordinates = array(), $saved_results = true, $from_database = false, $show_result = true, $propagate_neg = 0) {
global $_configuration, $feedback_type; global $_configuration, $feedback_type;
$questionId = intval($questionId); $questionId = intval($questionId);
@ -2341,6 +2365,10 @@ class Exercise {
if ($questionScore==-1) { if ($questionScore==-1) {
echo get_lang('Score').": 0 /".float_format($questionWeighting); echo get_lang('Score').": 0 /".float_format($questionWeighting);
} else { } else {
if ($propagate_neg && $questionScore < 0) {
$questionScore = 0;
}
echo get_lang('Score').": ".float_format($questionScore,1)."/".float_format($questionWeighting,1); echo get_lang('Score').": ".float_format($questionScore,1)."/".float_format($questionWeighting,1);
} }
echo '</div>'; echo '</div>';

@ -303,7 +303,7 @@ foreach ($questionList as $questionId) {
} }
// We're inside *one* question. Go through each possible answer for this question // We're inside *one* question. Go through each possible answer for this question
$result = $objExercise->manage_answer($exeId, $questionId, $choice,'exercise_result', $exerciseResultCoordinates, true); $result = $objExercise->manage_answer($exeId, $questionId, $choice,'exercise_result', $exerciseResultCoordinates, true, false, true, $objExercise->selectPropagateNeg());
$totalScore += $result['score']; $totalScore += $result['score'];
$totalWeighting += $result['weight']; $totalWeighting += $result['weight'];
@ -315,7 +315,10 @@ if($origin != 'learnpath') {
if ($dsp_percent) { if ($dsp_percent) {
echo number_format(($totalScore/$totalWeighting)*100,1,'.','')."%"; echo number_format(($totalScore/$totalWeighting)*100,1,'.','')."%";
} else { } else {
echo float_format($totalScore,1)."/".float_format($totalWeighting,1); if ($objExercise->selectPropagateNeg() && $totalScore < 0) {
$totalScore = 0;
}
echo show_score($totalScore, $totalWeighting, false);
} }
echo '</div>'; echo '</div>';
?> ?>

@ -584,6 +584,10 @@ if ($show_results) {
$my_total_weight = convert_score($questionWeighting, $total_weighting); $my_total_weight = convert_score($questionWeighting, $total_weighting);
echo '<div id="question_score">'; echo '<div id="question_score">';
if ($objExercise->selectPropagateNeg() && $my_total_score < 0) {
$my_total_score = 0;
}
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 get_lang('Score')." : ".show_score($my_total_score, $total_weighting, false);
echo '</div>'; echo '</div>';
@ -604,6 +608,9 @@ if ($origin!='learnpath' || ($origin == 'learnpath' && isset($_GET['fb_type'])))
$my_result = float_format($my_result,1); $my_result = float_format($my_result,1);
echo $my_result."%"; echo $my_result."%";
} else { } else {
if ($objExercise->selectPropagateNeg() && $totalScore < 0) {
$totalScore = 0;
}
echo show_score($totalScore, $totalWeighting, false); echo show_score($totalScore, $totalWeighting, false);
} }
echo '</div>'; echo '</div>';

Loading…
Cancel
Save