--- loncom/homework/bridgetask.pm 2006/06/13 21:34:28 1.171 +++ loncom/homework/bridgetask.pm 2006/07/17 20:35:11 1.181 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # definition of tags that give a structure to a document # -# $Id: bridgetask.pm,v 1.171 2006/06/13 21:34:28 albertel Exp $ +# $Id: bridgetask.pm,v 1.181 2006/07/17 20:35:11 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -50,7 +50,7 @@ my %dimension; sub initialize_bridgetask { # id of current Dimension, 0 means that no dimension is current # (inside only) - %Apache::bridgetask::dimension=(); + @Apache::bridgetask::dimension=(); # list of all Dimension ids seen %Apache::bridgetask::top_dimensionlist=(); # list of all current Instance ids @@ -83,7 +83,7 @@ sub proctor_check_auth { } } if ($authenticated) { - &create_new_version($type,$user,$domain,$slot_name); + &check_in($type,$user,$domain,$slot_name); return 1; } } @@ -91,8 +91,43 @@ sub proctor_check_auth { return 0; } +sub check_in { + my ($type,$user,$domain,$slot_name) = @_; + my $useslots = &Apache::lonnet::EXT("resource.0.useslots"); + if ( $useslots eq 'map_map') { + &check_in_sequence($user,$domain,$slot_name); + } else { + &create_new_version($type,$user,$domain,$slot_name); + } + return 1; +} + +sub check_in_sequence { + my ($user,$domain,$slot_name) = @_; + my $navmap = Apache::lonnavmaps::navmap->new(); + my ($symb) = &Apache::lonxml::whichuser(); + my ($map) = &Apache::lonnet::decode_symb($symb); + my @resources = + $navmap->retrieveResources($map, sub { $_[0]->is_problem() },0,0); + my %old_history = %Apache::lonhomework::history; + my %old_results = %Apache::lonhomework::results; + + foreach my $res (@resources) { + &Apache::lonxml::debug("doing ".$res->src); + &Apache::structuretags::initialize_storage($res->symb); + my $type = ($res->is_task()) ? 'Task' : 'problem'; + &create_new_version($type,$user,$domain,$slot_name); + &Apache::structuretags::finalize_storage($res->symb); + } + + %Apache::lonhomework::history = %old_history; + %Apache::lonhomework::results = %old_results; +} + sub create_new_version { my ($type,$user,$domain,$slot_name) = @_; + + my $id = '0'; if ($type eq 'Task') { # increment version my $version= @@ -107,28 +142,27 @@ sub create_new_version { } #setup new version and who did it - $Apache::lonhomework::results{'resource.0.version'}=$version; - if (defined($user) && defined($domain)) { - $Apache::lonhomework::results{"resource.$version.0.checkedin"}= - $user.':'.$domain; - } else { - $Apache::lonhomework::results{"resource.$version.0.checkedin"}= - $env{'user.name'}.':'.$env{'user.domain'}; - } - if (defined($slot_name)) { - $Apache::lonhomework::results{"resource.$version.0.checkedin.slot"}= - $slot_name; + $Apache::lonhomework::results{'resource.0.version'}=$version; + $id = "$version.0"; + if (!defined($user) || !defined($domain)) { + $user = $env{'user.name'}; + $domain = $env{'user.domain'}; } + } elsif ($type eq 'problem') { &Apache::lonxml::debug("authed $slot_name"); - if (defined($user) && defined($domain)) { - $Apache::lonhomework::results{"resource.0.checkedin"}= - $user.':'.$domain; - } - if (defined($slot_name)) { - $Apache::lonhomework::results{"resource.0.checkedin.slot"}= - $slot_name; - } + } + if (!defined($user) || !defined($domain)) { + $user = $env{'user.name'}; + $domain = $env{'user.domain'}; + } + + $Apache::lonhomework::results{"resource.$id.checkedin"}= + $user.':'.$domain; + + if (defined($slot_name)) { + $Apache::lonhomework::results{"resource.$id.checkedin.slot"}= + $slot_name; } } @@ -316,6 +350,38 @@ sub show_task { return 1; } +my @delay; +sub nest { + if (@delay) { + return $delay[-1]; + } else { + return; + } +} + +sub nested_parse { + my ($str,$env,$args) = @_; + my @old_env = @Apache::scripttag::parser_env; + @Apache::scripttag::parser_env = @$env; + if (exists($args->{'set_dim_id'})) { + &enable_dimension_parsing($args->{'set_dim_id'}); + } + push(@delay,(($args->{'delayed_dim_results'})? 1 : 0)); + my $result = &Apache::scripttag::xmlparse($$str); + pop(@delay); + if (exists($args->{'set_dim_id'})) { + &disable_dimension_parsing(); + } + @Apache::scripttag::parser_env = @old_env; + if ($args->{'delayed_dim_results'}) { + my $dim = &get_dim_id(); + &Apache::lonxml::debug(" tossing out $result "); + &Apache::lonxml::debug(" usining out $dim 's ". $dimension{$dim}{'result'}); + return $dimension{$dim}{'result'}; + } + return $result; +} + sub internal_location { my ($id)=@_; return ''; @@ -469,8 +535,8 @@ sub start_Task { my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; my ($status,$accessmsg,$slot); + &Apache::structuretags::init_problem_globals('Task'); if ($target ne 'webgrade') { - &Apache::structuretags::init_problem_globals('Task'); &Apache::structuretags::initialize_storage(); &Apache::lonhomework::showhash(%Apache::lonhomework::history); if ($env{'request.state'} eq 'construct') { @@ -533,7 +599,9 @@ sub start_Task { ($status,$accessmsg,my $slot_name,$slot) = &Apache::lonhomework::check_slot_access('0','Task'); if ($status eq 'CAN_ANSWER' && $version eq '') { - &create_new_version('Task',undef,undef,$slot_name); + # CAN_ANSWER mode, and no current version, unproctored access + # thus self-checkedin + &check_in('Task',undef,undef,$slot_name); &add_to_queue('gradingqueue',{'type' => 'Task', 'time' => time, 'slot' => $slot_name}); @@ -995,6 +1063,17 @@ DONEBUTTON &Apache::loncommon::end_page({'discussion' => 1}); } } + + my $useslots = &Apache::lonnet::EXT("resource.0.useslots"); + my %queue_data = ('type' => 'Task', + 'time' => time,); + if (defined($Apache::inputtags::slot_name)) { + $queue_data{'slot'} = $Apache::inputtags::slot_name; + } elsif (defined($Apache::lonhomework::history{"resource.$version.0.checkedin.slot"})) { + $queue_data{'slot'} = $Apache::lonhomework::history{"resource.$version.0.checkedin.slot"}; + } + + if ($target eq 'grade' && !$env{'form.webgrade'} && !$previous) { my $award='SUBMITTED'; &Apache::essayresponse::file_submission("$version.0",'bridgetask', @@ -1017,17 +1096,7 @@ DONEBUTTON &Apache::lonhomework::showhash(%Apache::lonhomework::results); &Apache::structuretags::finalize_storage(); if ($award eq 'SUBMITTED') { - my $useslots = &Apache::lonnet::EXT("resource.0.useslots"); - if ($useslots =~ /^\s*no\s*$/i) { - &add_to_queue('gradingqueue', - {'type' => 'Task', - 'time' => time}); - } elsif (defined($Apache::inputtags::slot_name)) { - &add_to_queue('gradingqueue', - {'type' => 'Task', - 'time' => time, - 'slot' => $Apache::inputtags::slot_name}); - } + &add_to_queue('gradingqueue',\%queue_data); } } elsif ($Apache::lonhomework::results{'INTERNAL_store'}) { &Apache::structuretags::finalize_storage(); @@ -1075,14 +1144,20 @@ DONEBUTTON &check_queue_unlock($env{'form.queue'}); &Apache::lonxml::debug(" still needs review not changing status."); } else { - &move_between_queues($env{'form.queue'},'reviewqueue'); + if ($env{'form.queue'} ne 'none') { + &move_between_queues($env{'form.queue'},'reviewqueue'); + } else { + &add_to_queue('reviewqueue',\%queue_data); + } } } elsif ($ungraded) { $Apache::lonhomework::results{"resource.$version.0.status"}='ungraded'; - if ($env{'form.queue'} eq 'reviewqueue' || - $env{'form.queue'} eq 'none' ) { + if ($env{'form.queue'} eq 'reviewqueue') { &Apache::lonxml::debug("moving back."); - &move_between_queues($env{'form.queue'},'gradingqueue'); + &move_between_queues($env{'form.queue'}, + 'gradingqueue'); + } elsif ($env{'form.queue'} eq 'none' ) { + &add_to_queue('gradingqueue',\%queue_data); } else { &check_queue_unlock($env{'form.queue'}); } @@ -1158,6 +1233,7 @@ DONEBUTTON $result.=&Apache::response::meta_stores_write('status','string', 'Bridge Task Status'); } + &Apache::structuretags::reset_problem_globals('Task'); undef($Apache::lonhomework::parsing_a_task); return $result; } @@ -1907,27 +1983,55 @@ sub start_Setup { &Apache::lonxml::startredirection(); return &internal_location($dim); } + +{ + my @allowed; + sub enable_dimension_parsing { + my ($id) = @_; + push(@allowed,$id); + } + sub disable_dimension_parsing { + pop(@allowed); + } + sub skip_dimension_parsing { + my ($check) = @_; + if (!@allowed) { return 0;} + # if unspecified allow any id + if ($allowed[-1] eq undef) { return 0;} + + return ($check ne $allowed[-1]); + } +} + sub start_Question { return &start_Dimension(@_); } sub start_Dimension { - my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; + my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; my $dim = &get_id($parstack,$safeeval); my $previous_dim; if (@Apache::bridgetask::dimension) { $previous_dim = $Apache::bridgetask::dimension[-1]; push(@{$Apache::bridgetask::dimension{$previous_dim}{'contains'}}, $dim); - $dimension{$previous_dim}{'criteria.'.$dim}=''; + if(&skip_dimension_parsing($dim)) { + $dimension{$previous_dim}{'criteria.'.$dim} = + $token->[4] + .&Apache::lonxml::get_all_text('/'.$tagstack->[-1],$parser, + $style) + .'[-1].'>'; + } $dimension{$previous_dim}{'criteria.'.$dim.'.type'}='dimension'; $dimension{$previous_dim}{'criteria.'.$dim.'.mandatory'}= &Apache::lonxml::get_param('Mandatory',$parstack,$safeeval); push(@{$dimension{$previous_dim}{'criterias'}},$dim); $dimension{$dim}{'nested'}=$previous_dim; + &Apache::lonxml::debug("adding $dim as criteria to $previous_dim"); } else { $Apache::bridgetask::top_dimensionlist{$dim}{'manadatory'}= &Apache::lonxml::get_param('Mandatory',$parstack,$safeeval); } push(@Apache::bridgetask::dimension,$dim); &Apache::lonxml::startredirection(); + &enable_dimension_parsing($dim); return &internal_location($dim); } @@ -1964,20 +2068,22 @@ sub get_instance { if (defined($instance)) { return $instance; } &Apache::response::pushrandomnumber(); - my @instances = @{$dimension{$dim}{'instances'}}; - # remove disabled instances - for (my $i=0; $i < $#instances; $i++) { - if ($dimension{$dim}{$instances[$i].'.disabled'}) { - splice(@instances,$i,1); - $i--; + if (ref($dimension{$dim}{'instances'}) eq 'ARRAY') { + my @instances = @{$dimension{$dim}{'instances'}}; + # remove disabled instances + for (my $i=0; $i < $#instances; $i++) { + if ($dimension{$dim}{$instances[$i].'.disabled'}) { + splice(@instances,$i,1); + $i--; + } + } + @instances = &Math::Random::random_permutation(@instances); + $instance = $instances[($version-1)%scalar(@instances)]; + if ($version =~ /^\d$/) { + $Apache::lonhomework::results{"resource.$version.0.$dim.instance"} = + $instance; + $Apache::lonhomework::results{'INTERNAL_store'} = 1; } - } - @instances = &Math::Random::random_permutation(@instances); - $instance = $instances[($version-1)%scalar(@instances)]; - if ($version =~ /^\d$/) { - $Apache::lonhomework::results{"resource.$version.0.$dim.instance"} = - $instance; - $Apache::lonhomework::results{'INTERNAL_store'} = 1; } &Apache::response::poprandomnumber(); return $instance; @@ -2008,26 +2114,40 @@ sub get_criteria { my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; my $result=&Apache::lonxml::endredirection(); my $dim=&get_id($parstack,$safeeval); + if (&skip_dimension_parsing($dim)) { + &disable_dimension_parsing($dim); + pop(@Apache::bridgetask::dimension); + return; + } my $instance=&get_instance($dim); my $version=&get_version(); if ($target eq 'web') { - @Apache::scripttag::parser_env = @_; - $result.=&Apache::scripttag::xmlparse($dimension{$dim}{'intro'}); + $result .= &nested_parse(\$dimension{$dim}{'intro'},[@_]); my @instances = $instance; if (&Apache::response::showallfoils()) { @instances = @{$dimension{$dim}{'instances'}}; } my $shown_question_text; foreach my $instance (@instances) { - @Apache::scripttag::parser_env = @_; - $result.=&Apache::scripttag::xmlparse($dimension{$dim}{$instance.'.text'}); - @Apache::scripttag::parser_env = @_; - $result.=&Apache::scripttag::xmlparse($dimension{$dim}{'questiontext'}); - + $result .= &nested_parse(\$dimension{$dim}{$instance.'.text'}, + [@_]); + $result .= &nested_parse(\$dimension{$dim}{'questiontext'}, + [@_],{'set_dim_id' => undef}); my $task_status = $Apache::lonhomework::history{"resource.$version.0.status"}; - if ($task_status eq 'pass' || $task_status eq 'fail') { + if ($task_status ne 'pass' && $task_status ne 'fail') { + foreach my $id (@{$dimension{$dim}{$instance.'.criterias'}}, + @{$dimension{$dim}{'criterias'}}) { + my $type = $dimension{$dim}{'criteria.'.$id.'.type'}; + &Apache::lonxml::debug("$id is $type"); + if ($type eq 'dimension') { + $result.= + &nested_parse(\$dimension{$dim}{'criteria.'.$id}, + [@_],{'set_dim_id' => $id}); + } + } + } else { my $dim_status=$Apache::lonhomework::history{"resource.$version.0.$dim.status"}; my $mandatory='Mandatory'; if ($Apache::bridgetask::dimensionmandatory{$dim} eq 'N') { @@ -2095,8 +2215,9 @@ sub get_criteria { $result.= '

' .$mandatory.' Criteria

'; - @Apache::scripttag::parser_env = @_; - $result.=&Apache::scripttag::xmlparse($dimension{$dim}{'criteria.'.$id}); + $result.= + &nested_parse(\$dimension{$dim}{'criteria.'.$id}, + [@_],{'set_dim_id' => $id}); $result.='

'.$status_display.'

'; if ($comment) { $result.='

'. @@ -2106,24 +2227,22 @@ sub get_criteria { } } } - if (exists($dimension{$dim}{'nested'})) { - $dimension{$dim}{'result'}=$result; - undef($result); - } } elsif ($target eq 'webgrade') { # in case of any side effects that we need - @Apache::scripttag::parser_env = @_; - &Apache::scripttag::xmlparse($dimension{$dim}{'intro'}); - @Apache::scripttag::parser_env = @_; - &Apache::scripttag::xmlparse($dimension{$dim}{$instance.'.text'}); - @Apache::scripttag::parser_env = @_; - &Apache::scripttag::xmlparse($dimension{$dim}{'questiontext'}); + &nested_parse(\$dimension{$dim}{'intro'},[@_]); + &nested_parse(\$dimension{$dim}{$instance.'.text'},[@_]); + $result.= + &nested_parse(\$dimension{$dim}{'questiontext'},[@_], + {'set_dim_id' => undef, + 'delayed_dim_results' => 1}); foreach my $id (@{$dimension{$dim}{$instance.'.criterias'}}, @{$dimension{$dim}{'criterias'}} ) { my $type = $dimension{$dim}{'criteria.'.$id.'.type'}; if ($type eq 'dimension') { # dimensional 'criteria' don't get assigned grades - $result.=$dimension{$id}{'result'}; + $result.= + &nested_parse(\$dimension{$dim}{'criteria.'.$id}, + [@_],{'set_dim_id' => $id}); next; } @@ -2131,10 +2250,10 @@ sub get_criteria { my $status= &get_criteria('status',$version,$dim,$id); $result.='

'."\n". '
'."\n"; - @Apache::scripttag::parser_env = @_; - $result.=&Apache::scripttag::xmlparse($dimension{$dim}{'criteria.'.$id}); + $result.= + &nested_parse(\$dimension{$dim}{'criteria.'.$id},[@_]); + $result.='
'."\n". - #$dimension{$dim}{'criteria.'.$id}. '
'."\n". ''."\n". ''."\n". @@ -2152,8 +2271,9 @@ sub get_criteria { $result.=&grading_history($version,$dim,$id); $last_link=$link; } - if (exists($dimension{$dim}{'nested'})) { - $dimension{$dim}{'result'}=$result; + if (&nest()) { + &Apache::lonxml::debug(" for $dim stashing results into ".$dimension{$dim}{'nested'}); + $dimension{$dimension{$dim}{'nested'}}{'result'}.=$result; undef($result); } } elsif ($target eq 'grade' && $env{'form.webgrade'}) { @@ -2162,12 +2282,11 @@ sub get_criteria { my $ungraded=0; my $review=0; - @Apache::scripttag::parser_env = @_; - $result.=&Apache::scripttag::xmlparse($dimension{$dim}{'intro'}); - @Apache::scripttag::parser_env = @_; - $result.=&Apache::scripttag::xmlparse($dimension{$dim}{$instance.'.text'}); - @Apache::scripttag::parser_env = @_; - &Apache::scripttag::xmlparse($dimension{$dim}{'questiontext'}); + $result .= &nested_parse(\$dimension{$dim}{'intro'},[@_]); + $result .= &nested_parse(\$dimension{$dim}{$instance.'.text'}, + [@_]); + $result .= &nested_parse(\$dimension{$dim}{'questiontext'}, + [@_],{'set_dim_id' => undef}); foreach my $id (@{$dimension{$dim}{$instance.'.criterias'}}, @{$dimension{$dim}{'criterias'}}) { @@ -2178,6 +2297,10 @@ sub get_criteria { # dimensional 'criteria' don't get assigned grades $Apache::lonhomework::results{"resource.$version.0.$dim.$id.status"}=$env{'form.HWVAL_'.$link}; $Apache::lonhomework::results{"resource.$version.0.$dim.$id.comment"}=$env{'form.HWVAL_comment_'.$link}; + } else { + $result .= + &nested_parse(\$dimension{$dim}{'criteria.'.$id}, + [@_],{'set_dim_id' => $id}); } my $status= &get_criteria('status',$version,$dim,$id); @@ -2223,6 +2346,7 @@ sub get_criteria { # any other targets no output undef($result); } + &disable_dimension_parsing(); pop(@Apache::bridgetask::dimension); return $result; }