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

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

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