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