[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 5338 Revision 5339
131# and initialize it. 131# and initialize it.
132# 132#
133sub new { 133sub new {
134 my $self = shift; my $class = ref($self) || $self; 134 my $self = shift; my $class = ref($self) || $self;
135 my $pr = bless { 135 my $pr = bless {
136 when => "Correct", 136 when => "correct",
137 onlyAfterDue => 1, 137 onlyAfterDue => 1,
138 style => "Button", 138 style => "Button",
139 label => undef, 139 label => undef,
140 buttonLabel => "Get a new version of this problem", 140 buttonLabel => "Get a new version of this problem",
141 checkboxLabel => "Get a new version of this problem", 141 checkboxLabel => "Get a new version of this problem",
144 random => $main::PG_random_generator, 144 random => $main::PG_random_generator,
145 status => {}, 145 status => {},
146 @_ 146 @_
147 }, $class; 147 }, $class;
148 $pr->{style} = uc(substr($pr->{style},0,1)) . lc(substr($pr->{style},1)); 148 $pr->{style} = uc(substr($pr->{style},0,1)) . lc(substr($pr->{style},1));
149 $pr->{when} = lc($pr->{when});
149 $pr->getStatus; 150 $pr->getStatus;
150 $pr->initProblem; 151 $pr->initProblem;
151 return $pr; 152 return $pr;
152} 153}
153 154
313 # 314 #
314 my $status = $self->{status}; 315 my $status = $self->{status};
315 $status->{ans_rule_count} = $main::ans_rule_count; 316 $status->{ans_rule_count} = $main::ans_rule_count;
316 $status->{answers} = join(';',grep(!/${main::QUIZ_PREFIX}${main::ANSWER_PREFIX}/o,keys(%{$_[0]}))); 317 $status->{answers} = join(';',grep(!/${main::QUIZ_PREFIX}${main::ANSWER_PREFIX}/o,keys(%{$_[0]})));
317 my $data = quoteHTML($self->encode); 318 my $data = quoteHTML($self->encode);
319 $result->{type} = "problemRandomize ($result->{type})";
320
321 #
322 # Conditions for when to show the reseed message
323 #
324 my $isWhen = ($self->{when} eq 'always' ||
325 ($self->{when} eq 'correct' && $result->{score} >= 1 &&
326 !$main::inputs_ref->{previewAnswers}));
327 my $okDate = (!$self->{onlyAfterDue} || time >= $main::dueDate);
318 328
319 # 329 #
320 # Add the problemRandomize message and data 330 # Add the problemRandomize message and data
321 # 331 #
322 $result->{type} = "problemRandomize ($result->{type})"; 332 if ($isWhen && !$okDate) {
333 $result->{msg} .= "</i><br /><b>Note:</b> <i>" if $result->{msg};
334 $result->{msg} .= "You can get a new version of this problem after the due date.";
335 }
323 if (!$result->{msg}) { 336 if (!$result->{msg}) {
324 # hack to remove unwanted "<b>Note: </b>" from the problem 337 # hack to remove unwanted "<b>Note: </b>" from the problem
325 # (it is inserted automatically by Problem.pm when {msg} is non-emtpy). 338 # (it is inserted automatically by Problem.pm when {msg} is non-emtpy).
326 $result->{msg} .= '<script>var bb = document.getElementsByTagName("b");' 339 $result->{msg} .= '<script>var bb = document.getElementsByTagName("b");'
327 . 'bb[bb.length-1].style.display="none"</script>'; 340 . 'bb[bb.length-1].style.display="none"</script>';
329 $result->{msg} .= qq!<input type="hidden" name="_status" value="$data" />!; 342 $result->{msg} .= qq!<input type="hidden" name="_status" value="$data" />!;
330 343
331 # 344 #
332 # Include the "randomize" checkbox, button, or whatever. 345 # Include the "randomize" checkbox, button, or whatever.
333 # 346 #
334 if (lc($self->{when}) eq 'always' || 347 if ($isWhen && $okDate) {
335 (lc($self->{when}) eq 'correct' && $result->{score} >= 1 &&
336 !$main::inputs_ref->{previewAnswers})) {
337 if (!$self->{onlyAfterDue} || time >= $main::dueDate) {
338 my $method = "randomize".$self->{style}; 348 my $method = "randomize".$self->{style};
339 $result->{msg} .= $self->$method($self->{label},1).'<br/>'; 349 $result->{msg} .= $self->$method($self->{label},1).'<br/>';
340 }
341 } 350 }
342 351
343 # 352 #
344 # Don't show the summary section if the problem is being reset. 353 # Don't show the summary section if the problem is being reset.
345 # 354 #

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

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9