diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index 96de5fffc..029f5a071 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -1,7 +1,7 @@ 7.7.3 - fixed #10094: double explanation in thread help - rfe #9612: Carousel Wobject (was Widget Wobject) (SDH Consulting Group) - + - Survey summaries now added. In the Survey edit, select quiz mode, and a summary will be shown to the user at the end of the survey. 7.7.2 - fixed #10056: YUI javascripts included while adminOff (BNC) - fixed a bug that required you to hit "update cart" before the checkout diff --git a/docs/upgrades/packages-7.7.3/root_import_survey_default-survey-summary.wgpkg b/docs/upgrades/packages-7.7.3/root_import_survey_default-survey-summary.wgpkg new file mode 100644 index 000000000..5037d556a Binary files /dev/null and b/docs/upgrades/packages-7.7.3/root_import_survey_default-survey-summary.wgpkg differ diff --git a/lib/WebGUI/Asset/Wobject/Survey.pm b/lib/WebGUI/Asset/Wobject/Survey.pm index ede348662..4dae8ce10 100644 --- a/lib/WebGUI/Asset/Wobject/Survey.pm +++ b/lib/WebGUI/Asset/Wobject/Survey.pm @@ -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 } ); diff --git a/lib/WebGUI/Asset/Wobject/Survey/ResponseJSON.pm b/lib/WebGUI/Asset/Wobject/Survey/ResponseJSON.pm index 7fc303230..57bce54de 100644 --- a/lib/WebGUI/Asset/Wobject/Survey/ResponseJSON.pm +++ b/lib/WebGUI/Asset/Wobject/Survey/ResponseJSON.pm @@ -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}++; } } diff --git a/lib/WebGUI/i18n/English/Asset_Survey.pm b/lib/WebGUI/i18n/English/Asset_Survey.pm index 85c7532b1..cca7bf4d0 100644 --- a/lib/WebGUI/i18n/English/Asset_Survey.pm +++ b/lib/WebGUI/i18n/English/Asset_Survey.pm @@ -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|, diff --git a/www/extras/wobject/Survey/administersurvey.js b/www/extras/wobject/Survey/administersurvey.js index 86486347a..486ddb094 100644 --- a/www/extras/wobject/Survey/administersurvey.js +++ b/www/extras/wobject/Survey/administersurvey.js @@ -327,6 +327,11 @@ if (typeof Survey === "undefined") { // Public API Survey.Form = { + showSummary: function(html){ + var html = html; + document.getElementById('survey').innerHTML = html; + YAHOO.util.Event.addListener("submitbutton", "click", function(){ Survey.Comm.submitSummary(); }); + }, displayQuestions: function(params){ toValidate = []; var qs = params.questions; diff --git a/www/extras/wobject/Survey/administersurvey/comm.js b/www/extras/wobject/Survey/administersurvey/comm.js index 18d2000aa..b68a4ca68 100644 --- a/www/extras/wobject/Survey/administersurvey/comm.js +++ b/www/extras/wobject/Survey/administersurvey/comm.js @@ -44,14 +44,23 @@ if (typeof Survey === "undefined") { if (response.type === 'displayquestions') { Survey.Form.displayQuestions(response); } - else + else{ if (response.type === 'forward') { - //YAHOO.log("going to "+response.url); - location.href = response.url; + var url; + if(response.url.match(/http/)){ + url = response.url; + }else{ + url = location.protocol+"//"+location.host+"/"+response.url; + } + window.location = url; + } + else if(response.type === 'summary'){ + Survey.Form.showSummary(response.summary); } else { alert("bad response"); } + } }, failure: function(o){ callMade = 0; @@ -63,6 +72,10 @@ if (typeof Survey === "undefined") { } } }, + submitSummary: function(data,functionName){ + var sUrl = "?func=loadQuestions&shownSummary=1"; + request(sUrl, this.callback, null, null, null); + }, callServer: function(data, functionName, form, hasFile){ var postData; if (!form) {