[system] / trunk / pg / macros / problemRandomize.pl Repository:
ViewVC logotype

Diff of /trunk/pg/macros/problemRandomize.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 5337 Revision 5338
155# Look up the status from the previous invocation 155# Look up the status from the previous invocation
156# and check to see if a rerandomization is requested 156# and check to see if a rerandomization is requested
157# 157#
158sub getStatus { 158sub getStatus {
159 my $self = shift; 159 my $self = shift;
160 main::RECORD_FORM_LABEL("_randomize"); 160 main::RECORD_FORM_LABEL("_reseed");
161 main::RECORD_FORM_LABEL("_status"); 161 main::RECORD_FORM_LABEL("_status");
162 my $label = $self->{label} || $self->{lc($self->{style})."Label"}; 162 my $label = $self->{label} || $self->{lc($self->{style})."Label"};
163 $self->{status} = $self->decode; 163 $self->{status} = $self->decode;
164 $self->{submit} = $main::inputs_ref->{submitAnswers}; 164 $self->{submit} = $main::inputs_ref->{submitAnswers};
165 $self->{isReset} = $main::inputs_ref->{_randomize} || ($self->{submit} && $self->{submit} eq $label); 165 $self->{isReset} = $main::inputs_ref->{_reseed} || ($self->{submit} && $self->{submit} eq $label);
166 $self->{isReset} = 0 unless !$self->{onlyAfterDue} || time >= $main::dueDate; 166 $self->{isReset} = 0 unless !$self->{onlyAfterDue} || time >= $main::dueDate;
167} 167}
168 168
169# 169#
170# Initialize the current problem 170# Initialize the current problem
185 my $status = $self->{status}; 185 my $status = $self->{status};
186 foreach my $id (split(/;/,$status->{answers})) {delete $main::inputs_ref->{$id}} 186 foreach my $id (split(/;/,$status->{answers})) {delete $main::inputs_ref->{$id}}
187 foreach my $id (1..$status->{ans_rule_count}) 187 foreach my $id (1..$status->{ans_rule_count})
188 {delete $main::inputs_ref->{"${main::QUIZ_PREFIX}${main::ANSWER_PREFIX}$id"}} 188 {delete $main::inputs_ref->{"${main::QUIZ_PREFIX}${main::ANSWER_PREFIX}$id"}}
189 $main::inputs_ref->{_status} = $self->encode(\%defaultStatus); 189 $main::inputs_ref->{_status} = $self->encode(\%defaultStatus);
190 $main::inputs_ref->{_randomize} = 1;
191 $status->{seed} = ($main::inputs_ref->{_seed} || substr(time,5,5)); 190 $status->{seed} = ($main::inputs_ref->{_reseed} || seed());
192} 191}
192
193sub seed {substr(time,5,5)}
193 194
194################################################## 195##################################################
195 196
196# 197#
197# Return the HTML for the "re-randomize" checkbox. 198# Return the HTML for the "re-randomize" checkbox.
199sub randomizeCheckbox { 200sub randomizeCheckbox {
200 my $self = shift; 201 my $self = shift;
201 my $label = shift || $self->{checkboxLabel}; 202 my $label = shift || $self->{checkboxLabel};
202 $label = "<b>$label</b> (when you submit your answers)."; 203 $label = "<b>$label</b> (when you submit your answers).";
203 my $par = shift; $par = ($par ? $main::PAR : ''); 204 my $par = shift; $par = ($par ? $main::PAR : '');
204 $self->{randomizeInserted} = 1; 205 $self->{reseedInserted} = 1;
205 $par . '<input type="checkbox" name="_randomize" value="1" />' . $label; 206 $par . '<input type="checkbox" name="_reseed" value="'.seed().'" />' . $label;
206} 207}
207 208
208# 209#
209# Return the HTML for the "next part" button. 210# Return the HTML for the "next part" button.
210# 211#
211sub randomizeButton { 212sub randomizeButton {
212 my $self = shift; 213 my $self = shift;
213 my $label = quoteHTML(shift || $self->{buttonLabel}); 214 my $label = quoteHTML(shift || $self->{buttonLabel});
214 my $par = shift; $par = ($par ? $main::PAR : ''); 215 my $par = shift; $par = ($par ? $main::PAR : '');
215 $par . qq!<input type="submit" name="submitAnswers" value="$label" ! 216 $par . qq!<input type="submit" name="submitAnswers" value="$label" !
216 . q!onclick="document.getElementById('_randomize').value=1" />!; 217 . q!onclick="document.getElementById('_reseed').value=!.seed().'" />';
217} 218}
218 219
219# 220#
220# Return the HTML for the "problem seed" input box 221# Return the HTML for the "problem seed" input box
221# 222#
222sub randomizeInput { 223sub randomizeInput {
223 my $self = shift; 224 my $self = shift;
224 my $label = quoteHTML(shift || $self->{inputLabel}); 225 my $label = quoteHTML(shift || $self->{inputLabel});
225 my $par = shift; $par = ($par ? main::PAR : ''); 226 my $par = shift; $par = ($par ? main::PAR : '');
226 $par . qq!<input type="submit" name="submitAnswers" value="$label">! 227 $par . qq!<input type="submit" name="submitAnswers" value="$label" !
228 . q!onclick="document.getElementById('_reseed').value=document.getElementById('_seed').value" />!
227 . qq!<input name="_seed" value="$self->{status}{seed}" size="10">!; 229 . qq!<input name="_seed" id="_seed" value="$self->{status}{seed}" size="10">!;
228} 230}
229 231
230# 232#
231# Return the raw HTML provided 233# Return the raw HTML provided
232# 234#
301 my $self = $main::PG_FLAGS{problemRandomize}; 303 my $self = $main::PG_FLAGS{problemRandomize};
302 304
303 # 305 #
304 # Call the original grader 306 # Call the original grader
305 # 307 #
308 $self->{grader} = \&problemRandomize::resetGrader if $self->{isReset};
306 my ($result,$state) = &{$self->{grader}}(@_); 309 my ($result,$state) = &{$self->{grader}}(@_);
307 310
308 # 311 #
309 # Update that state information and encode it. 312 # Update that state information and encode it.
310 # 313 #
349 } 352 }
350 353
351 # 354 #
352 # Make sure we don't go on unless the next button really is checked 355 # Make sure we don't go on unless the next button really is checked
353 # 356 #
354 $result->{msg} .= '<input type="hidden" name="_randomize" value="0" />' 357 $result->{msg} .= '<input type="hidden" name="_reseed" id="_reseed" value="0" />'
355 unless $self->{randomizeInserted}; 358 unless $self->{reseedInserted};
356 359
357 return ($result,$state); 360 return ($result,$state);
358} 361}
359 362
363#
364# Fake grader for when the problem is reset
365#
366sub resetGrader {
367 my $answers = shift;
368 my $state = shift;
369 my %options = @_;
370 my $result = {
371 score => 0,
372 msg => '',
373 errors => '',
374 type => 'problemRandomize (reset)',
375 };
376 return ($result,$state);
377}
378
3601; 3791;

Legend:
Removed from v.5337  
changed lines
  Added in v.5338

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9