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

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

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