Added Survey meta-targets NEXT_SECTION and END_SURVEY to allow for more
convenient jumping Improved processGotoExpression tests
This commit is contained in:
parent
99855719d0
commit
6c58e1de81
3 changed files with 100 additions and 40 deletions
|
|
@ -274,17 +274,20 @@ sub startTime {
|
|||
|
||||
Accessor. Initialized on first access via L<"initSurveyOrder">.
|
||||
|
||||
This data strucutre is an array (reference) of Survey addresses (see
|
||||
L<WebGUI::Asset::Wobject::Survey::SurveyJSON/Address Parameter>), stored in the order
|
||||
in which items are presented to the user.
|
||||
This data strucutre represents the list of items that are shown to the user, in the order
|
||||
that they will be shown (ignoring jumps and jump expressions).
|
||||
|
||||
In general, the surveyOrder data structure looks like:
|
||||
Typically each item will correspond to a question, and contains enough information to look
|
||||
up both the corresponding section and all contained answers (if any).
|
||||
|
||||
Empty sections also appear in the list.
|
||||
|
||||
Each element of the array is an address, similar in structure to
|
||||
L<WebGUI::Asset::Wobject::Survey::SurveyJSON/Address Parameter>,
|
||||
except that instead of an answerIndex in the third slot, we have a sub-array of all contained answer indicies.
|
||||
|
||||
[ $sectionIndex, $questionIndex, [ $answerIndex1, $answerIndex2, ....]
|
||||
|
||||
There is one array element for every section and address in the survey. If there are
|
||||
no questions, or no addresses, those array elements will not be present.
|
||||
|
||||
By making use of L<WebGUI::Asset::Wobject::Survey::SurveyJSON> methods which expect address params as
|
||||
arguments, you can access Section/Question/Answer items in order by iterating over surveyOrder.
|
||||
|
||||
|
|
@ -590,6 +593,23 @@ A variable name to match against all section and question variable names.
|
|||
sub processGoto {
|
||||
my $self = shift;
|
||||
my ($goto) = validate_pos(@_, {type => SCALAR});
|
||||
|
||||
if ($goto eq 'NEXT_SECTION') {
|
||||
$self->session->log->debug("NEXT_SECTION jump target encountered");
|
||||
my $lastResponseSectionIndex = $self->lastResponseSectionIndex;
|
||||
|
||||
# Increment lastRepsonse until nextResponseSectionIndex moves
|
||||
while ($self->nextResponseSectionIndex == $lastResponseSectionIndex) {
|
||||
$self->lastResponse( $self->lastResponse + 1);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if ($goto eq 'END_SURVEY') {
|
||||
$self->session->log->debug("END_SURVEY jump target encountered");
|
||||
$self->lastResponse( scalar( @{ $self->surveyOrder} ) - 1 );
|
||||
return;
|
||||
}
|
||||
|
||||
# Iterate over items in order..
|
||||
my $itemIndex = 0;
|
||||
|
|
|
|||
|
|
@ -414,16 +414,17 @@ Generates the list of valid goto targets
|
|||
sub getGotoTargets {
|
||||
my $self = shift;
|
||||
|
||||
# Valid goto targets are all of the section variable names..
|
||||
my @section_vars = map {$_->{variable}} @{$self->sections};
|
||||
# Valid goto targets are all of the non-empty section variable names..
|
||||
my @section_vars = grep { $_ ne q{} } map {$_->{variable}} @{$self->sections};
|
||||
|
||||
# ..and all of the question variable names..
|
||||
my @question_vars = map {$_->{variable}} @{$self->questions};
|
||||
# ..and all of the non-empty question variable names..
|
||||
my @question_vars = grep { $_ ne q{} } map {$_->{variable}} @{$self->questions};
|
||||
|
||||
# ..excluding the ones that are empty
|
||||
my @grep = grep { $_ ne q{} } (@section_vars, @question_vars);
|
||||
return \@grep;
|
||||
#return grep { $_ ne q{} } (@section_vars, @question_vars);
|
||||
# ..plus some special vars
|
||||
my @special_vars = qw(NEXT_SECTION END_SURVEY);
|
||||
|
||||
# ..all combined
|
||||
return [ @section_vars, @question_vars, @special_vars ];
|
||||
}
|
||||
|
||||
=head2 getSectionEditVars ( $address )
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue