[LON-CAPA-cvs] cvs: loncom /homework response.pm structuretags.pm /publisher packages.tab /xml lonxml.pm

albertel lon-capa-cvs@mail.lon-capa.org
Fri, 01 Apr 2005 18:08:14 -0000


albertel		Fri Apr  1 13:08:14 2005 EDT

  Modified files:              
    /loncom/publisher	packages.tab 
    /loncom/homework	response.pm structuretags.pm 
    /loncom/xml	lonxml.pm 
  Log:
  - BUG# 2331, homework can be done in 'sequential' mode now, Only show part 2 once part 1 is correct, or unanswerable (tries exhausted)
  - added new function &check_status($partid) to check the current status of a part
  
  
  
Index: loncom/publisher/packages.tab
diff -u loncom/publisher/packages.tab:1.41 loncom/publisher/packages.tab:1.42
--- loncom/publisher/packages.tab:1.41	Thu Mar 17 16:21:11 2005
+++ loncom/publisher/packages.tab	Fri Apr  1 13:08:14 2005
@@ -26,6 +26,9 @@
 part&problemstatus&display:Show Problem Status
 part&display&display:Part Description
 part&display&type:string
+part&ordered&type:string_yesno
+part&ordered&default:no
+part&ordered&display:Show Parts 1 at a time
 part_0&hiddenparts&display:List of hidden parts
 part_0&hiddenparts&type:string_any
 part_0&hiddenresource&display:Resource hidden from students
Index: loncom/homework/response.pm
diff -u loncom/homework/response.pm:1.116 loncom/homework/response.pm:1.117
--- loncom/homework/response.pm:1.116	Mon Mar 28 18:19:45 2005
+++ loncom/homework/response.pm	Fri Apr  1 13:08:14 2005
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # various response type definitons response definition
 #
-# $Id: response.pm,v 1.116 2005/03/28 23:19:45 foxr Exp $
+# $Id: response.pm,v 1.117 2005/04/01 18:08:14 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -110,6 +110,7 @@
 	&Apache::lonxml::error("Unable to restore random algorithm.");
     }
 }
+
 sub setrandomnumber {
     my $rndseed;
     $rndseed=&Apache::structuretags::setup_rndseed();
@@ -726,6 +727,37 @@
     # otherwise no submission occured
     return 0;
 }
+
+# basically undef and 0 (both false) mean that they still have work to do
+# and all true values mean that they can't do any more work
+#
+# a return of undef means it is unattempted
+# a return of 0 means it is attmpted and wrong but still has tries
+# a return of 1 means it is marked correct
+# a return of 2 means they have exceed maximum number of tries
+# a return of 3 means it after the answer date
+sub check_status {
+    my ($id)=@_;
+    if (!$id) {	$id=$Apache::linputtags::part; }
+    my $curtime=&Apache::lonnet::EXT('system.time');
+    my $opendate=&Apache::lonnet::EXT("resource.$id.opendate");
+    my $duedate=&Apache::lonnet::EXT("resource.$id.duedate");
+    my $answerdate=&Apache::lonnet::EXT("resource.$id.answerdate");
+    if ( $opendate && $curtime > $opendate &&
+         $duedate && $curtime > $duedate &&
+         $answerdate && $curtime > $answerdate) {
+        return 3;
+    }
+    my $status=&Apache::lonnet::EXT("user.resource.resource.$id.solved");
+    if ($status =~ /^correct/) { return 1; }
+    if (!$status) { return undef; }
+    my $maxtries=&Apache::lonnet::EXT("resource.$id.maxtries");
+    if ($maxtries eq '') { $maxtries=2; }
+    my $curtries=&Apache::lonnet::EXT("user.resource.resource.$id.tries");
+    if ($curtries < $maxtries) { return 0; }
+    return 2;
+}
+
 1;
 __END__
  
Index: loncom/homework/structuretags.pm
diff -u loncom/homework/structuretags.pm:1.282 loncom/homework/structuretags.pm:1.283
--- loncom/homework/structuretags.pm:1.282	Thu Mar 17 08:56:32 2005
+++ loncom/homework/structuretags.pm	Fri Apr  1 13:08:14 2005
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA 
 # definition of tags that give a structure to a document
 #
-# $Id: structuretags.pm,v 1.282 2005/03/17 13:56:32 albertel Exp $
+# $Id: structuretags.pm,v 1.283 2005/04/01 18:08:14 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1066,6 +1066,17 @@
     return $result;
 }
 
+sub ordered_show_check {
+    my $last_part=$Apache::inputtags::partlist[-2];
+    my $in_order=
+	&Apache::lonnet::EXT('resource.'.$Apache::inputtags::part.'.ordered');
+    my $in_order_show=1;
+    if ($last_part ne '0' && lc($in_order) eq 'yes') {
+	$in_order_show=&Apache::response::check_status($last_part);
+    }
+    return $in_order_show;
+}
+
 sub start_part {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
     my $result='';
@@ -1080,7 +1091,7 @@
     my $hidden=&Apache::loncommon::check_if_partid_hidden($Apache::inputtags::part);
     my $newtype=&Apache::lonnet::EXT("resource.$id.type");
     if ($newtype) { $Apache::lonhomework::type=$newtype; }
-
+    my $in_order_show=&ordered_show_check();
     my $expression='$external::part=\''.$Apache::inputtags::part.'\';';
     $expression.='$external::type=\''.$Apache::lonhomework::type.'\';';
     &Apache::run::run($expression,$safeeval);
@@ -1091,7 +1102,7 @@
 	       &Apache::response::meta_parameter_write('display','string',$display,'Part Description');
     } elsif ($target eq 'web' || $target eq 'grade' ||
 	     $target eq 'answer' || $target eq 'tex') {
-	if ($hidden) {
+	if ($hidden || !$in_order_show) {
 	    my $bodytext=&Apache::lonxml::get_all_text("/part",$parser);
 	} else {
 	    my ($status,$accessmsg) = &Apache::lonhomework::check_access($id);
@@ -1171,18 +1182,20 @@
     &Apache::lonxml::debug("in end_part $target ");
     my $status=$Apache::inputtags::status['-1'];
     my $hidden=&Apache::loncommon::check_if_partid_hidden($Apache::inputtags::part);
+    my $in_order_show=&ordered_show_check();
     my $result='';
     if ( $target eq 'meta' ) {
 	$result='';
     } elsif ($target eq 'grade') {
 	if (($status eq 'CAN_ANSWER' || $Apache::lonhomework::scantronmode) &&
-	    !$hidden) {
+	    !$hidden && $in_order_show) {
 	    $result=&Apache::inputtags::grade;
 	} else {
 	    # move any submission data to .hidden
 	    &Apache::inputtags::hidealldata($Apache::inputtags::part);
 	}
-    } elsif (($target eq 'web' || $target eq 'tex') && !$hidden ) {
+    } elsif (($target eq 'web' || $target eq 'tex') &&
+	     !$hidden && $in_order_show) {
 	my $gradestatus=&Apache::inputtags::gradestatus($Apache::inputtags::part,
 							$target);
 	if ($Apache::lonhomework::type eq 'exam' && $target eq 'tex') {
Index: loncom/xml/lonxml.pm
diff -u loncom/xml/lonxml.pm:1.368 loncom/xml/lonxml.pm:1.369
--- loncom/xml/lonxml.pm:1.368	Thu Mar 31 10:55:47 2005
+++ loncom/xml/lonxml.pm	Fri Apr  1 13:08:14 2005
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # XML Parser Module 
 #
-# $Id: lonxml.pm,v 1.368 2005/03/31 15:55:47 albertel Exp $
+# $Id: lonxml.pm,v 1.369 2005/04/01 18:08:14 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -700,6 +700,7 @@
   $safehole->wrap(\&Apache::lonnet::EXT,$safeeval,'&EXT');
   $safehole->wrap(\&Apache::chemresponse::chem_standard_order,$safeeval,
 		  '&chem_standard_order');
+  $safehole->wrap(\&Apache::response::check_status,$safeeval,'&check_status');
 
   $safehole->wrap(\&Math::Cephes::asin,$safeeval,'&asin');
   $safehole->wrap(\&Math::Cephes::acos,$safeeval,'&acos');