Permalink
Browse files

MDL-25535 Testing default values when editing numerical options

  • Loading branch information...
1 parent 93b4ecb commit fe75941008c4c35d6764c8d744c60d5c27e06065 @ppichet ppichet committed Dec 3, 2010
Showing with 49 additions and 41 deletions.
  1. +49 −41 question/type/numerical/questiontype.php
@@ -134,7 +134,7 @@ function get_numerical_options(&$question) {
$question->options->showunits = $options->showunits;
$question->options->unitsleft = $options->unitsleft;
$question->options->instructions = $options->instructions;
- $question->options->instructionsformat = $options->instructionsformat;
+ $question->options->instructionsformat = $options->instructionsformat;
}
return true;
@@ -1091,7 +1091,7 @@ function add_units_elements(& $mform,& $that) {
$repeated[] =& $mform->createElement('text', 'multiplier', get_string('multiplier', 'quiz'));
$mform->setType('multiplier', PARAM_NUMBER);
- if (isset($that->question->options)){
+ if (isset($that->question->options->units)){
$countunits = count($that->question->options->units);
} else {
$countunits = 0;
@@ -1122,54 +1122,62 @@ function set_numerical_unit_data($mform, &$question, &$default_values){
$context = $this->get_context_by_category_id($categoryid);
if (isset($question->options)){
- $default_values['unitgradingtypes'] = 1 ;
- if ($question->options->unitgradingtype == 2 ) {
- $default_values['unitgradingtypes'] = 1 ;
- }
- if ($question->options->unitgradingtype == 0 ) {
- $default_values['unitgradingtypes'] = 0 ;
+ if (isset($question->options->unitpenalty)){
+ $default_values['unitpenalty'] = $question->options->unitpenalty ;
}
- $default_values['unitpenalty'] = $question->options->unitpenalty ;
- switch ($question->options->showunits){
- case 0 :// NUMERICALQUESTIONUNITTEXTINPUTDISPLAY
- if($question->options->unitgradingtype == 0 ){
- $default_values['unitrole'] = 2 ;
- $default_values['multichoicedisplay'] = 0 ;
- }else { // 1 or 2
+ $default_values['unitgradingtypes'] = 1 ;
+ if (isset($question->options->unitgradingtype )&& isset($question->options->showunits ) ){
+ if ( $question->options->unitgradingtype == 2 ) {
+ $default_values['unitgradingtypes'] = 1 ;
+ }
+ if ( $question->options->unitgradingtype == 0 ) {
+ $default_values['unitgradingtypes'] = 0 ;
+ }
+ switch ($question->options->showunits){
+ case 0 :// NUMERICALQUESTIONUNITTEXTINPUTDISPLAY
+ if($question->options->unitgradingtype == 0 ){
+ $default_values['unitrole'] = 2 ;
+ $default_values['multichoicedisplay'] = 0 ;
+ }else { // 1 or 2
+ $default_values['unitrole'] = 3 ;
+ $default_values['multichoicedisplay'] = 0 ;
+ $default_values['unitgradingtypes'] = $question->options->unitgradingtype ;
+ }
+ break;
+ case 1 : // NUMERICALQUESTIONUNITMULTICHOICEDISPLAY
$default_values['unitrole'] = 3 ;
- $default_values['multichoicedisplay'] = 0 ;
+ $default_values['multichoicedisplay'] = $question->options->unitgradingtype ;
$default_values['unitgradingtypes'] = $question->options->unitgradingtype ;
- }
- break;
- case 1 : // NUMERICALQUESTIONUNITMULTICHOICEDISPLAY
- $default_values['unitrole'] = 3 ;
- $default_values['multichoicedisplay'] = $question->options->unitgradingtype ;
- $default_values['unitgradingtypes'] = $question->options->unitgradingtype ;
- break;
- case 2 : // NUMERICALQUESTIONUNITTEXTDISPLAY
- $default_values['unitrole'] = 1 ;
- case 3 : // NUMERICALQUESTIONUNITNODISPLAY
- $default_values['unitrole'] = 0 ;
- // $default_values['showunits1'] = $question->options->showunits ;
- break;
+ break;
+ case 2 : // NUMERICALQUESTIONUNITTEXTDISPLAY
+ $default_values['unitrole'] = 1 ;
+ case 3 : // NUMERICALQUESTIONUNITNODISPLAY
+ $default_values['unitrole'] = 0 ;
+ // $default_values['showunits1'] = $question->options->showunits ;
+ break;
+ }
+ }
+ if (isset($question->options->unitsleft)){
+ $default_values['unitsleft'] = $question->options->unitsleft ;
}
- $default_values['unitsleft'] = $question->options->unitsleft ;
// processing files
$component = 'qtype_' . $question->qtype;
$draftid = file_get_submitted_draft_itemid('instruction');
$default_values['instructions'] = array();
- $default_values['instructions']['format'] = $question->options->instructionsformat;
- $default_values['instructions']['text'] = file_prepare_draft_area(
- $draftid, // draftid
- $context->id, // context
- $component, // component
- 'instruction', // filarea
- !empty($question->id)?(int)$question->id:null, // itemid
- $mform->fileoptions, // options
- $question->options->instructions // text
- );
- $default_values['instructions']['itemid'] = $draftid;
+ if (isset($question->options->instructionsformat) && isset($question->options->instructions)){
+ $default_values['instructions']['format'] = $question->options->instructionsformat;
+ $default_values['instructions']['text'] = file_prepare_draft_area(
+ $draftid, // draftid
+ $context->id, // context
+ $component, // component
+ 'instruction', // filarea
+ !empty($question->id)?(int)$question->id:null, // itemid
+ $mform->fileoptions, // options
+ $question->options->instructions // text
+ );
+ }
+ $default_values['instructions']['itemid'] = $draftid ;
if (isset($question->options->units)) {
$units = array_values($question->options->units);

0 comments on commit fe75941

Please sign in to comment.