Annotation of loncom/homework/response.pm, revision 1.34

1.1       albertel    1: # The LearningOnline Network with CAPA
                      2: # various response type definitons response definition
                      3: 
1.7       www         4: # 11/23,11/24,11/28 Gerd Kortemeyer
1.33      www         5: # Guy Albertelli
                      6: # 08/04 Gerd Kortemeyer
1.5       www         7: 
1.1       albertel    8: package Apache::response;
                      9: use strict;
                     10: 
                     11: sub BEGIN {
1.31      albertel   12:   &Apache::lonxml::register('Apache::response',('responseparam','caparesponse','numericalresponse','stringresponse','radiobuttonresponse','optionresponse','imageresponse','essayresponse'));
1.1       albertel   13: }
                     14: 
1.13      albertel   15: sub start_response {
                     16:   my ($parstack,$safeeval)=@_;  
1.27      albertel   17:   my $id= &Apache::lonxml::get_param('id',$parstack,$safeeval);
1.13      albertel   18:   if ($id eq '') { $id = $Apache::lonxml::curdepth; }
                     19:   push (@Apache::inputtags::response,$id);
                     20:   push (@Apache::inputtags::responselist,$id);
                     21:   @Apache::inputtags::inputlist=();
                     22:   return $id;
                     23: }
                     24: 
                     25: sub end_response {
                     26:   pop @Apache::inputtags::response;
                     27:   @Apache::inputtags::inputlist=();
                     28:   return '';
                     29: }
                     30: 
1.26      albertel   31: # used by response to set the non-safe space random number generator to something
                     32: # that is stable and unique based on the part number and response number
                     33: sub setrandomnumber {
                     34:   my $rndseed=&Apache::lonnet::rndseed();
                     35:   &Apache::lonxml::debug("randseed $rndseed");
                     36: #  $rndseed=unpack("%32i",$rndseed);
                     37:   $rndseed=$rndseed
                     38:     +(&Apache::lonnet::numval($Apache::inputtags::part) << 10)
                     39:       +&Apache::lonnet::numval($Apache::inputtags::response['-1']);
                     40:   srand($rndseed);
                     41:   &Apache::lonxml::debug("randseed $rndseed");
                     42:   return '';
                     43: }
                     44: 
1.7       www        45: sub meta_parameter_write {
1.10      www        46:     my ($name,$type,$default,$display)=@_;
                     47:     return '<parameter part="'.$Apache::inputtags::part.
1.7       www        48: 	            '" name="'.$name.
                     49:                     '" type="'.$type.
                     50:                  '" default="'.$default.
1.10      www        51: 	         '" display="'.$display.
                     52:                           ' [Part: '.$Apache::inputtags::part.']"></parameter>'
1.33      www        53:      ."\n";
                     54: }
                     55: 
                     56: sub meta_package_write {
                     57:     my $name=shift;
                     58:     return '<parameter part="'.$Apache::inputtags::part.
                     59: 	         '" package="'.$name.'"></parameter>'
1.7       www        60:      ."\n";
                     61: }
                     62: 
                     63: sub meta_stores_write {
1.10      www        64:     my ($name,$type,$display)=@_;
                     65:     return '<stores part="'.$Apache::inputtags::part.
1.7       www        66: 	         '" name="'.$name.
                     67:                  '" type="'.$type.
1.10      www        68: 	      '" display="'.$display.
                     69:                        ' [Part: '.$Apache::inputtags::part.']"></stores>'
1.7       www        70:      ."\n";
                     71: }
                     72: 
                     73: sub mandatory_part_meta {
                     74: #
                     75: # Autogenerate metadata for mandatory
                     76: # input (from RAT or lonparmset) and 
                     77: # output (to lonspreadsheet)
                     78: # of each part
                     79: #
                     80:  return
1.34    ! www        81: #    &meta_parameter_write('opendate','date_start','',
        !            82: #                          'Opening Date').
        !            83: #    &meta_parameter_write('duedate','date_end','',
        !            84: #                          'Due Date').
        !            85: #    &meta_parameter_write('answerdate','date_start','',
        !            86: #                          'Show Answer Date').
        !            87: #    &meta_parameter_write('weight','int_zeropos','',
        !            88: #                          'Available Points').
        !            89: #    &meta_parameter_write('maxtries','int_pos','',
        !            90: #                          'Maximum Number of Tries').
        !            91:     &meta_package_write('part');
1.10      www        92:     &meta_stores_write('solved','string',
1.7       www        93:                           'Problem Status').
1.10      www        94:     &meta_stores_write('tries','int_zeropos',
1.24      albertel   95:                           'Number of Attempts').
1.10      www        96:     &meta_stores_write('awarded','float',
1.7       www        97: 		          'Partial Credit Factor');
                     98: #
                     99: # Note: responseid-specific data 'submission' and 'awarddetail'
                    100: # not available to spreadsheet -> skip here
                    101: #
1.14      albertel  102: }
                    103: 
1.15      albertel  104: sub check_for_previous {
1.32      albertel  105:   my ($curresponse,$partid,$id) = @_;
                    106:   my %previous;
                    107:   $previous{'used'} = 0;
                    108:   foreach my $key (reverse(sort(keys(%Apache::lonhomework::history)))) {
                    109:     if ($key =~ /resource\.$partid\.$id\.submission/) {
                    110:       &Apache::lonxml::debug("Trying $key");
                    111:       my $pastresponse=$Apache::lonhomework::history{$key};
                    112:       if ($pastresponse eq $curresponse) {
                    113: 	$previous{'used'} = 1;
                    114: 	my $history;
                    115: 	if ( $key =~ /^(\d+):/ ) {
                    116: 	  $history=$1;
                    117: 	  $previous{'award'} = $Apache::lonhomework::history{"$history:resource.$partid.$id.awarddetail"};
                    118: 	  $previous{'last'}='0';
                    119: 	} else {
                    120: 	  $previous{'award'} = $Apache::lonhomework::history{"resource.$partid.$id.awarddetail"};
                    121: 	  $previous{'last'}='1';
                    122: 	}
                    123: 	if (! $previous{'award'} ) { $previous{'award'} = 'UNKNOWN';	}
                    124: 	&Apache::lonxml::debug("got a match :$previous{'award'}:$previous{'used'}:");
                    125: 	last;
                    126:       }
                    127:     }
                    128:   }
                    129:   return %previous;
1.15      albertel  130: }
                    131: 
1.31      albertel  132: sub start_caparesponse {
1.14      albertel  133:   require Apache::caparesponse; 
                    134:   import Apache::caparesponse; 
1.28      albertel  135:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.31      albertel  136: #  print "\n<br />\nsimple caparesponse\n";
                    137:   return &Apache::caparesponse::start_caparesponse($target,$token,$tagstack,$parstack,$parser,$safeeval,$style);
                    138: }
                    139: 
                    140: sub start_stringresponse {
                    141:   require Apache::caparesponse;
                    142:   import Apache::caparesponse;
                    143:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                    144:   return &Apache::caparesponse::start_stringresponse($target,$token,$tagstack,$parstack,$parser,$safeeval,$style);
1.7       www       145: }
                    146: 
1.31      albertel  147: sub start_numericalresponse {
1.1       albertel  148:   require Apache::caparesponse; 
                    149:   import Apache::caparesponse; 
1.28      albertel  150:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.34    ! www       151:   if ($target eq 'meta') {
        !           152:       return &meta_package_write('numericalresponse');
        !           153:   } else {
        !           154:       return &Apache::caparesponse::start_numericalresponse
        !           155:              ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style);
        !           156:   }
1.16      albertel  157: }
                    158: 
                    159: sub start_radiobuttonresponse {
                    160:   require Apache::radiobuttonresponse; 
                    161:   import Apache::radiobuttonresponse; 
1.28      albertel  162:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                    163:   return &Apache::radiobuttonresponse::start_radiobuttonresponse($target,$token,$tagstack,$parstack,$parser,$safeeval,$style);
1.19      albertel  164: }
                    165: 
                    166: sub start_optionresponse {
                    167:   require Apache::optionresponse; 
                    168:   import Apache::optionresponse; 
1.28      albertel  169:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                    170:   return &Apache::optionresponse::start_optionresponse($target,$token,$tagstack,$parstack,$parser,$safeeval,$style);
1.21      albertel  171: }
                    172: 
                    173: sub start_imageresponse {
                    174:   require Apache::imageresponse; 
                    175:   import Apache::imageresponse; 
1.28      albertel  176:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                    177:   return &Apache::imageresponse::start_imageresponse($target,$token,$tagstack,$parstack,$parser,$safeeval,$style);
1.23      albertel  178: }
                    179: 
                    180: sub start_essayresponse {
                    181:   require Apache::essayresponse; 
                    182:   import Apache::essayresponse; 
1.28      albertel  183:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                    184:   return &Apache::essayresponse::start_essayresponse($target,$token,$tagstack,$parstack,$parser,$safeeval,$style);
1.3       albertel  185: }
                    186: 
                    187: sub start_responseparam {
1.28      albertel  188:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.20      albertel  189:   if ($target eq 'grade' || $target eq 'web') {
1.27      albertel  190:     my $default= &Apache::lonxml::get_param('default',$parstack,$safeeval);
                    191:     my $name= &Apache::lonxml::get_param('name',$parstack,$safeeval);
1.9       albertel  192:     &Apache::lonxml::debug("looking for resource.$Apache::inputtags::part.$name");
                    193:     my $value = &Apache::lonnet::EXT("resource.$Apache::inputtags::part.$name");
1.8       albertel  194:     &Apache::lonxml::debug("$name has value :$value: and default :$default:");
1.18      albertel  195:     if ($value eq '' || $value eq 'con_lost') {
                    196:       &Apache::lonxml::debug("defaulting");
1.8       albertel  197:       $Apache::inputtags::params{$name}=$default;
                    198:     } else {
1.11      albertel  199:       &Apache::lonxml::debug("using value");
1.8       albertel  200:       $Apache::inputtags::params{$name}=$value;
                    201:     }
                    202:     return '';
1.12      albertel  203:   } elsif ($target eq 'meta') {
1.10      www       204:     return &meta_parameter_write($token->[2]->{'name'},
1.8       albertel  205: 				 $token->[2]->{'type'},
                    206: 				 $token->[2]->{'default'},
                    207: 				 $token->[2]->{'description'});
1.29      albertel  208:   } elsif ($target eq 'edit') {
                    209:     my $result.=&Apache::edit::tag_start($target,$token,&Apache::lonxml::description($token));
                    210:     $result.=&Apache::edit::text_arg('Name:','name',$token).
                    211:       &Apache::edit::text_arg('Type:','type',$token).
                    212: 	&Apache::edit::text_arg('Description:','description',$token).
                    213: 	  &Apache::edit::text_arg('Default:','default',$token).
                    214: 	    "</td></tr>";
                    215:     $result.=&Apache::edit::end_table;
                    216:     return $result;
                    217:   } elsif ($target eq 'modified') {
                    218:     my $result;
                    219:     my $constructtag=&Apache::edit::get_new_args($token,$parstack,$safeeval,
                    220: 						 'name','type','description',
                    221: 						 'default');
1.30      albertel  222:     if ($constructtag) {
                    223:       $result = &Apache::edit::rebuild_tag($token);
                    224:       $result.=&Apache::edit::handle_insert();
                    225:     }
1.29      albertel  226:     return $result;
                    227: 
1.12      albertel  228:   } else {
                    229:     return '';
1.3       albertel  230:   }
                    231: }
                    232: 
                    233: sub end_responseparam {
1.29      albertel  234:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    235:   if ($target eq 'edit') { return ('','no'); }
1.25      albertel  236:   return '';
1.1       albertel  237: }
1.2       albertel  238: 
1.1       albertel  239: 1;
                    240: __END__
                    241:  

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>