Skip to content

Commit

Permalink
Persistent problem data - modify to retrieve from $envir
Browse files Browse the repository at this point in the history
and to allow update and get operations. The webwork2 side
will now store this in a special field.
  • Loading branch information
taniwallach committed Apr 13, 2023
1 parent 3803165 commit 782dd66
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
23 changes: 19 additions & 4 deletions lib/PGcore.pm
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,13 @@ sub new {
POST_HEADER_ARRAY => [],
# PG_ANSWERS => [], # holds answers with labels # deprecated
# PG_UNLABELED_ANSWERS => [], # holds unlabeled ans. #deprecated -replaced by PG_ANSWERS_HASH
PG_ANSWERS_HASH => {}, # holds label=>answer pairs
PERSISTENCE_HASH => {}, # holds other data, besides answers, which persists during a session and beyond
answer_eval_count => 0,
answer_blank_count => 0,
PG_ANSWERS_HASH => {}, # holds label=>answer pairs

# holds other data, besides answers, which persists during a session and beyond
PERSISTENCE_HASH => $envir->{PERSISTENCE_HASH} // {},

answer_eval_count => 0,
answer_blank_count => 0,
unlabeled_answer_blank_count => 0,
unlabeled_answer_eval_count => 0,
KEPT_EXTRA_ANSWERS => [],
Expand Down Expand Up @@ -549,6 +552,18 @@ sub store_persistent_data { # will store strings only (so far)
$label;
}

sub update_persistent_data { # will store strings only (so far)
my $self = shift;
my $label = shift;
$self->{PERSISTENCE_HASH}->{$label} = join("", @_);
}

sub get_persistent_data {
my $self = shift;
my $label = shift;
return ($self->{PERSISTENCE_HASH}->{$label});
}

sub check_answer_hash {
my $self = shift;
foreach my $key (keys %{ $self->{PG_ANSWERS_HASH} }) {
Expand Down
1 change: 1 addition & 0 deletions lib/WeBWorK/PG.pm
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ sub defineProblemEnvironment ($pg_envir, $options = {}, $image_generator = undef
pastDue => $options->{pastDue} // 0,
answersAvailable => $options->{answersAvailable} // 0,
isInstructor => $options->{isInstructor} // 0,
PERSISTENCE_HASH => $options->{PERSISTENCE_HASH} // {},

inputs_ref => $options->{inputs_ref},

Expand Down
13 changes: 10 additions & 3 deletions macros/PG.pl
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,15 @@ sub ANS_NUM_TO_NAME {
}

sub store_persistent_data {
$PG->store_persistent_data(@_); #needs testing
$PG->store_persistent_data(@_);
}

sub update_persistent_data {
$PG->update_persistent_data(@_);
}

sub get_persistent_data {
return ($PG->get_persistent_data(shift));
}

sub RECORD_FORM_LABEL { # this stores form data (such as sticky answers), but does nothing more
Expand Down Expand Up @@ -600,8 +608,7 @@ sub ENDDOCUMENT {
warn "$key is ", join("|", %{ $PG->{PG_ANSWERS_HASH}->{$key} });
}
}
push @KEPT_EXTRA_ANSWERS, keys %{ $PG->{PERSISTENCE_HASH} };
#Hackish way to store other persistence data

$PG->{flags}->{KEPT_EXTRA_ANSWERS} = \@KEPT_EXTRA_ANSWERS;
$PG->{flags}->{ANSWER_ENTRY_ORDER} = \@PG_ANSWER_ENTRY_ORDER;

Expand Down

0 comments on commit 782dd66

Please sign in to comment.