[LON-CAPA-cvs] cvs: loncom /homework structuretags.pm /interface lonplacementtest.pm

raeburn raeburn at source.lon-capa.org
Mon Apr 4 11:57:07 EDT 2016


raeburn		Mon Apr  4 15:57:07 2016 EDT

  Modified files:              
    /loncom/interface	lonplacementtest.pm 
    /loncom/homework	structuretags.pm 
  Log:
  - Bug 6808. New course container -- "Placement" for Placement Tests.
  
  
-------------- next part --------------
Index: loncom/interface/lonplacementtest.pm
diff -u loncom/interface/lonplacementtest.pm:1.1 loncom/interface/lonplacementtest.pm:1.2
--- loncom/interface/lonplacementtest.pm:1.1	Sat Apr  2 04:30:21 2016
+++ loncom/interface/lonplacementtest.pm	Mon Apr  4 15:56:58 2016
@@ -2,7 +2,7 @@
 # Handler to manage dependencies for HTML files uploaded directly
 # to a course.
 #
-# $Id: lonplacementtest.pm,v 1.1 2016/04/02 04:30:21 raeburn Exp $
+# $Id: lonplacementtest.pm,v 1.2 2016/04/04 15:56:58 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -140,16 +140,18 @@
                 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);
@@ -203,57 +205,104 @@
     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;
+    unless ($inhibitmenu) {
+        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 .= '<p class="LC_info">'.&mt('Test is complete').'</p>';
     }
-    return $output
-          .'<p>'.&mt('You scored [quant,_1,point].',$score).'</p>'
-          .&Apache::lonhtmlcommon::actionbox(
-              ['<a href="/adm/flip?postdata=firstres%3a">'.$aclt{'newt'}.'</a></li>',
-               '<a href="/adm/logout">'.$aclt{'exit'}.'</a></li>',
-              ])
-          .&Apache::loncommon::end_page();
+    $output .= '<p>'.&mt('You scored [quant,_1,point].',$score).'</p>'
+              .&Apache::lonhtmlcommon::actionbox(
+                  ['<a href="/adm/flip?postdata=firstres%3a">'.$aclt{'newt'}.'</a></li>',
+                   '<a href="/adm/logout">'.$aclt{'exit'}.'</a></li>',
+                  ]);
+    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})
-              .'<p class="LC_warning">'.&mt('Your Placement Test is incomplete.').'<p></p>'
-              .&mt('Currently, you have not submitted any answers for any of the questions.')
-              .'</p>'
-              .&Apache::lonhtmlcommon::actionbox(
-                  ['<a href="/adm/flip?postdata=firstres%3a">'.$aclt{'begin'}.'</a></li>',
-                   '<a href="/adm/logout">'.$aclt{'exit'}.'</a></li>',
-                  ])
-              .&Apache::loncommon::end_page(); 
+        unless ($inhibitmenu) {
+            my $brcrum = [{'href' => '/adm/flip?postdata=firstres%3a',
+                           'text' => 'Test Status'},];
+            $output = &Apache::loncommon::start_page('Placement Test Unattempted',
+                                                     undef,{bread_crumbs=>$brcrum});
+        }
+        $output .= '<p class="LC_warning">'.&mt('Your Placement Test is incomplete.').'<p></p>'
+                  .&mt('Currently, you have not submitted any answers for any of the questions.')
+                  .'</p>'
+                  .&Apache::lonhtmlcommon::actionbox(
+                      ['<a href="/adm/flip?postdata=firstres%3a">'.$aclt{'begin'}.'</a></li>',
+                       '<a href="/adm/logout">'.$aclt{'exit'}.'</a></li>',
+                      ]);
     } 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})  
-              .'<p class="LC_warning">'.&mt('Your Placement Test is incomplete.').'<p></p>'
-              .&mt('Currently, you have not provided an answer for [_1]% of the questions.',$incomplete)
-              .'</p>'
-              .&Apache::lonhtmlcommon::actionbox(
-                  ['<a href="/adm/flip?postdata=endplacement%3a">'.$aclt{'endt'}.'</a></li>',
-                   '<a href="/adm/flip?postdata=firstanswerable%3a">'.$aclt{'comp'}.'</a></li>',
-                   '<a href="/adm/logout">'.$aclt{'exit'}.'</a></li>',
-                  ])
-              .&Apache::loncommon::end_page();
+        unless ($inhibitmenu) {
+            my $brcrum = [{'href' => '/adm/flip?postdata=endplacement%3a',
+                           'text' => 'Test Status'},];
+            $output .=  &Apache::loncommon::start_page('Incomplete Placement Test',
+                                                      undef,{bread_crumbs=>$brcrum});
+        }
+        $output .= '<p class="LC_warning">'.&mt('Your Placement Test is incomplete.').'<p></p>'
+                  .&mt('Currently, you have not provided an answer for [_1]% of the questions.',$incomplete)
+                  .'</p>'
+                  .&Apache::lonhtmlcommon::actionbox(
+                      ['<a href="/adm/flip?postdata=endplacement%3a">'.$aclt{'endt'}.'</a></li>',
+                       '<a href="/adm/flip?postdata=firstanswerable%3a">'.$aclt{'comp'}.'</a></li>',
+                       '<a href="/adm/logout">'.$aclt{'exit'}.'</a></li>',
+                      ]);
+    }
+    unless ($inhibitmenu) {
+        $output .= &Apache::loncommon::end_page();
     }
+    return $output;
 }
 
 sub test_action_text {
Index: loncom/homework/structuretags.pm
diff -u loncom/homework/structuretags.pm:1.546 loncom/homework/structuretags.pm:1.547
--- loncom/homework/structuretags.pm:1.546	Sat Apr  2 04:30:39 2016
+++ loncom/homework/structuretags.pm	Mon Apr  4 15:57:07 2016
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA 
 # definition of tags that give a structure to a document
 #
-# $Id: structuretags.pm,v 1.546 2016/04/02 04:30:39 raeburn Exp $
+# $Id: structuretags.pm,v 1.547 2016/04/04 15:57:07 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1926,8 +1926,36 @@
                 # <script></script> so document will be valid xhtml.
                 #
                 my $showdisc = 1;
-                if ($env{'course.'.$env{'request.course.id'}.'.type'} eq 'Placement') { 
+                if (($env{'course.'.$env{'request.course.id'}.'.type'} eq 'Placement') &&
+                    (!$env{'request.role.adv'})) { 
+# For Placement Tests footer with "Post Discussion" and "Send Feedback" links is suppressed.
                     $showdisc = 0;
+                    my ($symb)= &Apache::lonnet::whichuser();
+                    if ($symb) {
+                        my $navmap = Apache::lonnavmaps::navmap->new();
+                        if (ref($navmap)) {
+                            my $hastries = &Apache::lonplacementtest::has_tries($symb,$navmap);  
+# For Placement Tests test status is displayed if this is the last resource in the course
+# and there are no tries left;
+                            unless ($hastries) {
+                                if (&Apache::lonplacementtest::is_lastres($symb,$navmap)) {
+                                    my ($score,$incomplete) = 
+                                        &Apache::lonplacementtest::check_completion(undef,undef,1);
+                                    if (!$incomplete) {
+                                        $result .= &Apache::lonplacementtest::showresult(1,1);
+                                    } elsif ($incomplete < 100) { 
+                                        $result.= &Apache::lonplacementtest::showincomplete($incomplete,1);
+                                    }
+                                } else {
+# For Placement Tests score is displayed if test has just been completed
+                                    my ($score,$incomplete) = &Apache::lonplacementtest::check_completion(undef,undef,1);
+                                    if (!$incomplete) {
+                                        $result.= &Apache::lonplacementtest::showresult(1,1);
+                                    }
+                                }
+                            }
+                        }
+                    }
                 }
 		$result.= &Apache::loncommon::end_page({'discussion' => $showdisc,
 							'notbody'    => 1});


More information about the LON-CAPA-cvs mailing list