Branching now works, but now it isn't recognizing the end of the survey properly. Will be easy fix tomorrow.
This commit is contained in:
parent
a4afde5786
commit
ff2ecaa8fc
2 changed files with 45 additions and 15 deletions
|
|
@ -587,10 +587,6 @@ $self->session->errorHandler->error(Dumper $responses);
|
|||
|
||||
my @goodResponses = keys %$responses;#load everything.
|
||||
|
||||
if(@goodResponses == 0){##nothing to load
|
||||
return $self->www_loadQuestions();
|
||||
}
|
||||
|
||||
$self->loadBothJSON();
|
||||
|
||||
my $termInfo = $self->response->recordResponses($responses);
|
||||
|
|
@ -660,8 +656,13 @@ $self->session->errorHandler->error("Can take survey");
|
|||
|
||||
return $self->surveyEnd() if($self->response->surveyEnd());
|
||||
|
||||
my $questions = $self->response->nextQuestions();
|
||||
$self->session->errorHandler->error("Load Questions had ".@$questions." questions");
|
||||
my $questions;
|
||||
eval{
|
||||
$questions = $self->response->nextQuestions();
|
||||
};
|
||||
$self->session->errorHandler->error($@) if($@);
|
||||
|
||||
$self->session->errorHandler->error("Load Questions had ".@$questions." questions") if(ref $questions eq 'ARRAY');
|
||||
|
||||
|
||||
my $section = $self->response->nextSection();
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@ sub new{
|
|||
$self->{log} = $log;
|
||||
$self->{responseId} = $rId;
|
||||
my $temp = decode_json($json) if defined $json;
|
||||
$self->{goto} = defined $temp->{goto} ? $temp->{goto} : [];
|
||||
$self->{surveyOrder} = defined $temp->{surveyOrder} ? $temp->{surveyOrder} : [];#an array of question addresses, with the third member being an array of answers
|
||||
$self->{responses} = defined $temp->{responses} ? $temp->{responses} : {};
|
||||
$self->{lastResponse} = defined $temp->{lastResponse} ? $temp->{lastResponse} : -1;
|
||||
|
|
@ -118,7 +117,10 @@ sub nextSection{
|
|||
my $self = shift;
|
||||
return $self->survey->section([$self->surveyOrder->[$self->lastResponse + 1]->[0]]);
|
||||
}
|
||||
|
||||
sub currentSection{
|
||||
my $self = shift;
|
||||
return $self->survey->section([$self->surveyOrder->[$self->lastResponse]->[0]]);
|
||||
}
|
||||
|
||||
sub recordResponses{
|
||||
my $self = shift;
|
||||
|
|
@ -133,18 +135,27 @@ sub recordResponses{
|
|||
my %fileTypes = ('File Upload',1);
|
||||
my %dateTypes = ('Date','Date Range',1);
|
||||
my %hiddenTypes = ('Hidden',1);
|
||||
|
||||
#These were just submitted from the user, so we need to see what and how they were (un)answered.
|
||||
my $questions = $self->nextQuestions();
|
||||
my $qAnswered = 1;
|
||||
my $terminal = 0;
|
||||
my $terminalUrl;
|
||||
my $goto;
|
||||
my $section = $self->survey->section([$questions->[0]->{sid}]);
|
||||
#my $section = $self->survey->section([$questions->[0]->{sid}]);
|
||||
my $section = $self->currentSection();
|
||||
if($section->{terminal}){
|
||||
$terminal = 1;
|
||||
$terminalUrl = $section->{terminalUrl};
|
||||
}
|
||||
|
||||
#There were no questions in the section just displayed, so increment the lastResponse by one
|
||||
if(ref $questions ne 'ARRAY'){
|
||||
$self->lastResponse($self->lastResponse + 1);
|
||||
$self->log("Incrementing last response by one");
|
||||
return [$terminal,$terminalUrl];
|
||||
}
|
||||
$self->log("There are questions to be submitted in this section");
|
||||
|
||||
for my $question(@$questions){
|
||||
my $aAnswered = 0;
|
||||
if($question->{terminal}){
|
||||
|
|
@ -189,8 +200,21 @@ sub recordResponses{
|
|||
sub goto{
|
||||
my $self = shift;
|
||||
my $goto = shift;
|
||||
|
||||
|
||||
$self->log("In goto for $goto");
|
||||
for(my $i = 0; $i <= $#{$self->surveyOrder()}; $i++){
|
||||
my $section = $self->survey->section($self->surveyOrder()->[$i]);
|
||||
my $question = $self->survey->question($self->surveyOrder()->[$i]);
|
||||
if(ref $section eq 'HASH' and $section->{variable} eq $goto){
|
||||
$self->log("setting lastResponse to section ".($i-1));
|
||||
$self->lastResponse($i - 1);
|
||||
last;
|
||||
}
|
||||
if(ref $question eq 'HASH' and $question->{variable} eq $goto){
|
||||
$self->log("setting lastResponse to question ".($i-1));
|
||||
$self->lastResponse($i - 1);
|
||||
last;
|
||||
}
|
||||
}
|
||||
}
|
||||
sub getPreviousAnswer{
|
||||
my $self = shift;
|
||||
|
|
@ -232,13 +256,15 @@ $self->log("qperpage $qPerPage");
|
|||
|
||||
my $questions;
|
||||
for(my $i = 1; $i <= $qPerPage; $i++){
|
||||
my $qAddy= $self->surveyOrder->[$self->lastResponse + $i];
|
||||
|
||||
my $qAddy = $self->surveyOrder->[$self->lastResponse + $i];
|
||||
$self->log("qAddy was $$qAddy[0]-$$qAddy[1]");
|
||||
next if(! exists $$qAddy[1]);#skip this if it doesn't have a question (for sections with no questions)
|
||||
|
||||
if($$qAddy[0] != $nextSectionId){
|
||||
$self->log("Next question section did not match current section");
|
||||
last;
|
||||
}
|
||||
$self->log("wtf");
|
||||
my %question = %{$self->survey->question([$$qAddy[0],$$qAddy[1]])};
|
||||
$question{'text'} =~ s/\[\[([^\%]*?)\]\]/$self->getPreviousAnswer($1)/eg;
|
||||
delete $question{answers};
|
||||
|
|
@ -252,11 +278,14 @@ $self->log("qAddy was $$qAddy[0]-$$qAddy[1]");
|
|||
}
|
||||
push(@$questions,\%question);
|
||||
}
|
||||
$self->log("Next Questions returning with ");
|
||||
return $questions
|
||||
}
|
||||
|
||||
sub surveyEnd{
|
||||
my $self = shift;
|
||||
return 1 if($self->lastResponse > $#{$self->surveyOrder});
|
||||
$self->log("LR is ".$self->lastResponse." and order is ".$#{$self->surveyOrder});
|
||||
return 1 if($self->lastResponse >= $#{$self->surveyOrder});
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue