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

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.35    ! albertel  151:   return &Apache::caparesponse::start_numericalresponse
        !           152:     ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style);
1.16      albertel  153: }
                    154: 
                    155: sub start_radiobuttonresponse {
                    156:   require Apache::radiobuttonresponse; 
                    157:   import Apache::radiobuttonresponse; 
1.28      albertel  158:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                    159:   return &Apache::radiobuttonresponse::start_radiobuttonresponse($target,$token,$tagstack,$parstack,$parser,$safeeval,$style);
1.19      albertel  160: }
                    161: 
                    162: sub start_optionresponse {
                    163:   require Apache::optionresponse; 
                    164:   import Apache::optionresponse; 
1.28      albertel  165:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                    166:   return &Apache::optionresponse::start_optionresponse($target,$token,$tagstack,$parstack,$parser,$safeeval,$style);
1.21      albertel  167: }
                    168: 
                    169: sub start_imageresponse {
                    170:   require Apache::imageresponse; 
                    171:   import Apache::imageresponse; 
1.28      albertel  172:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                    173:   return &Apache::imageresponse::start_imageresponse($target,$token,$tagstack,$parstack,$parser,$safeeval,$style);
1.23      albertel  174: }
                    175: 
                    176: sub start_essayresponse {
                    177:   require Apache::essayresponse; 
                    178:   import Apache::essayresponse; 
1.28      albertel  179:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                    180:   return &Apache::essayresponse::start_essayresponse($target,$token,$tagstack,$parstack,$parser,$safeeval,$style);
1.3       albertel  181: }
                    182: 
                    183: sub start_responseparam {
1.28      albertel  184:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.20      albertel  185:   if ($target eq 'grade' || $target eq 'web') {
1.27      albertel  186:     my $default= &Apache::lonxml::get_param('default',$parstack,$safeeval);
                    187:     my $name= &Apache::lonxml::get_param('name',$parstack,$safeeval);
1.9       albertel  188:     &Apache::lonxml::debug("looking for resource.$Apache::inputtags::part.$name");
                    189:     my $value = &Apache::lonnet::EXT("resource.$Apache::inputtags::part.$name");
1.8       albertel  190:     &Apache::lonxml::debug("$name has value :$value: and default :$default:");
1.18      albertel  191:     if ($value eq '' || $value eq 'con_lost') {
                    192:       &Apache::lonxml::debug("defaulting");
1.8       albertel  193:       $Apache::inputtags::params{$name}=$default;
                    194:     } else {
1.11      albertel  195:       &Apache::lonxml::debug("using value");
1.8       albertel  196:       $Apache::inputtags::params{$name}=$value;
                    197:     }
                    198:     return '';
1.12      albertel  199:   } elsif ($target eq 'meta') {
1.10      www       200:     return &meta_parameter_write($token->[2]->{'name'},
1.8       albertel  201: 				 $token->[2]->{'type'},
                    202: 				 $token->[2]->{'default'},
                    203: 				 $token->[2]->{'description'});
1.29      albertel  204:   } elsif ($target eq 'edit') {
                    205:     my $result.=&Apache::edit::tag_start($target,$token,&Apache::lonxml::description($token));
                    206:     $result.=&Apache::edit::text_arg('Name:','name',$token).
                    207:       &Apache::edit::text_arg('Type:','type',$token).
                    208: 	&Apache::edit::text_arg('Description:','description',$token).
                    209: 	  &Apache::edit::text_arg('Default:','default',$token).
                    210: 	    "</td></tr>";
                    211:     $result.=&Apache::edit::end_table;
                    212:     return $result;
                    213:   } elsif ($target eq 'modified') {
                    214:     my $result;
                    215:     my $constructtag=&Apache::edit::get_new_args($token,$parstack,$safeeval,
                    216: 						 'name','type','description',
                    217: 						 'default');
1.30      albertel  218:     if ($constructtag) {
                    219:       $result = &Apache::edit::rebuild_tag($token);
                    220:       $result.=&Apache::edit::handle_insert();
                    221:     }
1.29      albertel  222:     return $result;
                    223: 
1.12      albertel  224:   } else {
                    225:     return '';
1.3       albertel  226:   }
                    227: }
                    228: 
                    229: sub end_responseparam {
1.29      albertel  230:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    231:   if ($target eq 'edit') { return ('','no'); }
1.25      albertel  232:   return '';
1.1       albertel  233: }
1.2       albertel  234: 
1.1       albertel  235: 1;
                    236: __END__
                    237:  

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