Skip to content

Commit

Permalink
MDL-24503 recoding unit grading options
Browse files Browse the repository at this point in the history
  • Loading branch information
ppichet committed Oct 30, 2010
1 parent 122416d commit 92b3600
Show file tree
Hide file tree
Showing 4 changed files with 558 additions and 315 deletions.
210 changes: 128 additions & 82 deletions question/type/numerical/display.html
Expand Up @@ -17,11 +17,20 @@
<div class="answer">
<fieldset class="answer" id="generalheader">
<legend class="ftoggler">
<?php echo get_string('datasetnumber', 'quiz') ; ?>
<?php
echo $OUTPUT->help_icon('validnumberformats', 'qtype_numerical', '');
echo get_string('datasetnumber', 'quiz') ;
?>
</legend>
<input type="text" class="<?php echo $class; ?>" <?php echo "$readonly $nameanswer $valueanswer"; //
?> size="<?php echo $textlength;?>" />
<?php echo $feedbackimg; ?>
<?php echo $feedbackimg;
if(! $answerasterisk && $question->options->unitgradingtype != 0 && $unit_in_numerical_answer){
print_string('nonvalidcharactersinnumber', 'qtype_numerical');
}


?>
</fieldset>
</div>

Expand All @@ -44,27 +53,37 @@
<div class="answer numerical ">
<fieldset class="clearfix" id="generalheader">
<legend class="ftoggler">
<?php echo get_string('unit', 'quiz'); ?>
<?php
if ( $question->options->unitgradingtype == 0 ){
echo $OUTPUT->help_icon('unitoptional', 'qtype_numerical', '');
}else { // unitgradingtype == 1
echo $OUTPUT->help_icon('unitmandatory', 'qtype_numerical', '');
}
echo get_string('unit', 'quiz'); ?>
</legend>
<input type="text" class="<?php echo $classunit; ?>" <?php echo "$readonly $nameunit $valueunit"; //
?> size="<?php echo $textlength;?>"/>
<?php echo $feedbackimgunit;
if ($options->feedback && $classunitvalue == 0 && ! $answerasterisk ){
if(isset($question->options->units) && count($question->options->units) > 0){
$found = 0 ;
foreach($question->options->units as $key => $unit){
if($state->responses['unit'] == $unit->unit){
print_string('unitnotvalid', 'qtype_numerical');
$found = 1 ;
break;
if ($options->feedback && $question->options->unitgradingtype == 1 && ! $valid_numerical_unit && ! $answerasterisk ){
if ( $empty_unit) {
print_string('unitmandatory', 'qtype_numerical');
}else {
if(isset($question->options->units) && count($question->options->units) > 0){
$found = 0 ;
$valid_unit_found = 0 ;
foreach($question->options->units as $key => $unit){
if($state->responses['unit'] == $unit->unit){
print_string('unitnotvalid', 'qtype_numerical');
$valid_unit_found = 1 ;
break;
}
}
if ($valid_unit_found == 0) {
print_string('unitunknown', 'qtype_numerical');
}
}
if ($found == 0) {
print_string('unitunknown', 'qtype_numerical');
}
}
}

?>
</fieldset>
</div>
Expand Down Expand Up @@ -106,65 +125,98 @@
<div class="answer">
<fieldset class="clearfix" id="generalheader">
<legend class="ftoggler">
<?php echo get_string('unit', 'quiz');
<?php
echo get_string('selectunit', 'qtype_numerical');
?>
</legend>
<!-- <div class="que multichoice clearfix">
<div class="content"> class="answer"
<div class="ablock clearfix"> -->
<table >
<table >

<?php
// the order is not shuffled
//however the unitvalue is related to the number value
// if the response/unit->multiplier is true then
// the

// if(isset($state->responses['unit']) && $state->responses['unit'] != '' ){
$valid_numerical_unit_index = -1;
foreach ($question->options->units as $key => $unit) {
$checked = '';
$chosen = false;
$classunitvalue = 0 ;
$checked = '';
$chosen = false;
$classunit = 0 ;
$feedbackimgunit = question_get_feedback_image(0);
$valid_numerical_unit = false ;
$validunit = false ;
$type = 'type="radio"';
// $nameunit = "name=\"".$question->name_prefix;//."unit\"";
if ($response != '' && isset($state->responses['unit']) && $state->responses['unit'] != '' ){
// we have a unit response
// this unit is the one chosen
// test if the unit give a valid response
$testresponse = $response /$unit->multiplier ;
if($answerasterisk || ($answer->min <= $testresponse && $testresponse <= $answer->max)) {
$classunitvalue = $answer->fraction ;
}
// echo "<p> dans display classunitvalue $classunitvalue response $response $unit->multiplier $unit->unit state <pre>";print_r($answer);echo "</pre></p>";
if ($state->responses['unit'] == $unit->unit) {
$checked = 'checked="checked"';
$chosen = true;

// echo "<p> boucle unit $key $unit->unit answerfraction $answer->fraction classunit $classunit index $valid_numerical_unit_index $key response $response $unit->multiplier $unit->unit state <pre>";print_r($answer);echo "</pre></p>";
if(isset($state->responses['unit']) && $state->responses['unit'] != '' ){
// $nameunit = "name=\"".$question->name_prefix;//."unit\"";
// if (isset($response->number) && $response->number != false && isset($state->responses['unit']) && $state->responses['unit'] != '' ){
// if ($unit->unit == $state->responses['unit']){
// test if the numerical value as is or as multiplied by this unit
// could give a good response
// we need to extract the numerical and apply it with this unit
// as if it was used
$testresponse = $state->responses['answer']/$unit->multiplier ;
/* if(isset($state->responses['unit'])){
$testresponse .= $state->responses['unit'] ;
} */
$response = $this->apply_unit($testresponse, array($question->options->units[$key])) ;
$invalid_unit_found = 0 ;
if ($response !== false) {
$this->get_tolerance_interval($answer);
if($answer->min <= $response && $response <= $answer->max){
// then it could give a good response
// has it been used ?
$classunit = 1; // or max response i.e. 1
$feedbackimgunit = question_get_feedback_image($rawgrade);
$valid_numerical_unit = true ;
$validunit = true ;

$valid_numerical_unit_index = $key ;
}
}
}else if ($key == 0) {
}
// if ($unit->unit == $state->responses['unit']){
// we have a valid unit response
if($answerasterisk || $valid_numerical_unit_index == $key ){
$classunit = $rawgrade ; //question_get_feedback_class(1) ; // ;
}
// we have a unit response
// this unit is the one chosen
// test if the unit give a valid response
// $testresponse = $response->number /$unit->multiplier ;
// if($answerasterisk || ($answer->min <= $testresponse && $testresponse <= $answer->max)) {
// $classunitvalue = $answer->fraction ;
// }
// echo "<p> dans display $answer->fraction classunit $classunit index $valid_numerical_unit_index $key response $response $unit->multiplier $unit->unit state <pre>";print_r($answer);echo "</pre></p>";
// if ($state->responses['unit'] == $unit->unit) {
if (isset($state->responses['unit']) && $unit->unit == $state->responses['unit']){
$checked = 'checked="checked"';
$chosen = true;
}else {
$checked = '';
}

$aid = $question->id ;
$a = new stdClass;
$a->id = $question->name_prefix."unit" ;//. "2"
$a->class = '' ;
$a->feedbackimg = '';

$a->control = "<input $readonly $nameunit $checked $type value=\"$key\" />";

if ($options->correct_responses && $classunitvalue > 0 ) { //$answer->fraction
$a->class = question_get_feedback_class($classunitvalue);
}
if (($options->feedback && $chosen) || $options->correct_responses) {
$a->feedbackimg = question_get_feedback_image($classunitvalue, $chosen && $options->feedback);
}

// Print the control
// Print the answer text
$a->text = format_text($unit->unit, FORMAT_MOODLE, $formatoptions, $cmoptions->course);
$row = 0 ;



$aid = $question->id ;
$a = new stdClass;
$a->id = $question->name_prefix."unit" ;//. "2"
$a->class = '' ;
$a->feedbackimg = '';

$a->control = "<input $readonly $nameunit $checked $type value=\"$key\" />";

if ($options->correct_responses && $classunit > 0 ) { //$answer->fraction
$a->class = question_get_feedback_class($classunit);
}
if (($options->feedback && $chosen) || $options->correct_responses) {
$a->feedbackimg = question_get_feedback_image($classunit, $chosen && $options->feedback);
}

// Print the control
// Print the answer text
$a->text = format_text($unit->unit, FORMAT_MOODLE, $formatoptions, $cmoptions->course);
$row = 0 ;

?>
<tr class="<?php echo 'r'.$row = $row ? 0 : 1; ?>">
<td class="c0 control " style=" ">
Expand All @@ -174,22 +226,24 @@
<label for="<?php echo $a->id ?>">
<?php echo $a->text.'<br />'; ?>
<?php echo $a->feedbackimg;
if ($options->feedback && $classunitvalue == 0 && $chosen && !$answerasterisk){
if ($options->feedback && $classunit == 0 && $chosen && !$answerasterisk){
print_string('unitnotvalid', 'qtype_numerical');
}else {
echo '&nbsp;&nbsp;&nbsp;';
}
?>
</label>
</td>
</tr>
<?php } ?>

</table>
<!-- </div>
</div>
</div> -->
</fieldset>


<?php if ($options->feedback && isset($state->responses['answer'])&& $state->responses['answer'] != '' && (!isset($state->responses['unit']) || $state->responses['unit'] == '') && ! $answerasterisk ){

print_string('unitnotselected', 'qtype_numerical');
}
?>

</fieldset>
</div>
<?php } // end unit choices
// display intructions
Expand All @@ -201,7 +255,10 @@
<div class="answer">
<fieldset class="clearfix" id="generalheader">
<legend class="ftoggler">
<?php echo get_string('datasetnumber', 'quiz'); ?>
<?php
echo $OUTPUT->help_icon('validnumberformats', 'qtype_numerical', '');
echo get_string('datasetnumber', 'quiz');
?>
</legend>
<input type="text" class="<?php echo $class; ?>" <?php echo "$readonly $nameanswer $valueanswer"; //
?> size="<?php echo $textlength;?>"/>
Expand All @@ -215,29 +272,18 @@
</div>


<?php if (!empty($question->options->instructions)){?>
<div class="feedback">
<fieldset class="clearfix" id="generalheader">
<legend class="ftoggler">
<?php echo get_string('instructions', 'auth'); ?>
</legend>
<div class="feedback">
<fieldset class="clearfix" id="generalheader">
<legend class="ftoggler">
<?php echo get_string('validnumberformats', 'qtype_numerical');?>
</legend>
<?php echo get_string('validnumbers', 'qtype_numerical');

?>

</fieldset>
</div>
<?php if (!empty($question->options->instructions)){?>
<div>
<?php echo format_text($question->options->instructions, $question->options->instructionsformat, $formatoptions, $cmoptions->course);?>
</div>
<?php }?>
</fieldset>
</div>
<?php }?>

<?php if ($feedback) { ?>
<div class="feedback">
Expand Down
9 changes: 0 additions & 9 deletions question/type/numerical/edit_numerical_form.php
Expand Up @@ -86,15 +86,6 @@ function data_preprocessing($question) {
}
$QTYPES['numerical']->set_numerical_unit_data($this, $question, $default_values);

/* if (isset($question->options->units)){
$units = array_values($question->options->units);
if (!empty($units)) {
foreach ($units as $key => $unit){
$default_values['unit['.$key.']'] = $unit->unit;
$default_values['multiplier['.$key.']'] = $unit->multiplier;
}
}
}*/
$question = (object)((array)$question + $default_values);
}
return $question;
Expand Down
49 changes: 45 additions & 4 deletions question/type/numerical/lang/en/qtype_numerical.php
Expand Up @@ -37,6 +37,7 @@
$string['instructions'] = 'Instructions ';
$string['leftexample'] = 'LEFT as $1.00';
$string['noneditableunittext'] = 'NON editable text of Unit No1';
$string['nonvalidcharactersinnumber'] = 'NON valid characters in number';
$string['notenoughanswers'] = 'You must enter at least one answer.';
$string['nounitdisplay'] = 'No unit grading';
$string['numerical'] = 'Numerical';
Expand All @@ -56,22 +57,62 @@
If you add the unit kW with a multiplier of 0.001, this will add a correct response of 5.5 kW. This means that the answers 5500W or 5.5kW would be marked correct.
Note that the accepted error is also multiplied, so an allowed error of 100W would become an error of 0.1kW.';
$string['onlynumerical'] = 'Only NUMERICAL ANSWER will be graded';
$string['manynumerical'] = 'Only the NUMERICAL ANSWER will be graded using optional units ';
$string['onlynumerical'] = 'Only the NUMERICAL ANSWER will be graded, no units allowed';
$string['oneunitshown'] = 'Only the NUMERICAL ANSWER will be graded, Unit1 will be shown';
$string['rightexample'] = 'RIGHT as 1.00cm';
$string['selectunits'] = 'Select units';
$string['selectunit'] = 'Select one unit';
$string['studentunitanswer'] = 'UNIT ANSWER displayed as a ';
$string['unitchoice'] = 'Multichoice (radio elements)';
$string['unitdisplay'] = 'Display Unit1';
$string['unitdisplay'] = '<STRONG>Unit 1 displayed </STRONG>';
$string['unitedit'] = 'Edit unit';
$string['unitgraded'] = ' NUMERICAL ANSWER and UNIT ANSWER will be graded ';
$string['unitgraded'] = ' NUMERICAL ANSWER and UNIT ANSWER will be graded ';
$string['unitgraded1'] = '<STRONG>UNIT GRADED</STRONG>';
$string['unitsused'] = '<STRONG>UNIT USED</STRONG>';
$string['unithdr'] = 'Unit {$a}';
$string['unitmandatory'] = 'Mandatory';
$string['unitmandatory_help'] = '
* The response will be graded using the unit written.
* The unit penalty will be applied if the unit field is empty
';
$string['unitnotgraded'] = '<STRONG>UNIT NOT GRADED</STRONG>';
$string['unitnotused'] = '<STRONG>UNIT NOT USED</STRONG>';
$string['unitoptional'] = 'Optional unit';
$string['unitoptional_help'] = '
* If the unit field is not empty, the response will be graded using this unit.
* If the unit is badly written or unknown, the response will be considered as non valid.
';
$string['unitused'] = '<STRONG>UNIT USED</STRONG>';
$string['unituses'] = 'Unit uses';
$string['unituses_help'] = 'The unit(s) are uses as in pre 2,0 Moodle version
* The student can answer using units predefined by the teacher
* in which case the constant will be applied to the student value.
* If the student does not add any unit, his numerical answer is used as is.';
$string['unitnotvalid'] = ' Unit not valid with this numerical value';
$string['unitunknown'] = ' Undefined unit ';
$string['unitpenalty'] = 'Penalty for bad unit';
$string['unitpenalty'] = 'Unit penalty';
$string['unitpenalty_help'] = 'The penalty is applied if
* An undefined unit name is put in the Unit answer element or
* An unit name is put in the Number answer element ';
$string['unitappliedpenalty'] = 'These marks include a penalty of {$a} for bad unit.';
$string['unitposition'] = 'Unit position';
$string['unitnotselected'] = 'No unit selected';
$string['unitshandling'] = 'Units handling';
$string['validnumberformats'] = 'Valid number formats';
$string['validnumberformats_help'] = '
* regular numbers 13500.67 : 13 500.67 : 13500,67: 13 500,67
* if you use , as thousand separator *always* put the decimal . as in
13,500.67 : 13,500.
* for exponent form, say 1.350067 * 10<sup>4</sup>, use
1.350067 E4 : 1.350067 E04 ';

$string['validnumbers'] = ' 13500.67 : 13 500.67 : 13,500.67 : 13500,67: 13 500,67 : 1.350067 E4 : 1.350067 E04 ';

0 comments on commit 92b3600

Please sign in to comment.