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

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

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