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

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)=@_;  
                     15:   my $args ='';
                     16:   if ( $#$parstack > -1 ) { $args=$$parstack[$#$parstack]; }
                     17:   my $id = &Apache::run::run("{$args;".'return $id}',$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;
                     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.7       www        53:      ."\n";
                     54: }
                     55: 
                     56: sub meta_stores_write {
1.10      www        57:     my ($name,$type,$display)=@_;
                     58:     return '<stores part="'.$Apache::inputtags::part.
1.7       www        59: 	         '" name="'.$name.
                     60:                  '" type="'.$type.
1.10      www        61: 	      '" display="'.$display.
                     62:                        ' [Part: '.$Apache::inputtags::part.']"></stores>'
1.7       www        63:      ."\n";
                     64: }
                     65: 
                     66: sub mandatory_part_meta {
                     67: #
                     68: # Autogenerate metadata for mandatory
                     69: # input (from RAT or lonparmset) and 
                     70: # output (to lonspreadsheet)
                     71: # of each part
                     72: #
                     73:  return
1.10      www        74:     &meta_parameter_write('opendate','date_start','',
1.7       www        75:                           'Opening Date').
1.10      www        76:     &meta_parameter_write('duedate','date_end','',
1.7       www        77:                           'Due Date').
1.10      www        78:     &meta_parameter_write('answerdate','date_start','',
1.7       www        79:                           'Show Answer Date').
1.10      www        80:     &meta_parameter_write('weight','int_zeropos','',
1.7       www        81:                           'Available Points').
1.10      www        82:     &meta_parameter_write('maxtries','int_pos','',
1.7       www        83:                           'Maximum Number of Tries').
                     84: 
1.10      www        85:     &meta_stores_write('solved','string',
1.7       www        86:                           'Problem Status').
1.10      www        87:     &meta_stores_write('tries','int_zeropos',
1.24      albertel   88:                           'Number of Attempts').
1.10      www        89:     &meta_stores_write('awarded','float',
1.7       www        90: 		          'Partial Credit Factor');
                     91: #
                     92: # Note: responseid-specific data 'submission' and 'awarddetail'
                     93: # not available to spreadsheet -> skip here
                     94: #
1.14      albertel   95: }
                     96: 
1.15      albertel   97: sub check_for_previous {
                     98:   return '0';
                     99: }
                    100: 
1.14      albertel  101: sub start_numericalresponse {
                    102:   require Apache::caparesponse; 
                    103:   import Apache::caparesponse; 
                    104:   my ($target,$token,$parstack,$parser,$safeeval,$style)=@_;
1.23      albertel  105:   return &Apache::caparesponse::start_numericalresponse($target,$token,$parstack,$parser,$safeeval,$style);
1.7       www       106: }
                    107: 
1.1       albertel  108: sub start_caparesponse {
                    109:   require Apache::caparesponse; 
                    110:   import Apache::caparesponse; 
                    111:   my ($target,$token,$parstack,$parser,$safeeval,$style)=@_;
1.22      albertel  112: #  print "\n<br />\nsimple caparesponse\n";
1.23      albertel  113:   return &Apache::caparesponse::start_caparesponse($target,$token,$parstack,$parser,$safeeval,$style);
1.16      albertel  114: }
                    115: 
                    116: sub start_radiobuttonresponse {
                    117:   require Apache::radiobuttonresponse; 
                    118:   import Apache::radiobuttonresponse; 
                    119:   my ($target,$token,$parstack,$parser,$safeeval,$style)=@_;
1.23      albertel  120:   return &Apache::radiobuttonresponse::start_radiobuttonresponse($target,$token,$parstack,$parser,$safeeval,$style);
1.19      albertel  121: }
                    122: 
                    123: sub start_optionresponse {
                    124:   require Apache::optionresponse; 
                    125:   import Apache::optionresponse; 
                    126:   my ($target,$token,$parstack,$parser,$safeeval,$style)=@_;
1.23      albertel  127:   return &Apache::optionresponse::start_optionresponse($target,$token,$parstack,$parser,$safeeval,$style);
1.21      albertel  128: }
                    129: 
                    130: sub start_imageresponse {
                    131:   require Apache::imageresponse; 
                    132:   import Apache::imageresponse; 
                    133:   my ($target,$token,$parstack,$parser,$safeeval,$style)=@_;
1.23      albertel  134:   return &Apache::imageresponse::start_imageresponse($target,$token,$parstack,$parser,$safeeval,$style);
                    135: }
                    136: 
                    137: sub start_essayresponse {
                    138:   require Apache::essayresponse; 
                    139:   import Apache::essayresponse; 
                    140:   my ($target,$token,$parstack,$parser,$safeeval,$style)=@_;
                    141:   return &Apache::essayresponse::start_essayresponse($target,$token,$parstack,$parser,$safeeval,$style);
1.3       albertel  142: }
                    143: 
                    144: sub start_responseparam {
                    145:   my ($target,$token,$parstack,$parser,$safeeval)=@_;
1.20      albertel  146:   if ($target eq 'grade' || $target eq 'web') {
1.8       albertel  147:     my $args='';
                    148:     if ( $#$parstack > -1 ) { $args=$$parstack[$#$parstack]; }
                    149:     my $default = &Apache::run::run("{$args;".'return $default}',$safeeval);
                    150:     my $name = &Apache::run::run("{$args;".'return $name}',$safeeval);
1.9       albertel  151:     &Apache::lonxml::debug("looking for resource.$Apache::inputtags::part.$name");
                    152:     my $value = &Apache::lonnet::EXT("resource.$Apache::inputtags::part.$name");
1.8       albertel  153:     &Apache::lonxml::debug("$name has value :$value: and default :$default:");
1.18      albertel  154:     if ($value eq '' || $value eq 'con_lost') {
                    155:       &Apache::lonxml::debug("defaulting");
1.8       albertel  156:       $Apache::inputtags::params{$name}=$default;
                    157:     } else {
1.11      albertel  158:       &Apache::lonxml::debug("using value");
1.8       albertel  159:       $Apache::inputtags::params{$name}=$value;
                    160:     }
                    161:     return '';
1.12      albertel  162:   } elsif ($target eq 'meta') {
1.10      www       163:     return &meta_parameter_write($token->[2]->{'name'},
1.8       albertel  164: 				 $token->[2]->{'type'},
                    165: 				 $token->[2]->{'default'},
                    166: 				 $token->[2]->{'description'});
1.12      albertel  167:   } else {
                    168:     return '';
1.3       albertel  169:   }
                    170: }
                    171: 
                    172: sub end_responseparam {
1.25      albertel  173:   return '';
1.1       albertel  174: }
1.2       albertel  175: 
1.1       albertel  176: 1;
                    177: __END__
                    178:  

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