diff --git a/docs/upgrades/packages-7.7.17/root_import_survey_default-gradebook-report.wgpkg b/docs/upgrades/packages-7.7.17/root_import_survey_default-gradebook-report.wgpkg new file mode 100644 index 000000000..3781c2457 Binary files /dev/null and b/docs/upgrades/packages-7.7.17/root_import_survey_default-gradebook-report.wgpkg differ diff --git a/lib/WebGUI/Asset/Wobject/Survey.pm b/lib/WebGUI/Asset/Wobject/Survey.pm index 60b673483..529ea1a8d 100644 --- a/lib/WebGUI/Asset/Wobject/Survey.pm +++ b/lib/WebGUI/Asset/Wobject/Survey.pm @@ -405,15 +405,17 @@ sub responseJSON { my $self = shift; my ($json, $responseId) = validate_pos(@_, { type => SCALAR | UNDEF, optional => 1 }, { type => SCALAR, optional => 1}); - $responseId ||= $self->responseId; - - if (!$self->{_responseJSON} || $json) { - - # See if we need to load responseJSON from the database + # Mutate if lazy-loading, or json/responseId provided + if (!$self->{_responseJSON} || $json || $responseId) { + + # Either user-provided, or loaded from L + $responseId ||= $self->responseId; + + # If json undefined, load responseJSON from the db if (!defined $json) { $json = $self->session->db->quickScalar( 'select responseJSON from Survey_response where Survey_responseId = ?', [ $responseId ] ); } - + # Instantiate the ResponseJSON instance, and store it $self->{_responseJSON} = WebGUI::Asset::Wobject::Survey::ResponseJSON->new( $self->surveyJSON, $json ); } @@ -2187,9 +2189,9 @@ Returns the Grade Book screen. =cut sub www_viewGradeBook { - my $self = shift; - my $db = $self->session->db; - + my $self = shift; + my $db = $self->session->db; + return $self->session->privilege->insufficient() if !$self->session->user->isInGroup( $self->get('groupToViewReports') ); @@ -2197,26 +2199,42 @@ sub www_viewGradeBook { $self->loadTempReportTable(); - my $paginator = WebGUI::Paginator->new($self->session,$self->getUrl('func=viewGradebook')); - $paginator->setDataByQuery('select userId,username,ipAddress,Survey_responseId,startDate,endDate' - . ' from Survey_response where assetId=' - . $db->quote($self->getId) - . ' order by username,ipAddress,startDate'); - my $users = $paginator->getPageData; + my $paginator = WebGUI::Paginator->new( $self->session, $self->getUrl('func=viewGradebook') ); + my $userClause = ''; + if (my $userId = $self->session->form->process('userId')) { + $userClause = ' and userId = ' . $db->quote($userId); + } + my $quotedAssetId = $db->quote( $self->getId ); + $paginator->setDataByQuery( <getPageData; $var->{question_count} = $self->surveyJSON->questionCount; - + my @responseloop; - foreach my $user (@{$users}) { - my ($correctCount) = $db->quickArray('select count(*) from Survey_tempReport' - . ' where Survey_responseId=? and isCorrect=1',[$user->{Survey_responseId}]); - push @responseloop, { - # response_url is left out because it looks like Survey doesn't have a viewIndividualSurvey feature - # yet. - #'response_url'=>$self->getUrl('func=viewIndividualSurvey;responseId='.$user->{Survey_responseId}), - 'response_user_name'=>($user->{userId} eq '1') ? $user->{ipAddress} : $user->{username}, - 'response_count_correct' => $correctCount, - 'response_percent' => round(($correctCount/$var->{question_count})*100) + foreach my $row ( @{$rows} ) { + my ($correctCount) + = $db->quickArray( + 'select count(*) from Survey_tempReport' . ' where Survey_responseId=? and isCorrect=1', + [ $row->{Survey_responseId} ] ); + push @responseloop, + { + response_feedback_url => $self->getUrl("func=showFeedback;responseId=$row->{Survey_responseId}"), + response_id => $row->{Survey_responseId}, + response_userId => $row->{userId}, + response_ip => $row->{ip}, + response_startDate => $row->{startDate} + && WebGUI::DateTime->new( $self->session, $row->{startDate} )->toUserTimeZone, + response_endDate => $row->{endDate} + && WebGUI::DateTime->new( $self->session, $row->{endDate} )->toUserTimeZone, + response_user_name => ( $row->{userId} eq '1' ) ? $row->{ipAddress} : $row->{username}, + response_count_correct => $correctCount, + response_percent => round( ( $correctCount / $var->{question_count} ) * 100 ), }; } $var->{response_loop} = \@responseloop; diff --git a/lib/WebGUI/Help/Asset_Survey.pm b/lib/WebGUI/Help/Asset_Survey.pm index a85d73fd6..8fec9787b 100644 --- a/lib/WebGUI/Help/Asset_Survey.pm +++ b/lib/WebGUI/Help/Asset_Survey.pm @@ -81,6 +81,12 @@ our $HELP = { { 'name' => 'question_count' }, { 'name' => 'response_loop', 'variables' => [ + { 'name' => 'response_feedback_url' }, + { 'name' => 'response_id' }, + { 'name' => 'response_userId' }, + { 'name' => 'response_ip' }, + { 'name' => 'response_startDate' }, + { 'name' => 'response_endDate' }, { 'name' => 'response_user_name' }, { 'name' => 'response_count_correct' }, { 'name' => 'response_percent' } diff --git a/lib/WebGUI/i18n/English/Asset_Survey.pm b/lib/WebGUI/i18n/English/Asset_Survey.pm index 1090cf5d1..5505d3a9c 100644 --- a/lib/WebGUI/i18n/English/Asset_Survey.pm +++ b/lib/WebGUI/i18n/English/Asset_Survey.pm @@ -923,6 +923,42 @@ directly inside the answer_loop for other types of questions.|, context => q|Description of a template variable for a template Help page.|, lastUpdated => 1149654771, }, + + response_feedback_url => { + message => q|The URL of the individual response feedback page.|, + context => q|Description of a template variable for a template Help page.|, + lastUpdated => 0, + }, + + response_id => { + message => q|The unique ID of the response.|, + context => q|Description of a template variable for a template Help page.|, + lastUpdated => 0, + }, + + response_userId => { + message => q|The userId of the user that completed the response.|, + context => q|Description of a template variable for a template Help page.|, + lastUpdated => 0, + }, + + response_ip => { + message => q|The IP Address of the user that completed the response.|, + context => q|Description of a template variable for a template Help page.|, + lastUpdated => 0, + }, + + response_startDate => { + message => q|The Start Date of the response.|, + context => q|Description of a template variable for a template Help page.|, + lastUpdated => 0, + }, + + response_endDate => { + message => q|The End Date of the response.|, + context => q|Description of a template variable for a template Help page.|, + lastUpdated => 0, + }, 'survey template common vars title' => { message => q|Survey Template Common Vars|, @@ -1638,6 +1674,16 @@ section/answer.|, message => q{Tests Failed}, lastUpdated => 0, }, + + 'start date' => { + message => q{Start Date}, + lastUpdated => 0, + }, + + 'end date' => { + message => q{End Date}, + lastUpdated => 0, + }, };