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

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

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