[LON-CAPA-cvs] cvs: loncom /homework essayresponse.pm matchresponse.pm optionresponse.pm radiobuttonresponse.pm rankresponse.pm response.pm /homework/caparesponse caparesponse.pm /interface loncommon.pm

albertel lon-capa-cvs-allow@mail.lon-capa.org
Tue, 17 Apr 2007 23:25:42 -0000


This is a MIME encoded message

--albertel1176852342
Content-Type: text/plain

albertel		Tue Apr 17 19:25:42 2007 EDT

  Modified files:              
    /loncom/homework	essayresponse.pm matchresponse.pm 
                    	optionresponse.pm radiobuttonresponse.pm 
                    	rankresponse.pm response.pm 
    /loncom/homework/caparesponse	caparesponse.pm 
    /loncom/interface	loncommon.pm 
  Log:
  - 2622, refactoring out some code, essay response also works now
  
  
--albertel1176852342
Content-Type: text/plain
Content-Disposition: attachment; filename="albertel-20070417192542.txt"

Index: loncom/homework/essayresponse.pm
diff -u loncom/homework/essayresponse.pm:1.81 loncom/homework/essayresponse.pm:1.82
--- loncom/homework/essayresponse.pm:1.81	Mon Jan  8 06:12:44 2007
+++ loncom/homework/essayresponse.pm	Tue Apr 17 19:25:09 2007
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # essay (ungraded) style responses
 #
-# $Id: essayresponse.pm,v 1.81 2007/01/08 11:12:44 foxr Exp $
+# $Id: essayresponse.pm,v 1.82 2007/04/17 23:25:09 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -175,6 +175,11 @@
 						{'no_verbatim' => 1});
 	$result.=&Apache::response::answer_footer($$tagstack[-1]);
     }
+    if ($target eq 'web') {
+	&Apache::response::setup_prior_tries_hash(\&format_prior_response,
+						  ['portfiles',
+						   'uploadedurl']);
+    }
 
     if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' ||
 	$target eq 'tex' || $target eq 'analyze') {
@@ -185,6 +190,36 @@
     return $result;
 }
 
+sub format_prior_response {
+    my ($mode,$answer,$other_data) = @_;
+    my $output;
+
+    my (undef,undef,$udom,$uname) = &Apache::lonnet::whichuser();
+    my $port_url = '/uploaded/'.$udom.'/'.$uname.'/portfolio/';
+
+    my $file_list;
+
+    foreach my $file (split(/\s*,\s*/,
+			    $other_data->[0].','.$other_data->[1])) {
+	next if ($file!~/\S/);
+	if ($file !~ m{^/uploaded/}) { $file=$port_url.$file; }
+	$file=~s|/+|/|g;
+	&Apache::lonnet::allowuploaded('/adm/essayresponse',$file);
+	$file_list.='<li><span class="LC_nobreak"><a href="'.$file.'?rawmode=1" target="lonGRDs"><img src="'.
+	    &Apache::loncommon::icon($file).'" alt="file icon" border="0" /> '.$file.
+	    '</a></span></li>'."\n";
+    }
+    if ($file_list) {
+	$output.= &mt('Submitted Files').'<ul>'.$file_list.'</ul>';
+    }
+    if ($answer =~ /\S/) {
+	$output.='<p>'.&mt('Submitted text').
+	    '<blockquote>'.$answer.'</blockquote></p>';
+    }
+
+    return '<div class="LC_prior_essay">'.$output.'</div>';
+}
+
 sub file_submission {
     my ($part,$id,$which,$award,$uploadedflag)=@_;
     my $files;
Index: loncom/homework/matchresponse.pm
diff -u loncom/homework/matchresponse.pm:1.63 loncom/homework/matchresponse.pm:1.64
--- loncom/homework/matchresponse.pm:1.63	Wed Apr 11 05:20:32 2007
+++ loncom/homework/matchresponse.pm	Tue Apr 17 19:25:09 2007
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Full matching style response
 #
-# $Id: matchresponse.pm,v 1.63 2007/04/11 09:20:32 foxr Exp $
+# $Id: matchresponse.pm,v 1.64 2007/04/17 23:25:09 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -415,6 +415,24 @@
     }
 }
 
+sub format_prior_answer {
+    my ($mode,$answer,$other_data) = @_;
+    my %answer      =&Apache::lonnet::str2hash($answer);
+    my $foil_order  =$other_data->[0];
+    my %grading     =&Apache::lonnet::str2hash($other_data->[1]);
+    my @items       =&Apache::lonnet::str2array($other_data->[2]);
+    my $output;
+    
+    foreach my $name (@{ $foil_order }) {
+	my $item=shift(@items);
+	$output .= '<tr><td>'.$item.'</td></tr>';
+    }
+    return if (!defined($output));
+
+    $output = '<table class="LC_prior_match">'.$output.'</table>';
+    return $output;
+}
+
 sub itemdisplay {
     my ($location)=@_;
     if ($location eq 'top' &&
@@ -426,6 +444,7 @@
     }
     return undef;
 }
+
 sub displayfoils {
     my ($target,$max,$randomize)=@_;
     my ($tabsize, $lefttabsize, $righttabsize);
@@ -576,6 +595,12 @@
 	    $result='\setlength{\tabcolsep}{1 mm}\begin{tabular}{p{'.$lefttabsize.'}p{'.$righttabsize.'}}\begin{minipage}{'.$lefttabsize.'}'.$result.'\end{minipage}&\begin{minipage}{'.$righttabsize.'}'.$question.'\end{minipage}\end{tabular}';
 	}
     }
+    if ($target eq 'web') {
+	&Apache::response::setup_prior_tries_hash(\&format_prior_answer,
+						  [\@whichfoils,
+						   'submissiongrading',
+						   'submissionitems']);
+    }
     if ($target ne 'tex') {$result.="<br />";} else {$result.=' \\\\ ';}
     return $result;
 }
Index: loncom/homework/optionresponse.pm
diff -u loncom/homework/optionresponse.pm:1.142 loncom/homework/optionresponse.pm:1.143
--- loncom/homework/optionresponse.pm:1.142	Mon Apr 16 18:50:41 2007
+++ loncom/homework/optionresponse.pm	Tue Apr 17 19:25:09 2007
@@ -1,7 +1,7 @@
 # LearningOnline Network with CAPA
 # option list style responses
 #
-# $Id: optionresponse.pm,v 1.142 2007/04/16 22:50:41 albertel Exp $
+# $Id: optionresponse.pm,v 1.143 2007/04/17 23:25:09 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -355,27 +355,6 @@
     }
 }
 
-sub setup_prior_tries_hash {
-    my ($whichopt) = @_;
-    my $part=$Apache::inputtags::part;
-    my $id=$Apache::inputtags::response[-1];	
-    foreach my $i (1..$Apache::lonhomework::history{'version'}) {
-	my $key = "$i:resource.$part.$id.submission";
-	next if (!exists($Apache::lonhomework::history{"$key"}));
-	my %lastresponse=
-	    &Apache::lonnet::str2hash($Apache::lonhomework::history{$key});
-	my $output;
-	foreach my $name (@$whichopt) {
-	    next if (!defined($lastresponse{$name}));
-	    $output .= '<tr><td>'.$lastresponse{$name}.'</td></tr>';
-	}
-	next if (!defined($output));
-	$output =
-	    '<table class="LC_prior_option">'.$output.'</table>';
-	$Apache::inputtags::submission_display{$key} = $output;
-    }
-}
-
 sub displayfoils {
   my ($target,$max,$randomize,$TeXlayout,@opt)=@_;
   if (!defined(@{ $Apache::response::foilgroup{'names'} })) {return;}
@@ -499,7 +478,9 @@
   }
 
   if ($target eq 'web') {
-      &setup_prior_tries_hash(\@whichopt);
+      &Apache::response::setup_prior_tries_hash(\&Apache::rankresponse::format_prior_answer,
+						[\@whichopt,
+						 'submissiongrading']);
   }
 
   if ($target ne 'tex') {
Index: loncom/homework/radiobuttonresponse.pm
diff -u loncom/homework/radiobuttonresponse.pm:1.113 loncom/homework/radiobuttonresponse.pm:1.114
--- loncom/homework/radiobuttonresponse.pm:1.113	Tue Mar 27 15:20:49 2007
+++ loncom/homework/radiobuttonresponse.pm	Tue Apr 17 19:25:09 2007
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # mutliple choice style responses
 #
-# $Id: radiobuttonresponse.pm,v 1.113 2007/03/27 19:20:49 albertel Exp $
+# $Id: radiobuttonresponse.pm,v 1.114 2007/04/17 23:25:09 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -180,9 +180,6 @@
 	if ( $style eq 'survey'  && $target ne 'analyze') {
 	    if ($target eq 'web' || $target eq 'tex') {
 		$result=&displayallfoils($direction, $target);
-		if ($target eq 'web') {
-		    &setup_prior_tries_hash();
-		}
 	    } elsif ( $target eq 'answer' ) {
 		$result=&displayallanswers();
 	    } elsif ( $target eq 'grade' ) {
@@ -196,9 +193,6 @@
 						       $safeeval,'-2');
 	    if ($target eq 'web' || $target eq 'tex') {
 		$result=&displayfoils($target,$max,$randomize,$direction);
-		if ($target eq 'web') {
-		    &setup_prior_tries_hash();
-		}
 	    } elsif ($target eq 'answer' ) {
 		$result=&displayanswers($max,$randomize);
 	    } elsif ( $target eq 'grade') {
@@ -214,6 +208,11 @@
 	}
 	$Apache::lonxml::post_evaluate=0;
     }
+    if ($target eq 'web') {
+	&Apache::response::setup_prior_tries_hash(\&format_prior_answer,
+						  [\%Apache::response::foilgroup]);
+    }
+    
     &Apache::response::poprandomnumber();
     &Apache::lonxml::increment_counter();
     return $result;
@@ -237,18 +236,14 @@
     return ($truecnt,$falsecnt);
 }
 
-sub setup_prior_tries_hash {
-    my $part=$Apache::inputtags::part;
-    my $id=$Apache::inputtags::response[-1];	
-    foreach my $i (1..$Apache::lonhomework::history{'version'}) {
-	my $key = "$i:resource.$part.$id.submission";
-	next if (!exists($Apache::lonhomework::history{"$key"}));
-	my %response = 
-	    &Apache::lonnet::str2hash($Apache::lonhomework::history{$key});
-	my ($name) = keys(%response);
-	$Apache::inputtags::submission_display{$key} = 
-	    $Apache::response::foilgroup{$name.'.text'}
-    }
+sub format_prior_answer {
+    my ($mode,$answer,$other_data) = @_;
+    my $foil_data = $other_data->[0];
+    my %response = &Apache::lonnet::str2hash($answer);
+    my ($name)   = keys(%response);
+    return '<span class="LC_prior_radiobutton">'.
+	$foil_data->{$name.'.text'}.'</span>';
+
 }
 
 sub displayallfoils {
Index: loncom/homework/rankresponse.pm
diff -u loncom/homework/rankresponse.pm:1.51 loncom/homework/rankresponse.pm:1.52
--- loncom/homework/rankresponse.pm:1.51	Tue Mar 27 15:20:49 2007
+++ loncom/homework/rankresponse.pm	Tue Apr 17 19:25:09 2007
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # rank style response
 #
-# $Id: rankresponse.pm,v 1.51 2007/03/27 19:20:49 albertel Exp $
+# $Id: rankresponse.pm,v 1.52 2007/04/17 23:25:09 albertel Exp $
 # Copyright Michigan State University Board of Trustees
 #
 # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
@@ -264,6 +264,22 @@
     &Apache::response::handle_previous(\%previous,$ad);
 }
 
+sub format_prior_answer {
+    my ($mode,$answer,$other_data) = @_;
+    my %lastresponse=&Apache::lonnet::str2hash($answer);
+    my $foil_order  =$other_data->[0];
+    my %grading     =&Apache::lonnet::str2hash($other_data->[1]);
+    my $output;
+    foreach my $name (@{ $foil_order }) {
+	next if (!defined($lastresponse{$name}));
+	$output .= '<tr><td>'.$lastresponse{$name}.'</td></tr>';
+    }
+    return if (!defined($output));
+    $output =
+	'<table class="LC_prior_rank">'.$output.'</table>';
+    return $output;
+}
+
 sub displayfoils {
     my ($target,$max,$randomize,$tol)=@_;
     my $result;
@@ -335,6 +351,11 @@
 	    $temp++;
 	}
     }
+    if ($target eq 'web') {
+	&Apache::response::setup_prior_tries_hash(\&format_prior_answer,
+						  [\@whichfoils,
+						   'submissiongrading']);
+    }
     if ($target ne 'tex') {$result.="<br />";} else {$result.=' \vskip 0 mm ';}
     return $result;
 }
Index: loncom/homework/response.pm
diff -u loncom/homework/response.pm:1.161 loncom/homework/response.pm:1.162
--- loncom/homework/response.pm:1.161	Fri Apr  6 20:42:29 2007
+++ loncom/homework/response.pm	Tue Apr 17 19:25:09 2007
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # various response type definitons response definition
 #
-# $Id: response.pm,v 1.161 2007/04/07 00:42:29 albertel Exp $
+# $Id: response.pm,v 1.162 2007/04/17 23:25:09 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1095,6 +1095,33 @@
     return 2;
 }
 
+sub setup_prior_tries_hash {
+    my ($func,$data) = @_;
+    my $part = $Apache::inputtags::part;
+    my $id   = $Apache::inputtags::response[-1];	
+    foreach my $i (1..$Apache::lonhomework::history{'version'}) {
+	my $sub_key   = "$i:resource.$part.$id.submission";
+	next if (!exists($Apache::lonhomework::history{$sub_key}));
+	my @other_data;
+	foreach my $datum (@{ $data }) {
+	    if (ref($datum)) {
+		push(@other_data,$datum);
+	    } else {
+		my $info_key = "$i:resource.$part.$id.$datum";
+		push(@other_data,$Apache::lonhomework::history{$info_key});
+	    }
+	}
+
+	my $output =
+	    &$func('grade',
+		   $Apache::lonhomework::history{$sub_key},
+		   \@other_data);
+	if (defined($output)) {
+	    $Apache::inputtags::submission_display{$sub_key} = $output;
+	}
+    }
+}
+
 1;
 __END__
  
Index: loncom/homework/caparesponse/caparesponse.pm
diff -u loncom/homework/caparesponse/caparesponse.pm:1.211 loncom/homework/caparesponse/caparesponse.pm:1.212
--- loncom/homework/caparesponse/caparesponse.pm:1.211	Mon Apr 16 19:25:12 2007
+++ loncom/homework/caparesponse/caparesponse.pm	Tue Apr 17 19:25:24 2007
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # caparesponse definition
 #
-# $Id: caparesponse.pm,v 1.211 2007/04/16 23:25:12 albertel Exp $
+# $Id: caparesponse.pm,v 1.212 2007/04/17 23:25:24 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -601,7 +601,7 @@
 		}
 	    }
 	}
-	&setup_prior_tries_hash();
+	&Apache::response::setup_prior_tries_hash(\&format_prior_response_numerical);
     } elsif ($target eq 'edit') {
 	$result.='</td></tr>'.&Apache::edit::end_table;
     } elsif ($target eq 'answer' || $target eq 'analyze') {
@@ -792,18 +792,12 @@
     return $result;
 }
 
-sub setup_prior_tries_hash {
-    #FIXME support multi answer numericals/formula
-    my $part=$Apache::inputtags::part;
-    my $id=$Apache::inputtags::response[-1];	
-    foreach my $i (1..$Apache::lonhomework::history{'version'}) {
-	my $key = "$i:resource.$part.$id.submission";
-	next if (!exists($Apache::lonhomework::history{"$key"}));
-	$Apache::inputtags::submission_display{$key} =
-	    '<span class="LC_prior_numerical">'.
-	    &HTML::Entities::encode($Apache::lonhomework::history{$key},
-				    '"<>&').'</span>';
-    }
+sub format_prior_response_numerical {
+    my ($mode,$answer) = @_;
+    #FIXME needs to support multianswer modes
+    return '<span class="LC_prior_numerical">'.
+	    &HTML::Entities::encode($answer,'"<>&').'</span>';
+
 }
 
 sub check_for_answer_errors {
@@ -1025,17 +1019,10 @@
     return ($sig_ubound,$sig_lbound);
 }
 
-sub setup_prior_tries_hash_string {
-    my $part=$Apache::inputtags::part;
-    my $id=$Apache::inputtags::response[-1];	
-    foreach my $i (1..$Apache::lonhomework::history{'version'}) {
-	my $key = "$i:resource.$part.$id.submission";
-	next if (!exists($Apache::lonhomework::history{"$key"}));
-	$Apache::inputtags::submission_display{$key} =
-	    '<span class="LC_prior_string">'.
-	    &HTML::Entities::encode($Apache::lonhomework::history{$key},
-				    '"<>&').'</span>';
-    }
+sub format_prior_response_string {
+    my ($mode,$answer) =@_;
+    return '<span class="LC_prior_string">'.
+	    &HTML::Entities::encode($answer,'"<>&').'</span>';
 }
 
 sub start_stringresponse {
@@ -1216,7 +1203,7 @@
     } elsif ($target eq 'edit') {
 	$result.='</td></tr>'.&Apache::edit::end_table;
     } elsif ($target eq 'web' || $target eq 'tex') {
-	&setup_prior_tries_hash_string();
+	&Apache::response::setup_prior_tries_hash(\&format_prior_response_string);
     }
     if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' || 
 	$target eq 'tex' || $target eq 'analyze') {
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.527 loncom/interface/loncommon.pm:1.528
--- loncom/interface/loncommon.pm:1.527	Tue Apr 17 14:28:44 2007
+++ loncom/interface/loncommon.pm	Tue Apr 17 19:25:41 2007
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common routines
 #
-# $Id: loncommon.pm,v 1.527 2007/04/17 18:28:44 www Exp $
+# $Id: loncommon.pm,v 1.528 2007/04/17 23:25:41 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -4375,7 +4375,12 @@
   width: 100%;
   border-collapse: collapse;
 }
-table.LC_prior_option tr td {
+table.LC_prior_rank, table.LC_prior_match {
+  border-collapse: collapse;
+}
+table.LC_prior_option tr td,
+table.LC_prior_rank tr td,
+table.LC_prior_match tr td {
   border: 1px solid #000000;
 }
 

--albertel1176852342--