Used WG perltidyrc to clean up files
This commit is contained in:
parent
9f9601690a
commit
1d5859631c
3 changed files with 276 additions and 472 deletions
|
|
@ -13,17 +13,15 @@ sub new {
|
|||
$self->{survey} = $survey;
|
||||
$self->{log} = $log;
|
||||
my $temp = decode_json($json) if defined $json;
|
||||
$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;
|
||||
$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;
|
||||
bless( $self, $class );
|
||||
return $self;
|
||||
}
|
||||
} ## end sub new
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
|
|
@ -39,20 +37,18 @@ sub createSurveyOrder {
|
|||
my $self = shift;
|
||||
my $order;
|
||||
my $qstarting = 0;
|
||||
for ( my $s = 0 ; $s <= $#{ $self->survey->sections() } ; $s++ ) {
|
||||
for ( my $s = 0; $s <= $#{ $self->survey->sections() }; $s++ ) {
|
||||
|
||||
#create question order for section
|
||||
my @qorder;
|
||||
if ( $self->survey->section( [$s] )->{randomizeQuestions} ) {
|
||||
@qorder = shuffle(
|
||||
( $qstarting .. $#{ $self->survey->questions( [$s] ) } ) );
|
||||
@qorder = shuffle( ( $qstarting .. $#{ $self->survey->questions( [$s] ) } ) );
|
||||
}
|
||||
else {
|
||||
@qorder =
|
||||
( ( $qstarting .. $#{ $self->survey->questions( [$s] ) } ) );
|
||||
@qorder = ( ( $qstarting .. $#{ $self->survey->questions( [$s] ) } ) );
|
||||
}
|
||||
|
||||
#if this is an empty section, make sure it is still on the list to be seen
|
||||
#if this is an empty section, make sure it is still on the list to be seen
|
||||
if ( @qorder == 0 ) {
|
||||
push( @$order, [$s] );
|
||||
}
|
||||
|
|
@ -62,26 +58,16 @@ sub createSurveyOrder {
|
|||
for (@qorder) {
|
||||
my @aorder;
|
||||
if ( $self->survey->question( [ $s, $_ ] )->{randomizeAnswers} ) {
|
||||
@aorder = shuffle(
|
||||
(
|
||||
$qstarting ..
|
||||
$#{ $self->survey->question( [ $s, $_ ] )->{answers} }
|
||||
)
|
||||
);
|
||||
@aorder = shuffle( ( $qstarting .. $#{ $self->survey->question( [ $s, $_ ] )->{answers} } ) );
|
||||
}
|
||||
else {
|
||||
@aorder = (
|
||||
(
|
||||
$qstarting ..
|
||||
$#{ $self->survey->question( [ $s, $_ ] )->{answers} }
|
||||
)
|
||||
);
|
||||
@aorder = ( ( $qstarting .. $#{ $self->survey->question( [ $s, $_ ] )->{answers} } ) );
|
||||
}
|
||||
push( @$order, [ $s, $_, \@aorder ] );
|
||||
}
|
||||
}
|
||||
} ## end for ( my $s = 0; $s <= ...
|
||||
$self->{surveyOrder} = $order;
|
||||
}
|
||||
} ## end sub createSurveyOrder
|
||||
|
||||
sub shuffle {
|
||||
my @a = splice @_;
|
||||
|
|
@ -125,14 +111,12 @@ sub nextSectionId {
|
|||
|
||||
sub nextSection {
|
||||
my $self = shift;
|
||||
return $self->survey->section(
|
||||
[ $self->surveyOrder->[ $self->lastResponse + 1 ]->[0] ] );
|
||||
return $self->survey->section( [ $self->surveyOrder->[ $self->lastResponse + 1 ]->[0] ] );
|
||||
}
|
||||
|
||||
sub currentSection {
|
||||
my $self = shift;
|
||||
return $self->survey->section(
|
||||
[ $self->surveyOrder->[ $self->lastResponse ]->[0] ] );
|
||||
return $self->survey->section( [ $self->surveyOrder->[ $self->lastResponse ]->[0] ] );
|
||||
}
|
||||
|
||||
sub recordResponses {
|
||||
|
|
@ -141,23 +125,19 @@ sub recordResponses {
|
|||
my $session = shift;
|
||||
|
||||
my %mcTypes = (
|
||||
'Agree/Disagree', 1, 'Certainty', 1, 'Concern', 1,
|
||||
'Confidence', 1, 'Education', 1, 'Effectiveness', 1,
|
||||
'Gender', 1, 'Ideology', 1, 'Importance', 1,
|
||||
'Likelihood', 1, 'Party', 1, 'Multiple Choice', 1,
|
||||
'Oppose/Support', 1, 'Race', 1, 'Risk', 1,
|
||||
'Satisfaction', 1, 'Scale', 1, 'Security', 1,
|
||||
'Threat', 1, 'True/False', 1, 'Yes/No', 1
|
||||
'Agree/Disagree', 1, 'Certainty', 1, 'Concern', 1, 'Confidence', 1, 'Education', 1,
|
||||
'Effectiveness', 1, 'Gender', 1, 'Ideology', 1, 'Importance', 1, 'Likelihood', 1,
|
||||
'Party', 1, 'Multiple Choice', 1, 'Oppose/Support', 1, 'Race', 1, 'Risk', 1,
|
||||
'Satisfaction', 1, 'Scale', 1, 'Security', 1, 'Threat', 1, 'True/False', 1,
|
||||
'Yes/No', 1
|
||||
);
|
||||
my %sliderTypes =
|
||||
( 'Dual Slider - Range', 1, 'Multi Slider - Allocate', 1, 'Slider', 1 );
|
||||
my %textTypes =
|
||||
( 'Currency', 'Email', 1, 'Phone Number', 1, 'Text', 1, 'Text Date', 1 );
|
||||
my %sliderTypes = ( 'Dual Slider - Range', 1, 'Multi Slider - Allocate', 1, 'Slider', 1 );
|
||||
my %textTypes = ( 'Currency', 'Email', 1, 'Phone Number', 1, 'Text', 1, 'Text Date', 1 );
|
||||
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.
|
||||
#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;
|
||||
|
|
@ -171,7 +151,7 @@ sub recordResponses {
|
|||
$terminalUrl = $section->{terminalUrl};
|
||||
}
|
||||
|
||||
#There were no questions in the section just displayed, so increment the lastResponse by one
|
||||
#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 );
|
||||
return [ $terminal, $terminalUrl ];
|
||||
|
|
@ -183,8 +163,7 @@ sub recordResponses {
|
|||
$terminal = 1;
|
||||
$terminalUrl = $question->{terminalUrl};
|
||||
}
|
||||
$self->responses->{ $question->{id} }->{comment} =
|
||||
$responses->{ $question->{id} . "comment" };
|
||||
$self->responses->{ $question->{id} }->{comment} = $responses->{ $question->{id} . "comment" };
|
||||
for my $answer ( @{ $question->{answers} } ) {
|
||||
|
||||
if ( defined( $responses->{ $answer->{id} } )
|
||||
|
|
@ -193,16 +172,13 @@ sub recordResponses {
|
|||
|
||||
$aAnswered = 1;
|
||||
if ( $mcTypes{ $question->{questionType} } ) {
|
||||
$self->responses->{ $answer->{id} }->{value} =
|
||||
$answer->{recordedAnswer};
|
||||
$self->responses->{ $answer->{id} }->{value} = $answer->{recordedAnswer};
|
||||
}
|
||||
else {
|
||||
$self->responses->{ $answer->{id} }->{value} =
|
||||
$responses->{ $answer->{id} };
|
||||
$self->responses->{ $answer->{id} }->{value} = $responses->{ $answer->{id} };
|
||||
}
|
||||
$self->responses->{ $answer->{id} }->{'time'} = time();
|
||||
$self->responses->{ $answer->{id} }->{comment} =
|
||||
$responses->{ $answer->{id} . "comment" };
|
||||
$self->responses->{ $answer->{id} }->{comment} = $responses->{ $answer->{id} . "comment" };
|
||||
|
||||
if ( $answer->{terminal} ) {
|
||||
$terminal = 1;
|
||||
|
|
@ -211,12 +187,12 @@ sub recordResponses {
|
|||
elsif ( $answer->{goto} =~ /\w/ ) {
|
||||
$goto = $answer->{goto};
|
||||
}
|
||||
}
|
||||
}
|
||||
} ## end if ( defined( $responses...
|
||||
} ## end for my $answer ( @{ $question...
|
||||
$qAnswered = 0 if ( !$aAnswered and $question->{required} );
|
||||
}
|
||||
} ## end for my $question (@$questions)
|
||||
|
||||
#if all responses completed, move the lastResponse index to the last question shown
|
||||
#if all responses completed, move the lastResponse index to the last question shown
|
||||
if ($qAnswered) {
|
||||
$self->lastResponse( $self->lastResponse + @$questions );
|
||||
$self->goto($goto) if ( defined $goto );
|
||||
|
|
@ -225,12 +201,12 @@ sub recordResponses {
|
|||
$terminal = 0;
|
||||
}
|
||||
return [ $terminal, $terminalUrl ];
|
||||
}
|
||||
} ## end sub recordResponses
|
||||
|
||||
sub goto {
|
||||
my $self = shift;
|
||||
my $goto = shift;
|
||||
for ( my $i = 0 ; $i <= $#{ $self->surveyOrder() } ; $i++ ) {
|
||||
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 ) {
|
||||
|
|
@ -242,7 +218,7 @@ sub goto {
|
|||
last;
|
||||
}
|
||||
}
|
||||
}
|
||||
} ## end sub goto
|
||||
|
||||
sub getPreviousAnswer {
|
||||
my $self = shift;
|
||||
|
|
@ -251,14 +227,8 @@ sub getPreviousAnswer {
|
|||
my $question = $self->survey->question( [ $$q[0], $$q[1] ] );
|
||||
if ( $question->{variable} eq $questionParam ) {
|
||||
for ( 0 .. @{ $self->survey->answers( [ $$q[0], $$q[1] ] ) } ) {
|
||||
if (
|
||||
exists $self->responses->{ $$q[0] . "-"
|
||||
. $$q[1] . "-"
|
||||
. $_ } )
|
||||
{
|
||||
return $self->responses->{ $$q[0] . "-"
|
||||
. $$q[1] . "-"
|
||||
. $_ }->{value};
|
||||
if ( exists $self->responses->{ $$q[0] . "-" . $$q[1] . "-" . $_ } ) {
|
||||
return $self->responses->{ $$q[0] . "-" . $$q[1] . "-" . $_ }->{value};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -274,41 +244,36 @@ sub nextQuestions {
|
|||
|
||||
my $nextSectionId = $self->nextSectionId;
|
||||
|
||||
my $qPerPage =
|
||||
$self->survey->section( [ $self->nextSectionId ] )->{questionsPerPage};
|
||||
my $qPerPage = $self->survey->section( [ $self->nextSectionId ] )->{questionsPerPage};
|
||||
|
||||
#load Previous answer text
|
||||
my $section = $self->nextSection();
|
||||
$section->{'text'} =~ s/\[\[([^\%]*?)\]\]/$self->getPreviousAnswer($1)/eg;
|
||||
|
||||
my $questions;
|
||||
for ( my $i = 1 ; $i <= $qPerPage ; $i++ ) {
|
||||
for ( my $i = 1; $i <= $qPerPage; $i++ ) {
|
||||
my $qAddy = $self->surveyOrder->[ $self->lastResponse + $i ];
|
||||
next
|
||||
if ( !exists $$qAddy[1] )
|
||||
; #skip this if it doesn't have a question (for sections with no questions)
|
||||
if ( !exists $$qAddy[1] ); #skip this if it doesn't have a question (for sections with no questions)
|
||||
|
||||
if ( $$qAddy[0] != $nextSectionId ) {
|
||||
last;
|
||||
}
|
||||
my %question =
|
||||
%{ $self->survey->question( [ $$qAddy[0], $$qAddy[1] ] ) };
|
||||
$question{'text'} =~
|
||||
s/\[\[([^\%]*?)\]\]/$self->getPreviousAnswer($1)/eg;
|
||||
my %question = %{ $self->survey->question( [ $$qAddy[0], $$qAddy[1] ] ) };
|
||||
$question{'text'} =~ s/\[\[([^\%]*?)\]\]/$self->getPreviousAnswer($1)/eg;
|
||||
delete $question{answers};
|
||||
$question{id} = "$$qAddy[0]-$$qAddy[1]";
|
||||
$question{sid} = "$$qAddy[0]";
|
||||
for ( @{ $$qAddy[2] } ) {
|
||||
my $ans = $self->survey->answer( [ $$qAddy[0], $$qAddy[1], $_ ] );
|
||||
$ans->{'text'} =~
|
||||
s/\[\[([^\%]*?)\]\]/$self->getPreviousAnswer($1)/eg;
|
||||
$ans->{'text'} =~ s/\[\[([^\%]*?)\]\]/$self->getPreviousAnswer($1)/eg;
|
||||
$ans->{id} = "$$qAddy[0]-$$qAddy[1]-$_";
|
||||
push( @{ $question{answers} }, $ans );
|
||||
}
|
||||
push( @$questions, \%question );
|
||||
}
|
||||
} ## end for ( my $i = 1; $i <= ...
|
||||
return $questions;
|
||||
}
|
||||
} ## end sub nextQuestions
|
||||
|
||||
sub surveyEnd {
|
||||
my $self = shift;
|
||||
|
|
@ -327,57 +292,37 @@ sub returnResponseForReporting {
|
|||
for ( @{ $$entry[2] } ) {
|
||||
if ( defined $self->responses->{"$$entry[0]-$$entry[1]-$_"} ) {
|
||||
$self->responses->{"$$entry[0]-$$entry[1]-$_"}->{id} = $_;
|
||||
if ( $self->survey->answer( [ $$entry[0], $$entry[1], $_ ] )
|
||||
->{isCorrect} )
|
||||
{
|
||||
if ( $self->survey->answer( [ $$entry[0], $$entry[1], $_ ] )->{isCorrect} ) {
|
||||
my $value;
|
||||
if ( $self->survey->answer( [ $$entry[0], $$entry[1], $_ ] )
|
||||
->{value} =~ /\w/ )
|
||||
{
|
||||
$value = $self->survey->answer(
|
||||
[ $$entry[0], $$entry[1], $_ ] )->{value};
|
||||
if ( $self->survey->answer( [ $$entry[0], $$entry[1], $_ ] )->{value} =~ /\w/ ) {
|
||||
$value = $self->survey->answer( [ $$entry[0], $$entry[1], $_ ] )->{value};
|
||||
}
|
||||
else {
|
||||
$value =
|
||||
$self->survey->question( [ $$entry[0], $$entry[1] ] )
|
||||
->{value};
|
||||
$value = $self->survey->question( [ $$entry[0], $$entry[1] ] )->{value};
|
||||
}
|
||||
$self->responses->{"$$entry[0]-$$entry[1]-$_"}->{value} =
|
||||
$value;
|
||||
$self->responses->{"$$entry[0]-$$entry[1]-$_"}
|
||||
->{isCorrect} = 1;
|
||||
$self->responses->{"$$entry[0]-$$entry[1]-$_"}->{value} = $value;
|
||||
$self->responses->{"$$entry[0]-$$entry[1]-$_"}->{isCorrect} = 1;
|
||||
}
|
||||
else {
|
||||
$self->responses->{"$$entry[0]-$$entry[1]-$_"}
|
||||
->{isCorrect} = 0;
|
||||
$self->responses->{"$$entry[0]-$$entry[1]-$_"}->{isCorrect} = 0;
|
||||
}
|
||||
push( @answers,
|
||||
( $self->responses->{"$$entry[0]-$$entry[1]-$_"} ) );
|
||||
}
|
||||
}
|
||||
push( @answers, ( $self->responses->{"$$entry[0]-$$entry[1]-$_"} ) );
|
||||
} ## end if ( defined $self->responses...
|
||||
} ## end for ( @{ $$entry[2] } )
|
||||
push(
|
||||
@responses,
|
||||
(
|
||||
{
|
||||
'section',
|
||||
$$entry[0],
|
||||
'question',
|
||||
$$entry[1],
|
||||
'sectionName',
|
||||
$self->survey->section( [ $$entry[0] ] )->{variable},
|
||||
'questionName',
|
||||
$self->survey->question( [ $$entry[0], $$entry[1] ] )
|
||||
->{variable},
|
||||
'questionComment',
|
||||
$self->responses->{"$$entry[0]-$$entry[1]"}->{comment},
|
||||
'answers',
|
||||
\@answers
|
||||
@responses, ( {
|
||||
'section', $$entry[0],
|
||||
'question', $$entry[1],
|
||||
'sectionName', $self->survey->section( [ $$entry[0] ] )->{variable},
|
||||
'questionName', $self->survey->question( [ $$entry[0], $$entry[1] ] )->{variable},
|
||||
'questionComment', $self->responses->{"$$entry[0]-$$entry[1]"}->{comment},
|
||||
'answers', \@answers
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
} ## end for my $entry ( @{ $self...
|
||||
return \@responses;
|
||||
}
|
||||
} ## 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.
|
||||
#Questions only contain the comment and an array of answer Responses.
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ sub new {
|
|||
$self->newObject( [] );
|
||||
}
|
||||
return $self;
|
||||
}
|
||||
} ## end sub new
|
||||
|
||||
sub freeze {
|
||||
my $self = shift;
|
||||
|
|
@ -45,7 +45,7 @@ sub newObject {
|
|||
$$address[2] = $#{ $self->answers($address) };
|
||||
return $address;
|
||||
}
|
||||
}
|
||||
} ## end sub newObject
|
||||
|
||||
#address is the array of objects currently selected in the edit screen
|
||||
#data is the array of hash items for displaying
|
||||
|
|
@ -53,40 +53,32 @@ sub getDragDropList {
|
|||
my $self = shift;
|
||||
my $address = shift;
|
||||
my @data;
|
||||
for ( my $i = 0 ; $i <= $#{ $self->sections } ; $i++ ) {
|
||||
push( @data,
|
||||
{ text => $self->section( [$i] )->{title}, type => 'section' } );
|
||||
for ( my $i = 0; $i <= $#{ $self->sections }; $i++ ) {
|
||||
push( @data, { text => $self->section( [$i] )->{title}, type => 'section' } );
|
||||
if ( $address->[0] == $i ) {
|
||||
|
||||
for ( my $x = 0 ; $x <= $#{ $self->questions($address) } ; $x++ ) {
|
||||
for ( my $x = 0; $x <= $#{ $self->questions($address) }; $x++ ) {
|
||||
push(
|
||||
@data,
|
||||
{
|
||||
@data, {
|
||||
text => $self->question( [ $i, $x ] )->{text},
|
||||
type => 'question'
|
||||
}
|
||||
);
|
||||
if ( $address->[1] == $x ) {
|
||||
for (
|
||||
my $y = 0 ;
|
||||
$y <= $#{ $self->answers($address) } ;
|
||||
$y++
|
||||
)
|
||||
{
|
||||
for ( my $y = 0; $y <= $#{ $self->answers($address) }; $y++ ) {
|
||||
push(
|
||||
@data,
|
||||
{
|
||||
@data, {
|
||||
text => $self->answer( [ $i, $x, $y ] )->{text},
|
||||
type => 'answer'
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} ## end for ( my $x = 0; $x <= ...
|
||||
} ## end if ( $address->[0] == ...
|
||||
} ## end for ( my $i = 0; $i <= ...
|
||||
return \@data;
|
||||
}
|
||||
} ## end sub getDragDropList
|
||||
|
||||
sub getObject {
|
||||
my ( $self, $address ) = @_;
|
||||
|
|
@ -94,12 +86,10 @@ sub getObject {
|
|||
return $self->{sections}->[ $address->[0] ];
|
||||
}
|
||||
elsif ( @$address == 2 ) {
|
||||
return $self->{sections}->[ $address->[0] ]->{questions}
|
||||
->[ $address->[1] ];
|
||||
return $self->{sections}->[ $address->[0] ]->{questions}->[ $address->[1] ];
|
||||
}
|
||||
else {
|
||||
return $self->{sections}->[ $address->[0] ]->{questions}
|
||||
->[ $address->[1] ]->{answers}->[ $address->[2] ];
|
||||
return $self->{sections}->[ $address->[0] ]->{questions}->[ $address->[1] ]->{answers}->[ $address->[2] ];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -138,7 +128,7 @@ sub getSectionEditVars {
|
|||
}
|
||||
}
|
||||
return \%var;
|
||||
}
|
||||
} ## end sub getSectionEditVars
|
||||
|
||||
sub getQuestionEditVars {
|
||||
my $self = shift;
|
||||
|
|
@ -150,22 +140,14 @@ sub getQuestionEditVars {
|
|||
delete $var{answers};
|
||||
delete $var{questionType};
|
||||
my @types = (
|
||||
'Agree/Disagree', 'Certainty',
|
||||
'Concern', 'Confidence',
|
||||
'Currency', 'Date',
|
||||
'Date Range', 'Dual Slider - Range',
|
||||
'Education', 'Effectiveness',
|
||||
'Email', 'File Upload',
|
||||
'Gender', 'Hidden',
|
||||
'Ideology', 'Importance',
|
||||
'Likelihood', 'Multi Slider - Allocate',
|
||||
'Multiple Choice', 'Oppose/Support',
|
||||
'Party', 'Phone Number',
|
||||
'Race', 'Risk',
|
||||
'Satisfaction', 'Scale',
|
||||
'Security', 'Slider',
|
||||
'Text', 'Text Date',
|
||||
'Threat', 'True/False',
|
||||
'Agree/Disagree', 'Certainty', 'Concern', 'Confidence',
|
||||
'Currency', 'Date', 'Date Range', 'Dual Slider - Range',
|
||||
'Education', 'Effectiveness', 'Email', 'File Upload',
|
||||
'Gender', 'Hidden', 'Ideology', 'Importance',
|
||||
'Likelihood', 'Multi Slider - Allocate', 'Multiple Choice', 'Oppose/Support',
|
||||
'Party', 'Phone Number', 'Race', 'Risk',
|
||||
'Satisfaction', 'Scale', 'Security', 'Slider',
|
||||
'Text', 'Text Date', 'Threat', 'True/False',
|
||||
'Yes/No'
|
||||
);
|
||||
|
||||
|
|
@ -178,14 +160,14 @@ sub getQuestionEditVars {
|
|||
}
|
||||
}
|
||||
return \%var;
|
||||
}
|
||||
} ## end sub getQuestionEditVars
|
||||
|
||||
sub getAnswerEditVars {
|
||||
my $self = shift;
|
||||
my $address = shift;
|
||||
my $object = $self->answer($address);
|
||||
my %var = %{$object};
|
||||
$var{id} = $address->[0] . "-" . $address->[1] . "-" . $address->[2];
|
||||
$var{id} = $address->[0] . "-" . $address->[1] . "-" . $address->[2];
|
||||
$var{displayed_id} = $address->[2] + 1;
|
||||
return \%var;
|
||||
}
|
||||
|
|
@ -217,15 +199,14 @@ sub update {
|
|||
}
|
||||
}
|
||||
if ( @$address == 2 and !$newQuestion ) {
|
||||
if ( $ref->{questionType} ne $self->question($address)->{questionType} )
|
||||
{
|
||||
if ( $ref->{questionType} ne $self->question($address)->{questionType} ) {
|
||||
$self->updateQuestionAnswers( $address, $ref->{questionType} );
|
||||
}
|
||||
}
|
||||
for my $key ( keys %$object ) {
|
||||
$object->{$key} = $ref->{$key} if ( defined $$ref{$key} );
|
||||
}
|
||||
}
|
||||
} ## end sub update
|
||||
|
||||
#determine what to add and add it.
|
||||
# ref should contain all the information for the new
|
||||
|
|
@ -262,8 +243,7 @@ sub remove {
|
|||
my ( $self, $address, $movingOverride ) = @_;
|
||||
if ( @$address == 1 ) {
|
||||
splice( @{ $self->{sections} }, $$address[0], 1 )
|
||||
if ( $$address[0] != 0 or defined $movingOverride )
|
||||
; #can't delete the first section
|
||||
if ( $$address[0] != 0 or defined $movingOverride ); #can't delete the first section
|
||||
}
|
||||
elsif ( @$address == 2 ) {
|
||||
splice( @{ $self->questions($address) }, $$address[1], 1 );
|
||||
|
|
@ -275,18 +255,12 @@ sub remove {
|
|||
|
||||
sub newSection {
|
||||
my %members = (
|
||||
'text', '',
|
||||
'title', 'NEW SECTION',
|
||||
'variable', '',
|
||||
'questionsPerPage', 5,
|
||||
'questionsOnSectionPage', 1,
|
||||
'randomizeQuestions', 0,
|
||||
'everyPageTitle', 1,
|
||||
'everyPageText', 1,
|
||||
'terminal', 0,
|
||||
'terminalUrl', '',
|
||||
'goto', '',
|
||||
'timeLimit', 0,
|
||||
'text', '', 'title', 'NEW SECTION',
|
||||
'variable', '', 'questionsPerPage', 5,
|
||||
'questionsOnSectionPage', 1, 'randomizeQuestions', 0,
|
||||
'everyPageTitle', 1, 'everyPageText', 1,
|
||||
'terminal', 0, 'terminalUrl', '',
|
||||
'goto', '', 'timeLimit', 0,
|
||||
'type', 'section'
|
||||
);
|
||||
$members{questions} = [];
|
||||
|
|
@ -315,17 +289,12 @@ sub newQuestion {
|
|||
);
|
||||
$members{answers} = [];
|
||||
return \%members;
|
||||
}
|
||||
} ## end sub newQuestion
|
||||
|
||||
sub newAnswer {
|
||||
my %members = (
|
||||
'text', '', 'verbatim', 0,
|
||||
'textCols', 10, 'textRows', 5,
|
||||
'goto', '', 'recordedAnswer', '',
|
||||
'isCorrect', 1, 'min', 1,
|
||||
'max', 10, 'step', 1,
|
||||
'value', 1, 'terminal', 0,
|
||||
'terminalUrl', '', 'type', 'answer'
|
||||
'text', '', 'verbatim', 0, 'textCols', 10, 'textRows', 5, 'goto', '', 'recordedAnswer', '', 'isCorrect', 1,
|
||||
'min', 1, 'max', 10, 'step', 1, 'value', 1, 'terminal', 0, 'terminalUrl', '', 'type', 'answer'
|
||||
);
|
||||
return \%members;
|
||||
}
|
||||
|
|
@ -380,20 +349,12 @@ sub updateQuestionAnswers {
|
|||
$self->addAnswersToQuestion( \@addy, \@ans, { 7, 1 } );
|
||||
}
|
||||
elsif ( $type eq 'Party' ) {
|
||||
my @ans = (
|
||||
'Democratic party',
|
||||
'Republican party (or GOP)',
|
||||
'Independant party',
|
||||
'Other party (verbatim)'
|
||||
);
|
||||
my @ans = ( 'Democratic party', 'Republican party (or GOP)', 'Independant party', 'Other party (verbatim)' );
|
||||
$self->addAnswersToQuestion( \@addy, \@ans, { 3, 1 } );
|
||||
}
|
||||
elsif ( $type eq 'Race' ) {
|
||||
my @ans = (
|
||||
'American Indian', 'Asian',
|
||||
'Black', 'Hispanic',
|
||||
'White non-Hispanic', 'Something else (verbatim)'
|
||||
);
|
||||
my @ans
|
||||
= ( 'American Indian', 'Asian', 'Black', 'Hispanic', 'White non-Hispanic', 'Something else (verbatim)' );
|
||||
$self->addAnswersToQuestion( \@addy, \@ans, { 5, 1 } );
|
||||
}
|
||||
elsif ( $type eq 'Ideology' ) {
|
||||
|
|
@ -409,69 +370,43 @@ sub updateQuestionAnswers {
|
|||
$self->addAnswersToQuestion( \@addy, \@ans, {} );
|
||||
}
|
||||
elsif ( $type eq 'Security' ) {
|
||||
my @ans = (
|
||||
'Not at all secure',
|
||||
'', '', '', '', '', '', '', '', '', 'Extremely secure'
|
||||
);
|
||||
my @ans = ( 'Not at all secure', '', '', '', '', '', '', '', '', '', 'Extremely secure' );
|
||||
$self->addAnswersToQuestion( \@addy, \@ans, {} );
|
||||
}
|
||||
elsif ( $type eq 'Threat' ) {
|
||||
my @ans =
|
||||
( 'No threat', '', '', '', '', '', '', '', '', '', 'Extreme threat' );
|
||||
my @ans = ( 'No threat', '', '', '', '', '', '', '', '', '', 'Extreme threat' );
|
||||
$self->addAnswersToQuestion( \@addy, \@ans, {} );
|
||||
}
|
||||
elsif ( $type eq 'Risk' ) {
|
||||
my @ans =
|
||||
( 'No risk', '', '', '', '', '', '', '', '', '', 'Extreme risk' );
|
||||
my @ans = ( 'No risk', '', '', '', '', '', '', '', '', '', 'Extreme risk' );
|
||||
$self->addAnswersToQuestion( \@addy, \@ans, {} );
|
||||
}
|
||||
elsif ( $type eq 'Concern' ) {
|
||||
my @ans = (
|
||||
'Not at all concerned',
|
||||
'', '', '', '', '', '', '', '', '', 'Extremely concerned'
|
||||
);
|
||||
my @ans = ( 'Not at all concerned', '', '', '', '', '', '', '', '', '', 'Extremely concerned' );
|
||||
$self->addAnswersToQuestion( \@addy, \@ans, {} );
|
||||
}
|
||||
elsif ( $type eq 'Effectiveness' ) {
|
||||
my @ans = (
|
||||
'Not at all effective',
|
||||
'', '', '', '', '', '', '', '', '', 'Extremely effective'
|
||||
);
|
||||
my @ans = ( 'Not at all effective', '', '', '', '', '', '', '', '', '', 'Extremely effective' );
|
||||
$self->addAnswersToQuestion( \@addy, \@ans, {} );
|
||||
}
|
||||
elsif ( $type eq 'Confidence' ) {
|
||||
my @ans = (
|
||||
'Not at all confident',
|
||||
'', '', '', '', '', '', '', '', '', 'Extremely confident'
|
||||
);
|
||||
my @ans = ( 'Not at all confident', '', '', '', '', '', '', '', '', '', 'Extremely confident' );
|
||||
$self->addAnswersToQuestion( \@addy, \@ans, {} );
|
||||
}
|
||||
elsif ( $type eq 'Satisfaction' ) {
|
||||
my @ans = (
|
||||
'Not at all satisfied',
|
||||
'', '', '', '', '', '', '', '', '', 'Extremely satisfied'
|
||||
);
|
||||
my @ans = ( 'Not at all satisfied', '', '', '', '', '', '', '', '', '', 'Extremely satisfied' );
|
||||
$self->addAnswersToQuestion( \@addy, \@ans, {} );
|
||||
}
|
||||
elsif ( $type eq 'Certainty' ) {
|
||||
my @ans = (
|
||||
'Not at all certain',
|
||||
'', '', '', '', '', '', '', '', '', 'Extremely certain'
|
||||
);
|
||||
my @ans = ( 'Not at all certain', '', '', '', '', '', '', '', '', '', 'Extremely certain' );
|
||||
$self->addAnswersToQuestion( \@addy, \@ans, {} );
|
||||
}
|
||||
elsif ( $type eq 'Likelihood' ) {
|
||||
my @ans = (
|
||||
'Not at all likely',
|
||||
'', '', '', '', '', '', '', '', '', 'Extremely likely'
|
||||
);
|
||||
my @ans = ( 'Not at all likely', '', '', '', '', '', '', '', '', '', 'Extremely likely' );
|
||||
$self->addAnswersToQuestion( \@addy, \@ans, {} );
|
||||
}
|
||||
elsif ( $type eq 'Importance' ) {
|
||||
my @ans = (
|
||||
'Not at all important',
|
||||
'', '', '', '', '', '', '', '', '', 'Extremely important'
|
||||
);
|
||||
my @ans = ( 'Not at all important', '', '', '', '', '', '', '', '', '', 'Extremely important' );
|
||||
$self->addAnswersToQuestion( \@addy, \@ans, {} );
|
||||
}
|
||||
elsif ( $type eq 'Oppose/Support' ) {
|
||||
|
|
@ -497,7 +432,7 @@ sub updateQuestionAnswers {
|
|||
else {
|
||||
push( @{ $question->{answers} }, $self->newAnswer() );
|
||||
}
|
||||
}
|
||||
} ## end sub updateQuestionAnswers
|
||||
|
||||
sub addAnswersToQuestion {
|
||||
my $self = shift;
|
||||
|
|
@ -508,16 +443,13 @@ sub addAnswersToQuestion {
|
|||
push( @{ $self->question($addy)->{answers} }, $self->newAnswer() );
|
||||
$$addy[2] = $_;
|
||||
if ( defined $$verbs{$_} and $_ == $$verbs{$_} ) {
|
||||
$self->update( $addy,
|
||||
{ 'text', $$ans[$_], 'recordedAnswer', $_ + 1, 'verbatim', 1 }
|
||||
);
|
||||
$self->update( $addy, { 'text', $$ans[$_], 'recordedAnswer', $_ + 1, 'verbatim', 1 } );
|
||||
}
|
||||
else {
|
||||
$self->update( $addy,
|
||||
{ 'text', $$ans[$_], 'recordedAnswer', $_ + 1 } );
|
||||
$self->update( $addy, { 'text', $$ans[$_], 'recordedAnswer', $_ + 1 } );
|
||||
}
|
||||
}
|
||||
}
|
||||
} ## end sub addAnswersToQuestion
|
||||
|
||||
#------------------------------
|
||||
#accessors and helpers
|
||||
|
|
@ -548,15 +480,13 @@ sub question {
|
|||
sub answers {
|
||||
my $self = shift;
|
||||
my $address = shift;
|
||||
return $self->{sections}->[ $$address[0] ]->{questions}->[ $$address[1] ]
|
||||
->{answers};
|
||||
return $self->{sections}->[ $$address[0] ]->{questions}->[ $$address[1] ]->{answers};
|
||||
}
|
||||
|
||||
sub answer {
|
||||
my $self = shift;
|
||||
my $address = shift;
|
||||
return $self->{sections}->[ $$address[0] ]->{questions}->[ $$address[1] ]
|
||||
->{answers}->[ $$address[2] ];
|
||||
return $self->{sections}->[ $$address[0] ]->{questions}->[ $$address[1] ]->{answers}->[ $$address[2] ];
|
||||
}
|
||||
|
||||
sub log {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue