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

raeburn raeburn at source.lon-capa.org
Thu Dec 21 20:55:29 EST 2017


raeburn		Fri Dec 22 01:55:29 2017 EDT

  Modified files:              
    /loncom/homework	structuretags.pm 
  Log:
  - Code in &start_problem() used to (a) display message depending on access
    status of a problem which uses slots, (b) display the web form for 
    proctor validation, (c) check a user into a slot without proctor
    validation, is moved to three separate routines to faciltate re-use:
    &access_status_msg(), &checkin_prompt(), and &selfcheckin_resource().
  
  
-------------- next part --------------
Index: loncom/homework/structuretags.pm
diff -u loncom/homework/structuretags.pm:1.556 loncom/homework/structuretags.pm:1.557
--- loncom/homework/structuretags.pm:1.556	Wed Nov  8 00:34:41 2017
+++ loncom/homework/structuretags.pm	Fri Dec 22 01:55:28 2017
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA 
 # definition of tags that give a structure to a document
 #
-# $Id: structuretags.pm,v 1.556 2017/11/08 00:34:41 raeburn Exp $
+# $Id: structuretags.pm,v 1.557 2017/12/22 01:55:28 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1355,6 +1355,107 @@
     }
 }
 
+sub access_status_msg {
+    my ($mode,$status,$symb,$target,$ipused,$accessmsg) = @_;
+    my $msg;
+    if ($target eq 'web') {
+        if ($status eq 'UNAVAILABLE') {
+            $msg.='<p class="LC_error">'.&mt('Unable to determine if this resource is open due to network problems. Please try again later.').'</p>';
+        } elsif ($status eq 'NOT_IN_A_SLOT') {
+            $msg.='<p class="LC_warning">'.&mt('You are not currently signed up to work at this time and/or place.').'</p>';
+        } elsif (($status eq 'RESERVABLE') || ($status eq 'RESERVABLE_LATER') ||
+                 ($status eq 'NOTRESERVABLE')) {
+            $msg.='<p class="LC_warning">'.&mt('Access requires reservation to work at specific time/place.').'</p>';
+        } elsif ($status ne 'NOT_YET_VIEWED') {
+            $msg.='<p class="LC_warning">'.&mt('Not open to be viewed').'</p>';
+        }
+        if ($status eq 'CLOSED' || $status eq 'INVALID_ACCESS') {
+            $msg.=&mt('The problem ').$accessmsg;
+        } elsif ($status eq 'UNCHECKEDOUT') {
+            $msg.=&checkout_msg();
+        } elsif ($status eq 'NOT_YET_VIEWED') {
+            $msg.=&firstaccess_msg($accessmsg,$symb);
+        } elsif ($status eq 'NOT_IN_A_SLOT') {
+            $msg.=&Apache::bridgetask::add_request_another_attempt_button("Sign up for time to work");
+        } elsif ($status eq 'RESERVABLE') {
+            $msg.=&mt('Available to make a reservation.').' '.&mt('Reservation window closes [_1].',
+                      &Apache::lonnavmaps::timeToHumanString($accessmsg,'end')).
+                      '<br />'.
+                      &Apache::bridgetask::add_request_another_attempt_button("Sign up for time to work");
+        } elsif ($status eq 'RESERVABLE_LATER') {
+            $msg.=&mt('Window to make a reservation will open [_1].',
+                      &Apache::lonnavmaps::timeToHumanString($accessmsg,'start'));
+        } elsif ($status eq 'NOTRESERVABLE') {
+            $msg.=&mt('Not available to make a reservation.');
+        } elsif ($status eq 'NEED_DIFFERENT_IP') {
+            if ($ipused) {
+                $msg.=&mt('You must use the same computer ([_1]) you used when you first accessed this resource using your time/place-based reservation.',"IP: $ipused");
+            } else {
+                $msg.=&mt('Each student must use a different computer to access this resource at this time and/or place.').'<br />'.
+                      &mt('Somebody else has already used this particular computer for that purpose.');
+            }
+        }
+        $msg.='<br />';
+    } elsif ($target eq 'tex') {
+        my $startminipage = ($env{'form.problem_split'}=~/yes/i)? ''
+                             : '\begin{minipage}{\textwidth}';
+
+        $msg ='\noindent \vskip 1 mm '.
+              $startminipage.'\vskip 0 mm';
+        if ($status eq 'UNAVAILABLE') {
+            $msg.=&mt('Unable to determine if this resource is open due to network problems. Please try again later.').'\vskip 0 mm ';
+        } else {
+            $msg.=&mt('Problem is not open to be viewed. It')." $accessmsg \\vskip 0 mm ";
+        }
+    }
+    return $msg;
+}
+
+sub checkin_prompt {
+    my ($target,$slot_name,$slot,$type) = @_;
+    my $result; 
+    if ($target eq 'web') {
+        $result = &Apache::bridgetask::proctor_validation_screen($slot);
+    } elsif ($target eq 'grade') {
+        if (!&Apache::bridgetask::proctor_check_auth($slot_name,$slot,$type)) {
+            $result = &mt('An error occurred during check-in');
+        }
+    }
+    return $result;
+}
+
+sub selfcheckin_resource {
+    my ($resource_due,$slot_name,$slot,$symb) = @_;
+    if ($slot_name ne '') {
+        my $checked_in =
+            $Apache::lonhomework::history{'resource.0.checkedin'};
+        if ($checked_in eq '') {
+            # unproctored slot access, self checkin
+            my $needsiptied;
+            if (ref($slot)) {
+                $needsiptied = $slot->{'iptied'};
+            }
+            my $check = &Apache::bridgetask::check_in('problem',undef,undef,
+                                                      $slot_name,$needsiptied);
+            if ($check =~ /^error: /) {
+                &Apache::lonnet::logthis("Error during self-checkin of problem (symb: $symb) using slot: $slot_name");
+            } else {
+                $checked_in = $Apache::lonhomework::results{"resource.0.checkedin"};
+            }
+        }
+        if ((ref($slot) eq 'HASH') && ($checked_in ne '')) {
+            if ($slot->{'starttime'} < time()) {
+                if (!$resource_due) {
+                    $resource_due = $slot->{'endtime'};
+                } elsif ($slot->{'endtime'} < $resource_due) {
+                    $resource_due = $slot->{'endtime'};
+                }
+            }
+        }
+    }
+    return $resource_due;
+}
+
 sub checkout_msg {
     my %lt=&Apache::lonlocal::texthash( 
 		'resource'=>'The resource needs to be checked out',
@@ -1675,99 +1776,17 @@
             ( $status eq 'NEED_DIFFERENT_IP')) {
 	    my $bodytext=&Apache::lonxml::get_all_text("/problem",$parser,
 						       $style);
-	    if ( $target eq "web" ) {
-		my $msg;
-		if ($status eq 'UNAVAILABLE') {
-		    $msg.='<p class="LC_error">'.&mt('Unable to determine if this resource is open due to network problems. Please try again later.').'</p>';
-                } elsif ($status eq 'NOT_IN_A_SLOT') {
-                    $msg.='<p class="LC_warning">'.&mt('You are not currently signed up to work at this time and/or place.').'</p>';
-                } elsif (($status eq 'RESERVABLE') || ($status eq 'RESERVABLE_LATER') ||
-                         ($status eq 'NOTRESERVABLE')) {
-                    $msg.='<p class="LC_warning">'.&mt('Access requires reservation to work at specific time/place.').'</p>';
-		} elsif ($status ne 'NOT_YET_VIEWED') {
-		    $msg.='<p class="LC_warning">'.&mt('Not open to be viewed').'</p>';
-                }
-		if ($status eq 'CLOSED' || $status eq 'INVALID_ACCESS') {
-		    $msg.=&mt('The problem ').$accessmsg;
-		} elsif ($status eq 'UNCHECKEDOUT') {
-		    $msg.=&checkout_msg();
-		} elsif ($status eq 'NOT_YET_VIEWED') {
-		    $msg.=&firstaccess_msg($accessmsg,$symb);
-		} elsif ($status eq 'NOT_IN_A_SLOT') {
-		    $msg.=&Apache::bridgetask::add_request_another_attempt_button("Sign up for time to work");
-                } elsif ($status eq 'RESERVABLE') {
-                    $msg.=&mt('Available to make a reservation.').' '.&mt('Reservation window closes [_1].',
-                              &Apache::lonnavmaps::timeToHumanString($accessmsg,'end')).
-                          '<br />'.
-                          &Apache::bridgetask::add_request_another_attempt_button("Sign up for time to work");
-                } elsif ($status eq 'RESERVABLE_LATER') {
-                    $msg.=&mt('Window to make a reservation will open [_1].',
-                              &Apache::lonnavmaps::timeToHumanString($accessmsg,'start'));
-                } elsif ($status eq 'NOTRESERVABLE') {
-                    $msg.=&mt('Not available to make a reservation.');  
-		} elsif ($status eq 'NEED_DIFFERENT_IP') {
-                    if ($ipused) {
-                        $msg.=&mt('You must use the same computer ([_1]) you used when you first accessed this resource using your time/place-based reservation.',"IP: $ipused");
-                    } else {
-                        $msg.=&mt('Each student must use a different computer to access this resource at this time and/or place.').'<br />'.
-                              &mt('Somebody else has already used this particular computer for that purpose.');
-                    }
-                }
-		$result.=$msg.'<br />';
-	    } elsif ($target eq 'tex') {
-		my $startminipage = ($env{'form.problem_split'}=~/yes/i)? ''
-		                    : '\begin{minipage}{\textwidth}';
-		$result.='\noindent \vskip 1 mm '.
-		    $startminipage.'\vskip 0 mm';
-		if ($status eq 'UNAVAILABLE') {
-		    $result.=&mt('Unable to determine if this resource is open due to network problems. Please try again later.').'\vskip 0 mm ';
-		} else {
-		    $result.=&mt('Problem is not open to be viewed. It')." $accessmsg \\vskip 0 mm ";
-		}
-	    }
+            $result .= &access_status_msg('problem',$status,$symb,$target,$ipused,$accessmsg);
 	} elsif ($status eq 'NEEDS_CHECKIN') {
 	    my $bodytext=&Apache::lonxml::get_all_text("/problem",$parser,
 						       $style);
-	    if ($target eq 'web') {
-		$result .= 
-		    &Apache::bridgetask::proctor_validation_screen($slot);
-	    } elsif ($target eq 'grade') {
-		my $checkinresult = &Apache::bridgetask::proctor_check_auth($slot_name,$slot,
-							                    'problem');
-                if ($checkinresult = /^error:/) {
-                    $result .= 'error';
-                }
-	    }
+            $result .= &checkin_prompt($target,$slot_name,$slot,'problem');
 	} elsif ($target eq 'web') {
 	    if ($status eq 'CAN_ANSWER') {
                 $resource_due = &Apache::lonhomework::due_date(0, $env{'request.symb'});
                 if ($slot_name ne '') {
-                    my $checked_in =
-                        $Apache::lonhomework::history{'resource.0.checkedin'};
-                    if ($checked_in eq '') {
-                        # unproctored slot access, self checkin
-                        my $needsiptied;
-                        if (ref($slot)) {
-                            $needsiptied = $slot->{'iptied'};
-                        }
-                        my $check = &Apache::bridgetask::check_in('problem',undef,undef,
-                                                                  $slot_name,$needsiptied);
-                        if ($check =~ /^error: /) {
-                            &Apache::lonnet::logthis("Error during self-checkin of problem (symb: $env{'request.symb'}) using slot: $slot_name");
-                        } else {
-                            $checked_in =
-                                $Apache::lonhomework::results{"resource.0.checkedin"};
-                        }
-                    }
-                    if ((ref($slot) eq 'HASH') && ($checked_in ne '')) {
-                        if ($slot->{'starttime'} < time()) {
-                            if (!$resource_due) {
-                                $resource_due = $slot->{'endtime'};
-                            } elsif ($slot->{'endtime'} < $resource_due) {
-                                $resource_due = $slot->{'endtime'};
-                            }
-                        }
-                    }
+                    $resource_due = &selfcheckin_resource($resource_due,$slot_name,$slot,
+                                                          $env{'request.symb'});
                 }
                 if ($resource_due) {
                     my $time_left = $resource_due - time();
@@ -1811,8 +1830,6 @@
 	} elsif ($target eq 'tex') {
 	    $result .= 'INSERTTEXFRONTMATTERHERE';
 	    $result .= &select_metadata_hyphenation();
-	    
-
 	}
     } elsif ($target eq 'edit') {
 	$result .= $form_tag_start.&problem_edit_header();


More information about the LON-CAPA-cvs mailing list