From a6a70a46e01658e3c7fe0bed9377df3957c9ea8d Mon Sep 17 00:00:00 2001 From: Kaleb Murphy Date: Sun, 5 Apr 2009 19:33:46 +0000 Subject: [PATCH] Summaries added to the survey --- docs/changelog/7.x.x.txt | 2 +- ...import_survey_default-survey-summary.wgpkg | Bin 0 -> 1161 bytes lib/WebGUI/Asset/Wobject/Survey.pm | 25 +++++++++++++---- .../Asset/Wobject/Survey/ResponseJSON.pm | 26 +++++++++++++----- lib/WebGUI/i18n/English/Asset_Survey.pm | 20 ++++++++++++++ www/extras/wobject/Survey/administersurvey.js | 5 ++++ .../wobject/Survey/administersurvey/comm.js | 19 +++++++++++-- 7 files changed, 81 insertions(+), 16 deletions(-) create mode 100644 docs/upgrades/packages-7.7.3/root_import_survey_default-survey-summary.wgpkg 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 0000000000000000000000000000000000000000..5037d556a2b910e3d8ad855d49b65a401be956c8 GIT binary patch literal 1161 zcmV;41a|u$iwFP!000001MOBzZ`(K!_PM`8(8ZTcEIEGH36Q4A+GuLHaMCVzwOG&= zV>6LSElD|X7ya)YzD(72(mf;#ED#+mne*T`-wbDXSb6y;ilTP2S*gG~YDNAXY@VnR z$8oDwj~exQTnXYhikp=HOkVyeghU*mp&ZQ?`0@RICRf2lHaPYEpFA3M?0*~jJFXwz z3PztP2Jq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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) {