Add section separator comments between the subroutines.
Add a few checks to getNextSection* so that it won't autovivify array elements past the end of the survey order array.
This commit is contained in:
parent
d42d4e2569
commit
5fe0a7cbe2
1 changed files with 40 additions and 0 deletions
|
|
@ -32,6 +32,8 @@ use strict;
|
||||||
use JSON;
|
use JSON;
|
||||||
use Data::Dumper;
|
use Data::Dumper;
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------
|
||||||
|
|
||||||
=head2 new ( $json, $log, $survey )
|
=head2 new ( $json, $log, $survey )
|
||||||
|
|
||||||
Object constructor.
|
Object constructor.
|
||||||
|
|
@ -121,6 +123,8 @@ sub createSurveyOrder {
|
||||||
$self->{surveyOrder} = $order;
|
$self->{surveyOrder} = $order;
|
||||||
} ## end sub createSurveyOrder
|
} ## end sub createSurveyOrder
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------
|
||||||
|
|
||||||
=head2 shuffle ( @array )
|
=head2 shuffle ( @array )
|
||||||
|
|
||||||
Returns the contents of @array in a random order.
|
Returns the contents of @array in a random order.
|
||||||
|
|
@ -136,6 +140,8 @@ sub shuffle {
|
||||||
return @a;
|
return @a;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------
|
||||||
|
|
||||||
=head2 freeze
|
=head2 freeze
|
||||||
|
|
||||||
Serializes the object to JSON, after deleting the log and survey objects stored in it.
|
Serializes the object to JSON, after deleting the log and survey objects stored in it.
|
||||||
|
|
@ -150,6 +156,8 @@ sub freeze {
|
||||||
return to_json( \%temp );
|
return to_json( \%temp );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------
|
||||||
|
|
||||||
#Has the survey timed out?
|
#Has the survey timed out?
|
||||||
|
|
||||||
=head2 hasTimedOut ( $limit )
|
=head2 hasTimedOut ( $limit )
|
||||||
|
|
@ -170,6 +178,8 @@ sub hasTimedOut{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------
|
||||||
|
|
||||||
#the index of the last surveyOrder entry shown
|
#the index of the last surveyOrder entry shown
|
||||||
|
|
||||||
=head2 lastResponse ([ $responseIndex ])
|
=head2 lastResponse ([ $responseIndex ])
|
||||||
|
|
@ -194,6 +204,8 @@ sub lastResponse {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------
|
||||||
|
|
||||||
=head2 startTime ([ $newStartTime ])
|
=head2 startTime ([ $newStartTime ])
|
||||||
|
|
||||||
Mutator for the time the user began the survey. With no arguments,
|
Mutator for the time the user began the survey. With no arguments,
|
||||||
|
|
@ -216,6 +228,8 @@ sub startTime {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------
|
||||||
|
|
||||||
#array of addresses in which the survey should be presented
|
#array of addresses in which the survey should be presented
|
||||||
|
|
||||||
=head2 surveyOrder
|
=head2 surveyOrder
|
||||||
|
|
@ -236,6 +250,8 @@ sub surveyOrder {
|
||||||
return $self->{surveyOrder};
|
return $self->{surveyOrder};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------
|
||||||
|
|
||||||
=head2 nextSectionId
|
=head2 nextSectionId
|
||||||
|
|
||||||
Relative to the surveyOrder and the lastResponse index, get the index of the
|
Relative to the surveyOrder and the lastResponse index, get the index of the
|
||||||
|
|
@ -246,9 +262,12 @@ be the same as the current section index.
|
||||||
|
|
||||||
sub nextSectionId {
|
sub nextSectionId {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
|
return undef if $self->surveyEnd();
|
||||||
return $self->surveyOrder->[ $self->lastResponse + 1 ]->[0];
|
return $self->surveyOrder->[ $self->lastResponse + 1 ]->[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------
|
||||||
|
|
||||||
=head2 nextSection
|
=head2 nextSection
|
||||||
|
|
||||||
Relative to the surveyOrder and the lastResponse index, gets the next section.
|
Relative to the surveyOrder and the lastResponse index, gets the next section.
|
||||||
|
|
@ -259,9 +278,12 @@ the current section.
|
||||||
|
|
||||||
sub nextSection {
|
sub nextSection {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
|
return {} if $self->surveyEnd();
|
||||||
return $self->survey->section( [ $self->surveyOrder->[ $self->lastResponse + 1 ]->[0] ] );
|
return $self->survey->section( [ $self->surveyOrder->[ $self->lastResponse + 1 ]->[0] ] );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------
|
||||||
|
|
||||||
=head2 currentSection
|
=head2 currentSection
|
||||||
|
|
||||||
Relative to the surveyOrder and the lastResponse index, get the current section.
|
Relative to the surveyOrder and the lastResponse index, get the current section.
|
||||||
|
|
@ -273,6 +295,8 @@ sub currentSection {
|
||||||
return $self->survey->section( [ $self->surveyOrder->[ $self->lastResponse ]->[0] ] );
|
return $self->survey->section( [ $self->surveyOrder->[ $self->lastResponse ]->[0] ] );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------
|
||||||
|
|
||||||
sub recordResponses {
|
sub recordResponses {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my $session = shift;
|
my $session = shift;
|
||||||
|
|
@ -364,6 +388,8 @@ sub recordResponses {
|
||||||
return [ $terminal, $terminalUrl ];
|
return [ $terminal, $terminalUrl ];
|
||||||
} ## end sub recordResponses
|
} ## end sub recordResponses
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------
|
||||||
|
|
||||||
sub goto {
|
sub goto {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my $goto = shift;
|
my $goto = shift;
|
||||||
|
|
@ -381,6 +407,8 @@ sub goto {
|
||||||
}
|
}
|
||||||
} ## end sub goto
|
} ## end sub goto
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------
|
||||||
|
|
||||||
sub getPreviousAnswer {
|
sub getPreviousAnswer {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my $questionParam = shift;
|
my $questionParam = shift;
|
||||||
|
|
@ -396,6 +424,8 @@ sub getPreviousAnswer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------
|
||||||
|
|
||||||
sub nextQuestions {
|
sub nextQuestions {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
|
|
||||||
|
|
@ -434,6 +464,8 @@ sub nextQuestions {
|
||||||
return $questions;
|
return $questions;
|
||||||
} ## end sub nextQuestions
|
} ## end sub nextQuestions
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------
|
||||||
|
|
||||||
=head2 surveyEnd
|
=head2 surveyEnd
|
||||||
|
|
||||||
Returns true if the current index stored in lastResponse is greater than or
|
Returns true if the current index stored in lastResponse is greater than or
|
||||||
|
|
@ -447,6 +479,8 @@ sub surveyEnd {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------
|
||||||
|
|
||||||
sub returnResponseForReporting {
|
sub returnResponseForReporting {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my @responses = ();
|
my @responses = ();
|
||||||
|
|
@ -490,6 +524,8 @@ sub returnResponseForReporting {
|
||||||
return \@responses;
|
return \@responses;
|
||||||
} ## end sub returnResponseForReporting
|
} ## end sub returnResponseForReporting
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------
|
||||||
|
|
||||||
#the actual responses to the survey. A response is for a question and is accessed by the exact same address as a survey member.
|
#the actual responses to the survey. A response is for a question and is accessed by the exact same address as a survey member.
|
||||||
#Questions only contain the comment and an array of answer Responses.
|
#Questions only contain the comment and an array of answer Responses.
|
||||||
#Answers only contain, entered text, entered verbatim, their index in the Survey Question Answer array, and the assetId to the uploaded file.
|
#Answers only contain, entered text, entered verbatim, their index in the Survey Question Answer array, and the assetId to the uploaded file.
|
||||||
|
|
@ -510,6 +546,8 @@ sub responses {
|
||||||
return $self->{responses};
|
return $self->{responses};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------
|
||||||
|
|
||||||
=head2 responses
|
=head2 responses
|
||||||
|
|
||||||
Returns a referece to the SurveyJSON object that this object was created with.
|
Returns a referece to the SurveyJSON object that this object was created with.
|
||||||
|
|
@ -523,6 +561,8 @@ sub survey {
|
||||||
return $self->{survey};
|
return $self->{survey};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------
|
||||||
|
|
||||||
=head2 log
|
=head2 log
|
||||||
|
|
||||||
Logs an error to the webgui log file, using the session logger.
|
Logs an error to the webgui log file, using the session logger.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue