Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create addMessage method for parserMultiAnswer.pl (alternative to #999) #1001

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 41 additions & 14 deletions macros/parsers/parserMultiAnswer.pl
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,21 @@ sub new {
}
}
bless {
data => [@data],
cmp => [@cmp],
ans => [],
isValue => 1,
part => 0,
singleResult => 0,
namedRules => 0,
checkTypes => 1,
allowBlankAnswers => 0,
tex_separator => $separator . '\,',
separator => $separator . ' ',
tex_format => undef,
format => undef,
context => $context,
data => [@data],
cmp => [@cmp],
ans => [],
isValue => 1,
part => 0,
singleResult => 0,
namedRules => 0,
checkTypes => 1,
allowBlankAnswers => 0,
tex_separator => $separator . '\,',
separator => $separator . ' ',
tex_format => undef,
format => undef,
context => $context,
single_ans_messages => [],
}, $class;
}

Expand Down Expand Up @@ -201,6 +202,10 @@ sub single_check {
. join('<TR><TD HEIGHT="4"></TD></TR>', @errors)
. '</TABLE>';
}
if (@{ $self->{single_ans_messages} }) {
$ans->{ans_message} = $ans->{error_message} =
'<DIV>' . join('</DIV><DIV>', @{ $self->{single_ans_messages} }) . '</DIV>' . $ans->{ans_message};
}
if ($nonblank) {
$ans->{preview_latex_string} =
(
Expand Down Expand Up @@ -331,6 +336,15 @@ sub setMessage {
$self->{ans}[ $i - 1 ]{ans_message} = $self->{ans}[ $i - 1 ]{error_message} = $message;
}

# The user's checker can add messages to the single_ans_messages array,
# which are joined together along with any ans_messages from the
# individual answers.
sub addMessage {
my ($self, $message) = @_;
return unless $message;
push(@{ $self->{single_ans_messages} }, $message);
}

######################################################################

#
Expand Down Expand Up @@ -545,6 +559,19 @@ =head2 setMessage
$ma_obj->setMessage(2, "It's like a jungle sometimes..."); # succeeds
$ma_obj->setMessage(3, "It's like a jungle sometimes..."); # fails

=head2 addMessage

$multianswer_obj->addMessage($message_string)

Meant for use in C<checker> when using C<singleResult> to add feedback messages for the
combined answer rules. This will add the message to a message array, which will be all
joined together to create the final message. These messages are then attached to any
answer rule messages to be displayed to the user.

Note that unlike C<setMessage>, these messages are not tied to any answer rules, and
unlike C<Value::Error("message")>, this will not halt the answer checker allowing both
partial credit and other messages to also be shown.

=head1 USAGE

To create a MultiAnswer pass a list of answers to MultiAnswer() in the order they
Expand Down
Loading