[LON-CAPA-cvs] cvs: loncom /homework grades.pm
albertel
lon-capa-cvs-allow@mail.lon-capa.org
Thu, 25 Oct 2007 20:05:53 -0000
albertel Thu Oct 25 16:05:53 2007 EDT
Modified files:
/loncom/homework grades.pm
Log:
- refactor out collaborator checking, and eliminate use of $_
- &mt() colla errors
- css the error messages
- correct coloring of perstudent backgrounds
Index: loncom/homework/grades.pm
diff -u loncom/homework/grades.pm:1.463 loncom/homework/grades.pm:1.464
--- loncom/homework/grades.pm:1.463 Wed Oct 24 20:47:24 2007
+++ loncom/homework/grades.pm Thu Oct 25 16:05:52 2007
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# The LON-CAPA Grading handler
#
-# $Id: grades.pm,v 1.463 2007/10/25 00:47:24 albertel Exp $
+# $Id: grades.pm,v 1.464 2007/10/25 20:05:52 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -1960,7 +1960,7 @@
# This is where output for one specific student would start
my $bgcolor='#DDEEDD';
- if (int($counter/2) eq $counter) { $bgcolor='#DDDDEE'; }
+ if ($counter%2) { $bgcolor='#DDDDEE'; }
$request->print("\n\n".
'<p><table border="2"><tr><th bgcolor="'.$bgcolor.'">'.$env{'form.fullname'}.'</th></tr><tr><td bgcolor="'.$bgcolor.'">');
@@ -1990,60 +1990,13 @@
'" value="'.$env{'form.fullname'}.'" />'."\n";
# If any part of the problem is an essay-response (handgraded), then check for collaborators
- my @col_fullnames;
- my ($classlist,$fullname);
+ my $fullname;
+ my $col_fullnames = [];
if ($env{'form.handgrade'} eq 'yes') {
- ($classlist,undef,$fullname) = &getclasslist('all','0');
- for (keys (%$handgrade)) {
- my $ncol = &Apache::lonnet::EXT('resource.'.$_.
- '.maxcollaborators',
- $symb,$udom,$uname);
- next if ($ncol <= 0);
- s/\_/\./g;
- next if ($record{'resource.'.$_.'.collaborators'} eq '');
- my @goodcollaborators = ();
- my @badcollaborators = ();
- foreach (split(/,?\s+/,$record{'resource.'.$_.'.collaborators'})) {
- $_ =~ s/[\$\^\(\)]//g;
- next if ($_ eq '');
- my ($co_name,$co_dom) = split /\@|:/,$_;
- $co_dom = $udom if (! defined($co_dom) || $co_dom =~ /^domain$/i);
- next if ($co_name eq $uname && $co_dom eq $udom);
- # Doing this grep allows 'fuzzy' specification
- my @Matches = grep /^$co_name:$co_dom$/i,keys %$classlist;
- if (! scalar(@Matches)) {
- push @badcollaborators,$_;
- } else {
- push @goodcollaborators, @Matches;
- }
- }
- if (scalar(@goodcollaborators) != 0) {
- $result.='<b>Collaborators: </b>';
- foreach (@goodcollaborators) {
- my ($lastname,$givenn) = split(/,/,$$fullname{$_});
- push @col_fullnames, $givenn.' '.$lastname;
- $result.=$$fullname{$_}.' ';
- }
- $result.='<br />'."\n";
- my ($part)=split(/\./,$_);
- $result.='<input type="hidden" name="collaborator'.$counter.
- '" value="'.$part.':'.(join ':',@goodcollaborators).'" />'.
- "\n";
- }
- if (scalar(@badcollaborators) > 0) {
- $result.='<table border="0"><tr bgcolor="#ffbbbb"><td>';
- $result.='This student has submitted ';
- $result.=(scalar(@badcollaborators) == 1) ? 'an invalid collaborator' : 'invalid collaborators';
- $result .= ': '.join(', ',@badcollaborators);
- $result .= '</td></tr></table>';
- }
- if (scalar(@badcollaborators > $ncol)) {
- $result .= '<table border="0"><tr bgcolor="#ffbbbb"><td>';
- $result .= 'This student has submitted too many '.
- 'collaborators. Maximum is '.$ncol.'.';
- $result .= '</td></tr></table>';
- }
- }
+ (my $sub_result,$fullname,$col_fullnames)=
+ &check_collaborators($symb,$uname,$udom,\%record,$handgrade,
+ $counter);
+ $result.=$sub_result;
}
$request->print($result."\n");
@@ -2179,16 +2132,16 @@
if ($env{'form.handgrade'} eq 'yes') {
my ($lastname,$givenn) = split(/,/,$env{'form.fullname'});
my $msgfor = $givenn.' '.$lastname;
- if (scalar(@col_fullnames) > 0) {
- my $lastone = pop @col_fullnames;
- $msgfor .= ', '.(join ', ',@col_fullnames).' and '.$lastone.'.';
+ if (scalar(@$col_fullnames) > 0) {
+ my $lastone = pop(@$col_fullnames);
+ $msgfor .= ', '.(join ', ',@$col_fullnames).' and '.$lastone.'.';
}
$msgfor =~ s/\'/\\'/g; #' stupid emacs - no! javascript
$result='<input type="hidden" name="includemsg'.$counter.'" value="" />'."\n".
'<input type="hidden" name="newmsg'.$counter.'" value="" />'."\n";
$result.=' <a href="javascript:msgCenter(document.SCORE,'.$counter.
',\''.$msgfor.'\');" target="_self">'.
- &mt('Compose message to student').(scalar(@col_fullnames) >= 1 ? 's' : '').'</a><label> ('.
+ &mt('Compose message to student').(scalar(@$col_fullnames) >= 1 ? 's' : '').'</a><label> ('.
&mt('incl. grades').' <input type="checkbox" name="withgrades'.$counter.'" /></label>)'.
'<img src="'.$request->dir_config('lonIconsURL').
'/mailbkgrd.gif" width="14" height="10" name="mailicon'.$counter.'" />'."\n".
@@ -2266,6 +2219,62 @@
return '';
}
+sub check_collaborators {
+ my ($symb,$uname,$udom,$record,$handgrade,$counter) = @_;
+ my ($result,@col_fullnames);
+ my ($classlist,undef,$fullname) = &getclasslist('all','0');
+ foreach my $part (keys(%$handgrade)) {
+ my $ncol = &Apache::lonnet::EXT('resource.'.$part.
+ '.maxcollaborators',
+ $symb,$udom,$uname);
+ next if ($ncol <= 0);
+ $part =~ s/\_/\./g;
+ next if ($record->{'resource.'.$part.'.collaborators'} eq '');
+ my (@good_collaborators, @bad_collaborators);
+ foreach my $possible_collaborator
+ (split(/,?\s+/,$record->{'resource.'.$part.'.collaborators'})) {
+ $possible_collaborator =~ s/[\$\^\(\)]//g;
+ next if ($possible_collaborator eq '');
+ my ($co_name,$co_dom) = split(/\@|:/,$possible_collaborator);
+ $co_dom = $udom if (! defined($co_dom) || $co_dom =~ /^domain$/i);
+ next if ($co_name eq $uname && $co_dom eq $udom);
+ # Doing this grep allows 'fuzzy' specification
+ my @matches = grep(/^\Q$co_name\E:\Q$co_dom\E$/i,
+ keys(%$classlist));
+ if (! scalar(@matches)) {
+ push(@bad_collaborators, $possible_collaborator);
+ } else {
+ push(@good_collaborators, @matches);
+ }
+ }
+ if (scalar(@good_collaborators) != 0) {
+ $result.='<b>Collaborators: </b>';
+ foreach my $name (@good_collaborators) {
+ my ($lastname,$givenn) = split(/,/,$$fullname{$name});
+ push(@col_fullnames, $givenn.' '.$lastname);
+ $result.=$fullname->{$name}.' ';
+ }
+ $result.='<br />'."\n";
+ my ($part)=split(/\./,$_);
+ $result.='<input type="hidden" name="collaborator'.$counter.
+ '" value="'.$part.':'.(join ':',@good_collaborators).'" />'.
+ "\n";
+ }
+ if (scalar(@bad_collaborators) > 0) {
+ $result.='<div class="LC_error">';
+ $result.=&mt('This student has submitted [quant,_1,invalid collaborator]: [_2]',scalar(@bad_collaborators),join(', ',@bad_collaborators));
+ $result .= '</div>';
+ }
+ if (scalar(@bad_collaborators > $ncol)) {
+ $result .= '<div class="LC_error">';
+ $result .= &mt('This student has submitted too many '.
+ 'collaborators. Maximum is [_1].',$ncol);
+ $result .= '</div>';
+ }
+ }
+ return ($result,$fullname,\@col_fullnames);
+}
+
#--- Retrieve the last submission for all the parts
sub get_last_submission {
my ($returnhash)=@_;