Skip to content

Commit

Permalink
Correct passing answer_group_name. This now appears to work for all m…
Browse files Browse the repository at this point in the history
…ultiAnswer and matrix answer evaluators.

Debugging messages have been removed
  • Loading branch information
mgage committed Jun 6, 2017
1 parent afe0975 commit 5bbefa4
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 15 deletions.
25 changes: 16 additions & 9 deletions lib/Value/AnswerChecker.pm
Original file line number Diff line number Diff line change
Expand Up @@ -396,24 +396,31 @@ sub ans_matrix {
$self->{ans_name} = $ename;
$self->{ans_rows} = $rows;
$self->{ans_cols} = $cols;
# warn "ans_matrix: ename=$ename answer_group_name=$options{answer_group_name}";
my @array = ();
foreach my $i (0..$rows-1) {
my @row = ();
foreach my $j (0..$cols-1) {
my $label;
if ($options{aria_label}) {
$label = $options{aria_label}.'row '.($i+1).' col '.($j+1);
$label = $options{aria_label}.'row '.($i+1).' col '.($j+1);
} else {
$label = pgCall('generate_aria_label',ANS_NAME($ename,$i,$j));
$label = pgCall('generate_aria_label',ANS_NAME($ename,$i,$j));
}
my $answer_group_name = $options{answer_group_name}//$name;
if ($i == 0 && $j == 0) {
if ($extend) {
push(@row,&$named_extension($name,$size,ans_label=>$name,aria_label=>$label));
} else {
push(@row,&$named_ans_rule($name,$size,aria_label=>$label));
}
} else {
push(@row,&$named_extension(ANS_NAME($ename,$i,$j),$size,ans_label=>$name,aria_label=>$label));
if ($extend) {
push(@row,&$named_extension($name,$size,
answer_group_name=> $answer_group_name,
aria_label=>$label)
);
} else {
push(@row,&$named_ans_rule($name,$size,aria_label=>$label));
}
} else {
push(@row,&$named_extension(ANS_NAME($ename,$i,$j),$size,
answer_group_name => $answer_group_name,
aria_label=>$label));
}
}
push(@array,[@row]);
Expand Down
26 changes: 23 additions & 3 deletions macros/PGbasicmacros.pl
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,10 @@ sub NAMED_ANS_RULE_EXTENSION {
}
# this is the name of the parent answer group
my $answer_group_name = $options{answer_group_name}//'';
unless ($answer_group_name) {
WARN_MESSAGE("Error in NAMED_ANSWER_RULE_EXTENSION: every call to this subroutine needs
to have \$options{answer_group_name} defined. Answer blank name: $name");
}
# warn "from named answer rule extension in PGbasic answer_group_name: |$answer_group_name|";
my $answer_value = '';
$answer_value = ${$inputs_ref}{$name} if defined(${$inputs_ref}{$name});
Expand All @@ -468,7 +472,8 @@ sub NAMED_ANS_RULE_EXTENSION {
}
# $answer_value =~ tr/\\$@`//d; #`## make sure student answers can not be interpolated by e.g. EV3
$answer_value =~ s/\s+/ /g; ## remove excessive whitespace from student answer
# warn "from named answer rule extension in PGbasic: name: |$name| answer value: |$answer_value|";
# warn "from NAMED_ANSWER_RULE_EXTENSION in PGbasic:
# answer_group_name: |$answer_group_name| name: |$name| answer value: |$answer_value|";
INSERT_RESPONSE($answer_group_name,$name,$answer_value); #FIXME hack -- this needs more work to decide how to make it work
$answer_value = encode_pg_and_html($answer_value);

Expand Down Expand Up @@ -1095,8 +1100,23 @@ sub NAMED_ANS_ARRAY_EXTENSION{

# $answer_value =~ tr/\\$@`//d; #`## make sure student answers can not be interpolated by e.g. EV3
# warn "ans_label $options{ans_label} $name $answer_value";
if (defined($options{ans_label}) ) {
INSERT_RESPONSE($options{ans_label}, $name, $answer_value);
my $answer_group_name; # the name of the answer evaluator controlling this collection of responses.
# catch deprecated use of ans_label to pass answer_group_name
if (defined($options{ans_label})) {
WARN_MESSAGE("Error in NAMED_ANS_ARRAY_EXTENSION: the answer group name should be passed in ",
"\%options using answer_group_name=>\$answer_group_name",
"The use of ans_label=>\$answer_group_name is deprecated.",
"Answer blank name: $name"
);
$answer_group_name = $options{ans_label};
}
if (defined($options{answer_group_name}) ) {
$answer_group_name = $options{answer_group_name};
}
if ($answer_group_name) {
INSERT_RESPONSE($options{answer_group_name}, $name, $answer_value);
} else {
WARN_MESSAGE("Error: answer_group_name must be defined for $name");
}
$answer_value = encode_pg_and_html($answer_value);

Expand Down
10 changes: 7 additions & 3 deletions macros/parserMultiAnswer.pl
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ sub ans_rule {
$data->named_ans_rule_extension(
$name,$size, answer_group_name => $self->{answerName},
@_);
# warn "extension rule created: $extension_ans_rule";
# warn "extension rule created: $extension_ans_rule for ", ref($data);
return $extension_ans_rule;
} else {
return $data->named_ans_rule($name,$size,@_);
Expand All @@ -473,10 +473,14 @@ sub ans_array {
my $name = $self->ANS_NAME($self->{part}++);
if ($self->{singleResult} && $self->{part} == 1) {
my $label = main::generate_aria_label($answerPrefix.$name."_0");
return $data->named_ans_array($name,$size,@_,aria_label=>$label);
return $data->named_ans_array($name,$size,
answer_group_name => $self->{answerName},
@_,aria_label=>$label);
}
if ($self->{singleResult} && $self->{part} > 1) {
$HTML = $data->named_ans_array_extension($self->NEW_NAME($name),$size,@_);
$HTML = $data->named_ans_array_extension($self->NEW_NAME($name),$size,
answer_group_name => $self->{answerName}, @_);
# warn "array extension rule created: $HTML for ", ref($data);
} else {
$HTML = $data->named_ans_array($name,$size,@_);
}
Expand Down

0 comments on commit 5bbefa4

Please sign in to comment.