Annotation of loncom/homework/response.pm, revision 1.32
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 {
1.32 ! albertel 96: my ($curresponse,$partid,$id) = @_;
! 97: my %previous;
! 98: $previous{'used'} = 0;
! 99: foreach my $key (reverse(sort(keys(%Apache::lonhomework::history)))) {
! 100: if ($key =~ /resource\.$partid\.$id\.submission/) {
! 101: &Apache::lonxml::debug("Trying $key");
! 102: my $pastresponse=$Apache::lonhomework::history{$key};
! 103: if ($pastresponse eq $curresponse) {
! 104: $previous{'used'} = 1;
! 105: my $history;
! 106: if ( $key =~ /^(\d+):/ ) {
! 107: $history=$1;
! 108: $previous{'award'} = $Apache::lonhomework::history{"$history:resource.$partid.$id.awarddetail"};
! 109: $previous{'last'}='0';
! 110: } else {
! 111: $previous{'award'} = $Apache::lonhomework::history{"resource.$partid.$id.awarddetail"};
! 112: $previous{'last'}='1';
! 113: }
! 114: if (! $previous{'award'} ) { $previous{'award'} = 'UNKNOWN'; }
! 115: &Apache::lonxml::debug("got a match :$previous{'award'}:$previous{'used'}:");
! 116: last;
! 117: }
! 118: }
! 119: }
! 120: return %previous;
1.15 albertel 121: }
122:
1.31 albertel 123: sub start_caparesponse {
1.14 albertel 124: require Apache::caparesponse;
125: import Apache::caparesponse;
1.28 albertel 126: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.31 albertel 127: # print "\n<br />\nsimple caparesponse\n";
128: return &Apache::caparesponse::start_caparesponse($target,$token,$tagstack,$parstack,$parser,$safeeval,$style);
129: }
130:
131: sub start_stringresponse {
132: require Apache::caparesponse;
133: import Apache::caparesponse;
134: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
135: return &Apache::caparesponse::start_stringresponse($target,$token,$tagstack,$parstack,$parser,$safeeval,$style);
1.7 www 136: }
137:
1.31 albertel 138: sub start_numericalresponse {
1.1 albertel 139: require Apache::caparesponse;
140: import Apache::caparesponse;
1.28 albertel 141: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.31 albertel 142: return &Apache::caparesponse::start_numericalresponse($target,$token,$tagstack,$parstack,$parser,$safeeval,$style);
1.16 albertel 143: }
144:
145: sub start_radiobuttonresponse {
146: require Apache::radiobuttonresponse;
147: import Apache::radiobuttonresponse;
1.28 albertel 148: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
149: return &Apache::radiobuttonresponse::start_radiobuttonresponse($target,$token,$tagstack,$parstack,$parser,$safeeval,$style);
1.19 albertel 150: }
151:
152: sub start_optionresponse {
153: require Apache::optionresponse;
154: import Apache::optionresponse;
1.28 albertel 155: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
156: return &Apache::optionresponse::start_optionresponse($target,$token,$tagstack,$parstack,$parser,$safeeval,$style);
1.21 albertel 157: }
158:
159: sub start_imageresponse {
160: require Apache::imageresponse;
161: import Apache::imageresponse;
1.28 albertel 162: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
163: return &Apache::imageresponse::start_imageresponse($target,$token,$tagstack,$parstack,$parser,$safeeval,$style);
1.23 albertel 164: }
165:
166: sub start_essayresponse {
167: require Apache::essayresponse;
168: import Apache::essayresponse;
1.28 albertel 169: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
170: return &Apache::essayresponse::start_essayresponse($target,$token,$tagstack,$parstack,$parser,$safeeval,$style);
1.3 albertel 171: }
172:
173: sub start_responseparam {
1.28 albertel 174: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.20 albertel 175: if ($target eq 'grade' || $target eq 'web') {
1.27 albertel 176: my $default= &Apache::lonxml::get_param('default',$parstack,$safeeval);
177: my $name= &Apache::lonxml::get_param('name',$parstack,$safeeval);
1.9 albertel 178: &Apache::lonxml::debug("looking for resource.$Apache::inputtags::part.$name");
179: my $value = &Apache::lonnet::EXT("resource.$Apache::inputtags::part.$name");
1.8 albertel 180: &Apache::lonxml::debug("$name has value :$value: and default :$default:");
1.18 albertel 181: if ($value eq '' || $value eq 'con_lost') {
182: &Apache::lonxml::debug("defaulting");
1.8 albertel 183: $Apache::inputtags::params{$name}=$default;
184: } else {
1.11 albertel 185: &Apache::lonxml::debug("using value");
1.8 albertel 186: $Apache::inputtags::params{$name}=$value;
187: }
188: return '';
1.12 albertel 189: } elsif ($target eq 'meta') {
1.10 www 190: return &meta_parameter_write($token->[2]->{'name'},
1.8 albertel 191: $token->[2]->{'type'},
192: $token->[2]->{'default'},
193: $token->[2]->{'description'});
1.29 albertel 194: } elsif ($target eq 'edit') {
195: my $result.=&Apache::edit::tag_start($target,$token,&Apache::lonxml::description($token));
196: $result.=&Apache::edit::text_arg('Name:','name',$token).
197: &Apache::edit::text_arg('Type:','type',$token).
198: &Apache::edit::text_arg('Description:','description',$token).
199: &Apache::edit::text_arg('Default:','default',$token).
200: "</td></tr>";
201: $result.=&Apache::edit::end_table;
202: return $result;
203: } elsif ($target eq 'modified') {
204: my $result;
205: my $constructtag=&Apache::edit::get_new_args($token,$parstack,$safeeval,
206: 'name','type','description',
207: 'default');
1.30 albertel 208: if ($constructtag) {
209: $result = &Apache::edit::rebuild_tag($token);
210: $result.=&Apache::edit::handle_insert();
211: }
1.29 albertel 212: return $result;
213:
1.12 albertel 214: } else {
215: return '';
1.3 albertel 216: }
217: }
218:
219: sub end_responseparam {
1.29 albertel 220: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
221: if ($target eq 'edit') { return ('','no'); }
1.25 albertel 222: return '';
1.1 albertel 223: }
1.2 albertel 224:
1.1 albertel 225: 1;
226: __END__
227:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>