Summaries added to the survey

This commit is contained in:
Kaleb Murphy 2009-04-05 19:33:46 +00:00
parent e918f3ff7b
commit a6a70a46e0
7 changed files with 81 additions and 16 deletions

View file

@ -112,6 +112,14 @@ sub definition {
label => $i18n->get('Max user responses'),
hoverHelp => $i18n->get('Max user responses help'),
},
surveySummaryTemplateId => {
tab => 'display',
fieldType => 'template',
label => $i18n->get('Survey Summary Template'),
hoverHelp => $i18n->get('Survey Summary Template help'),
defaultValue => '7F-BuEHi7t9bPi008H8xZQ',
namespace => 'Survey/Summary',
},
surveyTakeTemplateId => {
tab => 'display',
fieldType => 'template',
@ -1144,6 +1152,14 @@ sub www_submitQuestions {
}
#-------------------------------------------------------------------
sub getSummary{
my $self = shift;
my $summary = $self->responseJSON->showSummary();
my $out = $self->processTemplate( $summary, $self->get('surveySummaryTemplateId') );
return $out;
# return $self->session->style->process( $out, $self->get('styleTemplateId') );
}
#-------------------------------------------------------------------
=head2 www_loadQuestions
@ -1155,7 +1171,7 @@ Determines which questions to display to the survey taker next, loads and return
sub www_loadQuestions {
my $self = shift;
my $wasRestarted = shift;
if ( !$self->canTakeSurvey() ) {
$self->session->log->debug('canTakeSurvey false, surveyEnd');
return $self->surveyEnd();
@ -1175,9 +1191,8 @@ sub www_loadQuestions {
$self->session->log->debug('Response surveyEnd, so calling surveyEnd');
if ( $self->get('quizModeSummary') ) {
if(! $self->session->form->param('shownsummary')){
my $summary = $self->responseJSON->showSummary();
my $out = $self->processTemplate( $summary, $self->get('surveyQuestionsId') );
# return $out;
my $json = to_json( { type => 'summary', summary => $self->getSummary() });
return $json;
}
}
return $self->surveyEnd();
@ -1261,7 +1276,7 @@ sub surveyEnd {
}
}
}
$url = $self->session->url->gateway($url);
$url = $self->session->url->gateway($url) if($url !~ /^http:/i);
#$self->session->http->setRedirect($url);
#$self->session->http->setMimeType('application/json');
my $json = to_json( { type => 'forward', url => $url } );

View file

@ -1117,10 +1117,18 @@ sub showSummary{
my ($sectionIndex, $questionIndex, $answerIndex) = (-1, -1, -1);
my ($currentSection,$currentQuestion) = (-1, -1);
($summaries->{totalCorrect},$summaries->{totalIncorrect}) = (0,0);
for my $response (@$responses){
if(! $all and ! $goodSection{$response->{address}->[0]}){next;}
if($response->{isCorrect}){
$summaries->{totalCorrect}++;
}else{
$summaries->{totalIncorrect}++;
}
$summaries->{totalAnswers}++;
if($currentSection != $response->{address}->[0]){
$summaries->{totalSections}++;
$sectionIndex++;
$questionIndex = -1;
$answerIndex = -1;
@ -1129,6 +1137,7 @@ sub showSummary{
_loadSectionIntoSummary(\%{$summaries->{sections}->[$sectionIndex]},$response);
}
if($currentQuestion != $response->{address}->[1]){
$summaries->{totalQuestions}++;
$questionIndex++;
$answerIndex = -1;
$currentQuestion = $response->{address}->[1];
@ -1145,10 +1154,13 @@ sub _loadAnswerIntoSummary{
my $node = shift;
my $response = shift;
my $types = shift;
$node->{id} = $response->{address}->[2] + 1;
if($response->{isCorrect}){
$node->{iscorrect} = 1;
$node->{score} = $response->{value};
}else{
$node->{iscorrect} = 0;
$node->{score} = 0;
}
$node->{text} = $response->{answerText};
@ -1163,21 +1175,21 @@ sub _loadAnswerIntoSummary{
sub _loadQuestionIntoSummary{
my $node = shift;
my $response = shift;
$node->{id} = $response->{address}->[1];
$node->{id} = $response->{address}->[1] + 1;
$node->{text} = $response->{questionText};
}
sub _loadSectionIntoSummary{
my $node = shift;
my $response = shift;
$node->{id} = $response->{address}->[0];
$node->{id} = $response->{address}->[0] + 1;
$node->{inCorrect} = 0 if(!defined $node->{section}->{inCorrect});
$node->{score} = 0 if(!defined $node->{section}->{score});
$node->{correct} = 0 if(!defined $node->{section}->{correct});
if($response->{isCorrect}){
$node->{score} = 0 if(!defined $node->{section}->{score});
$node->{correct} = 0 if(!defined $node->{section}->{correct});
$node->{score} += $response->{value};
$node->{correct}++;
}else{
$node->{incorrect} = 0 if(!defined $node->{section}->{incorrect});
$node->{incorrect}++;
$node->{inCorrect}++;
}
}

View file

@ -475,6 +475,14 @@ Survey's edit screen|,
context => q|The message shown to the user taking the survey when the survey is restarted after reaching
the time limit for completing the survey. This message is in the 'take survey' template.|,
},
'Quiz mode summaries' => {
message => q|Show quiz mode summaries?|,
lastUpdated => 0,
},
'Quiz mode summaries help' => {
message => q|When set, summaries are shown to users giving their quiz results?|,
lastUpdated => 0,
},
'Show user their progress' => {
message => q|Show user their progress?|,
lastUpdated => 0,
@ -608,6 +616,18 @@ the time limit for completing the survey. This message is in the 'take survey' t
message => q|The template for displaying the screen for editing the survey.|,
lastUpdated => 0
},
'Survey Summary Template' => {
message => q|Survey Summary Template|,
context => q|The template for displaying the summary page to users.|,
lastUpdated => 0
},
'Survey Summary Template help' => {
message => q|This is the template shown to users in quiz mode to summarize their results.|,
context => q|The template for displaying the summary page to users.|,
lastUpdated => 0
},
'Take Survey Template' => {
message => q|Take Survey Template|,