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

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.31    ! albertel   10:   &Apache::lonxml::register('Apache::response',('responseparam','caparesponse','numericalresponse','stringresponse','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.31    ! albertel   99: sub start_caparesponse {
1.14      albertel  100:   require Apache::caparesponse; 
                    101:   import Apache::caparesponse; 
1.28      albertel  102:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.31    ! albertel  103: #  print "\n<br />\nsimple caparesponse\n";
        !           104:   return &Apache::caparesponse::start_caparesponse($target,$token,$tagstack,$parstack,$parser,$safeeval,$style);
        !           105: }
        !           106: 
        !           107: sub start_stringresponse {
        !           108:   require Apache::caparesponse;
        !           109:   import Apache::caparesponse;
        !           110:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
        !           111:   return &Apache::caparesponse::start_stringresponse($target,$token,$tagstack,$parstack,$parser,$safeeval,$style);
1.7       www       112: }
                    113: 
1.31    ! albertel  114: sub start_numericalresponse {
1.1       albertel  115:   require Apache::caparesponse; 
                    116:   import Apache::caparesponse; 
1.28      albertel  117:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.31    ! albertel  118:   return &Apache::caparesponse::start_numericalresponse($target,$token,$tagstack,$parstack,$parser,$safeeval,$style);
1.16      albertel  119: }
                    120: 
                    121: sub start_radiobuttonresponse {
                    122:   require Apache::radiobuttonresponse; 
                    123:   import Apache::radiobuttonresponse; 
1.28      albertel  124:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                    125:   return &Apache::radiobuttonresponse::start_radiobuttonresponse($target,$token,$tagstack,$parstack,$parser,$safeeval,$style);
1.19      albertel  126: }
                    127: 
                    128: sub start_optionresponse {
                    129:   require Apache::optionresponse; 
                    130:   import Apache::optionresponse; 
1.28      albertel  131:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                    132:   return &Apache::optionresponse::start_optionresponse($target,$token,$tagstack,$parstack,$parser,$safeeval,$style);
1.21      albertel  133: }
                    134: 
                    135: sub start_imageresponse {
                    136:   require Apache::imageresponse; 
                    137:   import Apache::imageresponse; 
1.28      albertel  138:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                    139:   return &Apache::imageresponse::start_imageresponse($target,$token,$tagstack,$parstack,$parser,$safeeval,$style);
1.23      albertel  140: }
                    141: 
                    142: sub start_essayresponse {
                    143:   require Apache::essayresponse; 
                    144:   import Apache::essayresponse; 
1.28      albertel  145:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                    146:   return &Apache::essayresponse::start_essayresponse($target,$token,$tagstack,$parstack,$parser,$safeeval,$style);
1.3       albertel  147: }
                    148: 
                    149: sub start_responseparam {
1.28      albertel  150:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.20      albertel  151:   if ($target eq 'grade' || $target eq 'web') {
1.27      albertel  152:     my $default= &Apache::lonxml::get_param('default',$parstack,$safeeval);
                    153:     my $name= &Apache::lonxml::get_param('name',$parstack,$safeeval);
1.9       albertel  154:     &Apache::lonxml::debug("looking for resource.$Apache::inputtags::part.$name");
                    155:     my $value = &Apache::lonnet::EXT("resource.$Apache::inputtags::part.$name");
1.8       albertel  156:     &Apache::lonxml::debug("$name has value :$value: and default :$default:");
1.18      albertel  157:     if ($value eq '' || $value eq 'con_lost') {
                    158:       &Apache::lonxml::debug("defaulting");
1.8       albertel  159:       $Apache::inputtags::params{$name}=$default;
                    160:     } else {
1.11      albertel  161:       &Apache::lonxml::debug("using value");
1.8       albertel  162:       $Apache::inputtags::params{$name}=$value;
                    163:     }
                    164:     return '';
1.12      albertel  165:   } elsif ($target eq 'meta') {
1.10      www       166:     return &meta_parameter_write($token->[2]->{'name'},
1.8       albertel  167: 				 $token->[2]->{'type'},
                    168: 				 $token->[2]->{'default'},
                    169: 				 $token->[2]->{'description'});
1.29      albertel  170:   } elsif ($target eq 'edit') {
                    171:     my $result.=&Apache::edit::tag_start($target,$token,&Apache::lonxml::description($token));
                    172:     $result.=&Apache::edit::text_arg('Name:','name',$token).
                    173:       &Apache::edit::text_arg('Type:','type',$token).
                    174: 	&Apache::edit::text_arg('Description:','description',$token).
                    175: 	  &Apache::edit::text_arg('Default:','default',$token).
                    176: 	    "</td></tr>";
                    177:     $result.=&Apache::edit::end_table;
                    178:     return $result;
                    179:   } elsif ($target eq 'modified') {
                    180:     my $result;
                    181:     my $constructtag=&Apache::edit::get_new_args($token,$parstack,$safeeval,
                    182: 						 'name','type','description',
                    183: 						 'default');
1.30      albertel  184:     if ($constructtag) {
                    185:       $result = &Apache::edit::rebuild_tag($token);
                    186:       $result.=&Apache::edit::handle_insert();
                    187:     }
1.29      albertel  188:     return $result;
                    189: 
1.12      albertel  190:   } else {
                    191:     return '';
1.3       albertel  192:   }
                    193: }
                    194: 
                    195: sub end_responseparam {
1.29      albertel  196:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    197:   if ($target eq 'edit') { return ('','no'); }
1.25      albertel  198:   return '';
1.1       albertel  199: }
1.2       albertel  200: 
1.1       albertel  201: 1;
                    202: __END__
                    203:  

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