--- loncom/homework/bridgetask.pm 2005/09/09 18:20:16 1.45
+++ loncom/homework/bridgetask.pm 2005/10/04 19:32:08 1.66
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# definition of tags that give a structure to a document
#
-# $Id: bridgetask.pm,v 1.45 2005/09/09 18:20:16 albertel Exp $
+# $Id: bridgetask.pm,v 1.66 2005/10/04 19:32:08 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -144,11 +144,28 @@ sub add_previous_version_button {
}
sub add_grading_button {
+ my (undef,$cid)=&Apache::lonxml::whichuser();
+ my $cnum=$env{'course.'.$cid.'.num'};
+ my $cdom=$env{'course.'.$cid.'.domain'};
+ my %sections;
+ my $numsections=&Apache::loncommon::get_sections($cdom,$cnum,\%sections);
+ my $size=5;
+ if (scalar(keys(%sections)) < 3) {
+ $size=scalar(keys(%sections))+2;
+ }
+ my $sec_select = '\n";
+
my $result=' ';
$result.='';
if (&Apache::lonnet::allowed('mgq',$env{'request.course.id'})) {
my ($entries,$ready,$locks)=&get_queue_counts('gradingqueue');
+ $result.='
Specify a section: '.$sec_select.'
';
$result.='
'.&mt("Grading Queue has [_1] entries. [_2] of them are ready to be graded and [_3] of them are currently being graded",$entries,$ready,$locks);
$result.='
'."\n";
+ $result.=' '."\n";
}
return $result;
}
@@ -202,6 +221,120 @@ sub preserve_grade_info {
return $result;
}
+sub style {
+ return (<
+STYLE
+
+}
+
+sub show_task {
+ my ($status,$previous)=@_;
+ if (!$previous && (
+ ( $status eq 'CLOSED' ) ||
+ ( $status eq 'BANNED') ||
+ ( $status eq 'UNAVAILABLE') ||
+ ( $status eq 'NOT_IN_A_SLOT') ||
+ ( $status eq 'NEEDS_CHECKIN') ||
+ ( $status eq 'WAITING_FOR_GRADE') ||
+ ( $status eq 'INVALID_ACCESS') )) {
+ return 0;
+ }
+ if ($env{'form.donescreen'}) { return 0; }
+ return 1;
+}
+
+sub internal_location {
+ my ($id)=@_;
+ return '';
+}
+
+sub submission_time_stamp {
+ my ($symb,$courseid,$udom,$uname)=&Apache::lonxml::whichuser();
+ my $submissiontime;
+ my $version=$Apache::lonhomework::history{'resource.version'};
+ for (my $v=$Apache::lonhomework::history{'version'};$v>0;$v--) {
+ if (defined($Apache::lonhomework::history{$v.':resource.'.$version.'.0.bridgetask.portfiles'})) {
+ $submissiontime=$Apache::lonhomework::history{$v.':timestamp'};
+ }
+ }
+ my $result;
+ if ($submissiontime) {
+ my $slot_name=$Apache::lonhomework::history{'resource.'.$version.'.checkedin.slot'};
+ my %slot=&Apache::lonnet::get_slot($slot_name);
+ my $diff = $slot{'endtime'} - $submissiontime;
+ my ($color,$when)=('red','after');
+ if ($diff > 0) { ($color,$when)=('green','before'); }
+ my $info;
+ if ($diff%60) { $info=($diff%60).' seconds'; }
+ $diff=int($diff/60);
+ if ($diff%60) { $info=($diff%60).' minutes '.$info; }
+ $diff=int($diff/60);
+ if ($diff) { $info=$diff.' hours '.$info; }
+ $result='
'.
+ &mt('Student submitted [_1] [_2] the deadline.
+ (Submission was at [_3], end of period was [_4].)',
+ $info,$when,scalar(localtime($submissiontime)),
+ scalar(localtime($slot{'endtime'}))).
+ '
'.&mt('Indicate the files from your portfolio to be evaluated in grading this task.').'
').
"
";
$result.=&Apache::inputtags::gradestatus('0');
+ $result.='';
+ $result.=<
+
+
+
+DONEBUTTON
+ }
+ if (&show_task($status,$previous) &&
+ $Apache::lonhomework::history{"resource.$version.status"} =~ /^(pass|fail)$/) {
+ my $bt_status=$Apache::lonhomework::history{"resource.$version.status"};
+ my $title=&Apache::lonnet::gettitle();
+ my %slot=&Apache::lonnet::get_slot($Apache::inputtags::slot_name);
+ my $start_time=
+ &Apache::lonlocal::locallocaltime($slot{'starttime'});
+
+ my $status;
+ $status.="\n
\n";
+
+ if ($bt_status eq 'pass') {
+ $status.='
You passed the '.$title.' given on '.
+ $start_time.'.
';
+ }
+ if ($bt_status eq 'fail') {
+ $status.='
You did not pass the '.$title.' given on '.
+ $start_time.'.
';
+ if (!$previous) {
+ $status.=&add_request_another_attempt_button();
+ }
+ }
+ my $man_count=0;
+ my $opt_count=0;
+ my $opt_passed=0;
+ foreach my $dim_id (@Apache::bridgetask::dimensionlist) {
+ if ($Apache::bridgetask::dimensionmandatory{$dim_id}
+ eq 'N') {
+ $opt_count++;
+ if ($Apache::lonhomework::history{"resource.$version.$dim_id.status"} eq 'pass') {
+ $opt_passed++;
+ }
+ } else {
+ $man_count++;
+ }
+ }
+ my $opt_req=&Apache::lonxml::get_param('OptionalRequired',
+ $parstack,$safeeval);
+ if ($opt_req !~ /\S/) { $opt_req='0'; }
+ $status.="\n
".&mt('You needed to pass all of the [_1] mandatory components and [_2] of the [_3] optional components on the bridge task.',$man_count,$opt_req,$opt_count)."
\n";
+
+ my $internal_location=&internal_location();
+ $result=~s/\Q$internal_location\E/$status/;
}
}
if ($target eq 'web' || $target eq 'webgrade') {
@@ -484,6 +707,10 @@ sub end_Task {
$Apache::lonhomework::results{"resource.0.award"}=
$Apache::lonhomework::results{"resource.$version.0.award"}=
$award;
+ $Apache::lonhomework::results{"resource.0.submission"}=
+ $Apache::lonhomework::results{"resource.$version.0.submission"}='';
+ } else {
+ delete($Apache::lonhomework::results{"resource.$version.0.bridgetask.portfiles"});
}
&Apache::lonhomework::showhash(%Apache::lonhomework::results);
&Apache::structuretags::finalize_storage();
@@ -513,7 +740,9 @@ sub end_Task {
$ungraded++;
} elsif ($status eq 'review') {
$review++;
- }
+ } else {
+ $ungraded++;
+ }
}
if ($optional_passed < $optional_required) {
$mandatory_failed++;
@@ -527,13 +756,14 @@ sub end_Task {
&check_queue_unlock($env{'form.queue'});
&Apache::lonxml::debug(" still needs review not changing status.");
} else {
- &move_between_queues('gradingqueue','reviewqueue');
+ &move_between_queues($env{'form.queue'},'reviewqueue');
}
} elsif ($ungraded) {
$Apache::lonhomework::results{"resource.$version.status"}='ungraded';
- if ($env{'form.queue'} eq 'reviewqueue') {
+ if ($env{'form.queue'} eq 'reviewqueue' ||
+ $env{'form.queue'} eq 'none' ) {
&Apache::lonxml::debug("moving back.");
- &move_between_queues('reviewqueue','gradingqueue');
+ &move_between_queues($env{'form.queue'},'gradingqueue');
} else {
&check_queue_unlock($env{'form.queue'});
}
@@ -545,13 +775,16 @@ sub end_Task {
&remove_from_queue($env{'form.queue'});
my ($symb,$courseid,$udom,$uname)=&Apache::lonxml::whichuser();
- $Apache::lonhomework::results{"resource.$version.0.bridgetask.portfiles"}=
- $Apache::lonhomework::history{"resource.$version.0.bridgetask.portfiles"};
- &Apache::grades::version_portfiles(
- \%Apache::lonhomework::results,
- ["$version.0.bridgetask"],$courseid,
- $symb,$udom,$uname,
- ["$version.0.bridgetask"]);
+
+ if ($env{'form.regrade'} ne 'yes') {
+ $Apache::lonhomework::results{"resource.$version.0.bridgetask.portfiles"}=
+ $Apache::lonhomework::history{"resource.$version.0.bridgetask.portfiles"};
+ &Apache::grades::version_portfiles(
+ \%Apache::lonhomework::results,
+ ["$version.0.bridgetask"],$courseid,
+ $symb,$udom,$uname,
+ ["$version.0.bridgetask"]);
+ }
} else {
$Apache::lonhomework::results{"resource.$version.status"}='pass';
$Apache::lonhomework::results{"resource.$version.0.solved"}='correct_by_override';
@@ -560,23 +793,25 @@ sub end_Task {
&remove_from_queue($env{'form.queue'});
my ($symb,$courseid,$udom,$uname)=&Apache::lonxml::whichuser();
- $Apache::lonhomework::results{"resource.$version.0.bridgetask.portfiles"}=
- $Apache::lonhomework::history{"resource.$version.0.bridgetask.portfiles"};
- &Apache::grades::version_portfiles(
- \%Apache::lonhomework::results,
- ["$version.0.bridgetask"],$courseid,
- $symb,$udom,$uname,
- ["$version.0.bridgetask"]);
+ if ($env{'form.regrade'} ne 'yes') {
+ $Apache::lonhomework::results{"resource.$version.0.bridgetask.portfiles"}=
+ $Apache::lonhomework::history{"resource.$version.0.bridgetask.portfiles"};
+ &Apache::grades::version_portfiles(
+ \%Apache::lonhomework::results,
+ ["$version.0.bridgetask"],$courseid,
+ $symb,$udom,$uname,
+ ["$version.0.bridgetask"]);
+ }
}
$Apache::lonhomework::results{"resource.status"}=
$Apache::lonhomework::results{"resource.$version.status"};
if (defined($Apache::lonhomework::results{"resource.$version.0.awarded"})) {
$Apache::lonhomework::results{"resource.0.award"}=
- $Apache::lonhomework::results{"resource.$version.award"};
+ $Apache::lonhomework::results{"resource.$version.0.award"};
$Apache::lonhomework::results{"resource.0.awarded"}=
- $Apache::lonhomework::results{"resource.$version.awarded"};
+ $Apache::lonhomework::results{"resource.$version.0.awarded"};
$Apache::lonhomework::results{"resource.0.solved"}=
- $Apache::lonhomework::results{"resource.$version.solved"};
+ $Apache::lonhomework::results{"resource.$version.0.solved"};
}
&Apache::structuretags::finalize_storage();
}
@@ -602,8 +837,13 @@ sub end_Task {
sub move_between_queues {
my ($src_queue,$dest_queue)=@_;
- my $cur_data=&get_queue_data($src_queue);
- if (!$cur_data) { return 'not_exist'; }
+ my $cur_data;
+ if ($src_queue ne 'none') {
+ $cur_data=&get_queue_data($src_queue);
+ if (!$cur_data) { return 'not_exist'; }
+ } else {
+ $cur_data = ['none'];
+ }
my $result=&add_to_queue($dest_queue,$cur_data->[0]);
if ($result ne 'ok') {
return $result;
@@ -614,6 +854,7 @@ sub move_between_queues {
sub check_queue_unlock {
my ($queue,$key,$allow_not_me)=@_;
+ if ($queue eq 'none') { return 'ok'; }
my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
if (!defined($key)) {
$key="$symb\0queue\0$uname\@$udom";
@@ -633,6 +874,7 @@ sub check_queue_unlock {
sub remove_from_queue {
my ($queue)=@_;
+ if ($queue eq 'none') { return 'ok'; }
my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
my $cnum=$env{'course.'.$cid.'.num'};
my $cdom=$env{'course.'.$cid.'.domain'};
@@ -665,8 +907,30 @@ sub get_queue_data {
return undef;
}
+sub check_queue_for_key {
+ my ($cid,$queue,$todo)=@_;
+ my $cnum=$env{'course.'.$cid.'.num'};
+ my $cdom=$env{'course.'.$cid.'.domain'};
+ my %results=
+ &Apache::lonnet::get($queue,[$todo,"$todo\0locked"],$cdom,$cnum);
+
+ if (exists($results{$todo}) && ref($results{$todo})) {
+ if (defined($results{"$todo\0locked"})) {
+ return 'locked';
+ }
+ my $slot=$results{$todo}->[0];
+ my %slot_data=&Apache::lonnet::get_slot($slot);
+ if ($slot_data{'endtime'} > time) {
+ return 'in_progress';
+ }
+ return 'enqueued';
+ }
+ return undef;
+}
+
sub add_to_queue {
my ($queue,$slot_name)=@_;
+ if ($queue eq 'none') { return 'ok'; }
my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
my $cnum=$env{'course.'.$cid.'.num'};
my $cdom=$env{'course.'.$cid.'.domain'};
@@ -681,6 +945,17 @@ sub show_queue {
my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
my $cnum=$env{'course.'.$cid.'.num'};
my $cdom=$env{'course.'.$cid.'.domain'};
+
+ my @chosen_sections=
+ &Apache::loncommon::get_env_multiple('form.chosensections');
+ &Apache::grades::init_perm();
+ my ($classlist,$section,$fullname)=&Apache::grades::getclasslist(\@chosen_sections,);
+ &Apache::grades::reset_perm();
+ if (!(grep(/^all$/,@chosen_sections))) {
+ $result.='
Showing only sections '.join(', ',@chosen_sections).
+ '.
'."\n";
+ }
+
my $regexp="^$symb\0";
my %queue=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
my ($tmp)=%queue;
@@ -691,8 +966,9 @@ sub show_queue {
if ($with_selects) { $result.="
"; }
$result.="
resource
user
type
data
";
foreach my $key (sort(keys(%queue))) {
+ my ($symb,$uname,$udom) = &decode_queue_key($key);
+ if (!defined($classlist->{$uname.':'.$udom})) { next; }
if ($key=~/locked$/ && !$with_selects) {
- my ($symb,$uname,$udom) = &decode_queue_key($key);
my $title=&Apache::lonnet::gettitle($symb);
$result.="
$title
$uname
";
$result.='
lock
'.$queue{$key}.'
';
@@ -703,7 +979,6 @@ sub show_queue {
$result.='
Question : you did not pass this '.$mandatory.' question
';
+ }
+ my $man_count=0;
+ my $man_passed=0;
+ my $opt_count=0;
+ my $opt_passed=0;
+ foreach my $id (@{$dimension{$instance.'.criterias'}}) {
+ if ($dimension{$instance.'.criteria.'.$id.'.mandatory'}
+ eq 'N') {
+ $opt_count++;
+ if ($Apache::lonhomework::history{"resource.$version.$dim.$instance.$id.status"} eq 'pass') {
+ $opt_passed++;
+ }
+ } else {
+ $man_count++;
+ if ($Apache::lonhomework::history{"resource.$version.$dim.$instance.$id.status"} eq 'pass') {
+ $man_passed++;
+ }
+ }
+ }
+ if ($man_passed eq $man_count) { $man_passed='all'; }
+ my $opt_req=$dimension{$instance.'.optionalrequired'};
+ if ($opt_req !~ /\S/) { $opt_req='0'; }
+ $dim_info.="\n
".&mt('You passed [_1] of the [_2] mandatory components and [_3] of the [_4] optional components, of which you were required to pass [_5].',$man_passed,$man_count,$opt_passed,$opt_count,$opt_req)."
\n
";
+
+ my $internal_location=&internal_location($dim);
+ $result=~s/\Q$internal_location\E/$dim_info/;
+
foreach my $id (@{$dimension{$instance.'.criterias'}}) {
my $status=$Apache::lonhomework::history{"resource.$version.$dim.$instance.$id.status"};
my $comment=$Apache::lonhomework::history{"resource.$version.$dim.$instance.$id.comment"};
- $result.='
';
+ my $mandatory=($dimension{$instance.'.criteria.'.$id.'.mandatory'} ne 'N');
+ if ($mandatory) {
+ $mandatory='Mandatory';
+ } else {
+ $mandatory='Optional';
+ }
if ($status eq 'fail') {
- $result.=''.&mt('Did not pass').'';
} elsif ($status eq 'pass') {
- $result.=''.&mt('Passed').'';
} else {
- &Apache::lonxml::error("Student viewing a graded bridgetask was show a status of $status");
+ &Apache::lonxml::error("Student viewing a graded bridgetask was shown a status of $status");
}
- $result.='
';
if ($Apache::lonhomework::history{"resource.$version.$dim.$instance.$id.comment"}) {
- $result.=&mt('Comment from grader: ').$Apache::lonhomework::history{"resource.$version.$dim.$instance.$id.comment"}.'
';
+ $result.='';
}
}
} elsif ($target eq 'webgrade') {
+ # in case of any side effects that we need
+ @Apache::scripttag::parser_env = @_;
+ &Apache::scripttag::xmlparse($dimension{'intro'});
+ @Apache::scripttag::parser_env = @_;
+ &Apache::scripttag::xmlparse($dimension{$instance.'.text'});
foreach my $id (@{$dimension{$instance.'.criterias'}}) {
my $link='criteria_'.$instance.'_'.$id;
my $status=$Apache::lonhomework::history{"resource.$version.$dim.$instance.$id.status"};
$result.='