--- loncom/interface/lonplacementtest.pm 2016/04/02 04:30:21 1.1 +++ loncom/interface/lonplacementtest.pm 2016/05/30 03:16:28 1.5 @@ -1,8 +1,7 @@ # The LearningOnline Network with CAPA -# Handler to manage dependencies for HTML files uploaded directly -# to a course. +# Handler for a Placement Test course container # -# $Id: lonplacementtest.pm,v 1.1 2016/04/02 04:30:21 raeburn Exp $ +# $Id: lonplacementtest.pm,v 1.5 2016/05/30 03:16:28 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -20,7 +19,8 @@ # # You should have received a copy of the GNU General Public License # along with LON-CAPA; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA# +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# # /home/httpd/html/adm/gpl.txt # # http://www.lon-capa.org/ @@ -120,13 +120,16 @@ sub check_completion { my $incomplete; if (@resources) { my $firstsymb = $resources[0]->symb(); - my %bytitle; + my (%bytitle,%bysymb); foreach my $res (@resources) { my $currsymb = $res->symb(); my $title = $res->compTitle; unless (exists($bytitle{$title})) { $bytitle{$title} = 0; } + unless (exists($bysymb{$currsymb})) { + $bysymb{$currsymb} = 0; + } my $notdone = 0; my $done = 0; my %storetries; @@ -140,16 +143,18 @@ sub check_completion { if ($tries < $maxtries) { $notdone ++; my $tries = $res->tries($part); - my @response_ids = $res->responseIds($part); - if (@response_ids) { - foreach my $id (@response_ids) { - $storetries{"resource.$part.$id.awarded"}=0; - $storetries{"resource.$part.$id.awarddetail"}='ASSIGNED_SCORE'; + if ($makenew) { + my @response_ids = $res->responseIds($part); + if (@response_ids) { + foreach my $id (@response_ids) { + $storetries{"resource.$part.$id.awarded"}=0; + $storetries{"resource.$part.$id.awarddetail"}='ASSIGNED_SCORE'; + } + $storetries{"resource.$part.tries"}=$maxtries; + $storetries{"resource.$part.solved"}='incorrect_by_override'; + $storetries{"resource.$part.award"}='ASSIGNED_SCORE'; + $storetries{"resource.$part.awarded"}=0; } - $storetries{"resource.$part.tries"}=$maxtries; - $storetries{"resource.$part.solved"}='incorrect_by_override'; - $storetries{"resource.$part.award"}='ASSIGNED_SCORE'; - $storetries{"resource.$part.awarded"}=0; } } else { my $awarded = $res->awarded($part); @@ -169,6 +174,7 @@ sub check_completion { $totaldone += $done; } $bytitle{$title} += $points; + $bysymb{$currsymb} += $points; $totalpoints += $points; } if ($makenew) { @@ -178,16 +184,53 @@ sub check_completion { 4,$newmax,'int_pos', $env{'user.name'}, $env{'user.domain'}); - my %grades = ( - uname => $env{'user.name'}, - domain => $env{'user.domain'}, - total => $totalpoints, - bytitle => \%bytitle, - ); - my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; - my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; - if (($cnum ne '') && ($cdom ne '')) { - &Apache::lonnet::auto_export_grades($cnum,$cdom,\%grades); + my $user = $env{'user.name'}.':'.$env{'user.domain'}; + if ($user) { + my %grades = ( + $user => { + role => $env{'request.role'}, + id => $env{'environment.id'}, + status => $env{'environment.inststatus'}, + lastname => $env{'environment.lastname'}, + firstname => $env{'environment.firstname'}, + permanentemail => $env{'environment.permanentemail'}, + section => $env{'request.course.sec'}, + total => $totalpoints, + category => '', + gradebookcolumn => '', + context => $map, + }, + ); + $grades{$user}{bytitle} = \%bytitle; + $grades{$user}{bysymb} = \%bysymb; + my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; + my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; + my $scope = 'map'; + my $instcode = $env{'course.'.$env{'request.course.id'}.'.internal.coursecode'}; + my $crstype = $env{'course.'.$env{'request.course.id'}.'.type'}; + my $context = 'completion'; + if (($cnum ne '') && ($cdom ne '')) { + my %info = ( + scope => $scope, + instcode => $instcode, + crstype => $crstype, + context => $context, + ); + my $response = &Apache::lonnet::auto_export_grades($cdom,$cnum,\%info,\%grades); + my $outcome; + if (ref($response) eq 'HASH') { + if ($response->{$user}) { + $outcome = 'ok'; + } else { + $outcome = 'fail'; + } + } else { + $outcome = $response; + } + unless ($outcome eq 'ok') { + &Apache::lonnet::logthis("Placement Test grade export for $env{'user.name'}:$env{'user.domain'} in $env{'request.course.id'} was: $outcome"); + } + } } } } @@ -203,57 +246,110 @@ sub check_completion { return ($totalpoints,$incomplete); } +sub is_lastres { + my ($symb,$navmap) = @_; + return unless (ref($navmap)); + my $numforward = 0; + my $currRes = $navmap->getBySymb($symb); + if (ref($currRes)) { + my $it = $navmap->getIterator($currRes,undef,undef,1); + while ( my $res=$it->next()) { + if (ref($res)) { + unless ($res->symb() eq $symb) { + $numforward ++; + } + } + } + } + if (!$numforward) { + return 1; + } + return; +} + +sub has_tries { + my ($symb,$navmap) = @_; + return unless (ref($navmap)); + my $currRes = $navmap->getBySymb($symb); + if (ref($currRes)) { + if ($currRes->is_problem()) { + if ($currRes->tries < $currRes->maxtries) { + return 1; + } + } + } + return; +} + sub showresult { - my ($complete) = @_; + my ($complete,$inhibitmenu) = @_; my ($score) = &Apache::lonplacementtest::check_completion(1,undef,1); my %aclt = &test_action_text(); - my $brcrum = [{'href' => '/adm/flip?postdata=firstres%3a', - 'text' => 'Test Status'},]; - my $output = &Apache::loncommon::start_page('Placement Test Completed', - undef,{bread_crumbs=>$brcrum}); + my $output; + if ($inhibitmenu) { + $output = '
'; + } else { + my $brcrum = [{'href' => '/adm/flip?postdata=firstres%3a', + 'text' => 'Test Status'},]; + $output = &Apache::loncommon::start_page('Placement Test Completed', + undef,{bread_crumbs=>$brcrum}); + } if ($complete) { $output .= '

'.&mt('Test is complete').'

'; } - return $output - .'

'.&mt('You scored [quant,_1,point].',$score).'

' - .&Apache::lonhtmlcommon::actionbox( - [''.$aclt{'newt'}.'', - ''.$aclt{'exit'}.'', - ]) - .&Apache::loncommon::end_page(); + $output .= '

'.&mt('You scored [quant,_1,point].',$score).'

' + .&Apache::lonhtmlcommon::actionbox( + [''.$aclt{'newt'}.'', + ''.$aclt{'exit'}.'', + ]); + unless ($inhibitmenu) { + $output .= &Apache::loncommon::end_page(); + } + return $output; } sub showincomplete { - my ($incomplete) = @_; + my ($incomplete,$inhibitmenu) = @_; my %aclt = &test_action_text(); + my $output; if ($incomplete == 100) { - my $brcrum = [{'href' => '/adm/flip?postdata=firstres%3a', - 'text' => 'Test Status'},]; - return &Apache::loncommon::start_page('Placement Test Unattempted', - undef,{bread_crumbs=>$brcrum}) - .'

'.&mt('Your Placement Test is incomplete.').'

' - .&mt('Currently, you have not submitted any answers for any of the questions.') - .'

' - .&Apache::lonhtmlcommon::actionbox( - [''.$aclt{'begin'}.'', - ''.$aclt{'exit'}.'', - ]) - .&Apache::loncommon::end_page(); + if ($inhibitmenu) { + $output = '
'; + } else { + my $brcrum = [{'href' => '/adm/flip?postdata=firstres%3a', + 'text' => 'Test Status'},]; + $output = &Apache::loncommon::start_page('Placement Test Unattempted', + undef,{bread_crumbs=>$brcrum}); + } + $output .= '

'.&mt('Your Placement Test is incomplete.').'

' + .&mt('Currently, you have not submitted any answers for any of the questions.') + .'

' + .&Apache::lonhtmlcommon::actionbox( + [''.$aclt{'begin'}.'', + ''.$aclt{'exit'}.'', + ]); } elsif ($incomplete) { - my $brcrum = [{'href' => '/adm/flip?postdata=endplacement%3a', - 'text' => 'Test Status'},]; - return &Apache::loncommon::start_page('Incomplete Placement Test', - undef,{bread_crumbs=>$brcrum}) - .'

'.&mt('Your Placement Test is incomplete.').'

' - .&mt('Currently, you have not provided an answer for [_1]% of the questions.',$incomplete) - .'

' - .&Apache::lonhtmlcommon::actionbox( - [''.$aclt{'endt'}.'', - ''.$aclt{'comp'}.'', - ''.$aclt{'exit'}.'', - ]) - .&Apache::loncommon::end_page(); + if ($inhibitmenu) { + $output = '
'; + } else { + my $brcrum = [{'href' => '/adm/flip?postdata=endplacement%3a', + 'text' => 'Test Status'},]; + $output .= &Apache::loncommon::start_page('Incomplete Placement Test', + undef,{bread_crumbs=>$brcrum}); + } + $output .= '

'.&mt('Your Placement Test is incomplete.').'

' + .&mt('Currently, you have not provided an answer for [_1]% of the questions.',$incomplete) + .'

' + .&Apache::lonhtmlcommon::actionbox( + [''.$aclt{'endt'}.'', + ''.$aclt{'comp'}.'', + ''.$aclt{'exit'}.'', + ]); + } + unless ($inhibitmenu) { + $output .= &Apache::loncommon::end_page(); } + return $output; } sub test_action_text {