[LON-CAPA-cvs] cvs: loncom /homework bridgetask.pm
albertel
lon-capa-cvs@mail.lon-capa.org
Fri, 16 Jun 2006 09:27:41 -0000
This is a MIME encoded message
--albertel1150450061
Content-Type: text/plain
albertel Fri Jun 16 05:27:41 2006 EDT
Modified files:
/loncom/homework bridgetask.pm
Log:
- reworked the nesting algorithm so parsing happens in the expected order
--albertel1150450061
Content-Type: text/plain
Content-Disposition: attachment; filename="albertel-20060616052741.txt"
Index: loncom/homework/bridgetask.pm
diff -u loncom/homework/bridgetask.pm:1.172 loncom/homework/bridgetask.pm:1.173
--- loncom/homework/bridgetask.pm:1.172 Wed Jun 14 11:47:58 2006
+++ loncom/homework/bridgetask.pm Fri Jun 16 05:27:38 2006
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# definition of tags that give a structure to a document
#
-# $Id: bridgetask.pm,v 1.172 2006/06/14 15:47:58 albertel Exp $
+# $Id: bridgetask.pm,v 1.173 2006/06/16 09:27:38 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -316,6 +316,36 @@
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();
+ return $dimension{$dim}{'result'};
+ }
+ return $result;
+}
+
sub internal_location {
my ($id)=@_;
return '<!-- LONCAPA_INTERNAL_ADD_TASK_STATUS'.$id.' -->';
@@ -1907,16 +1937,42 @@
&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)
+ .'</'.$tagstack->[-1].'>';
+ }
$dimension{$previous_dim}{'criteria.'.$dim.'.type'}='dimension';
$dimension{$previous_dim}{'criteria.'.$dim.'.mandatory'}=
&Apache::lonxml::get_param('Mandatory',$parstack,$safeeval);
@@ -1929,6 +1985,7 @@
}
push(@Apache::bridgetask::dimension,$dim);
&Apache::lonxml::startredirection();
+ &enable_dimension_parsing($dim);
return &internal_location($dim);
}
@@ -1965,20 +2022,22 @@
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;
@@ -2009,26 +2068,40 @@
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') {
@@ -2096,8 +2169,9 @@
$result.=
'<div class="LC_'.$status.' LC_criteria"><h4>'
.$mandatory.' Criteria</h4><p>';
- @Apache::scripttag::parser_env = @_;
- $result.=&Apache::scripttag::xmlparse($dimension{$dim}{'criteria.'.$id});
+ $result.=
+ &nested_parse(\$dimension{$dim}{'criteria.'.$id},
+ [@_],{'set_dim_id' => $id});
$result.='</p><p class="LC_grade">'.$status_display.'</p>';
if ($comment) {
$result.='<p class="LC_comment">'.
@@ -2105,34 +2179,24 @@
}
$result.='</div>';
}
- } else {
- foreach my $id (@{$dimension{$dim}{$instance.'.criterias'}},
- @{$dimension{$dim}{'criterias'}}) {
- my $type = $dimension{$dim}{'criteria.'.$id.'.type'};
- if ($type eq 'dimension') {
- $result.=$dimension{$id}{'result'};
- }
- }
}
}
- 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,
+ 'delay_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;
}
@@ -2140,10 +2204,10 @@
my $status= &get_criteria('status',$version,$dim,$id);
$result.='<div class="LC_GRADING_criteria" id="'.$link.'">'."\n".
'<div class="LC_GRADING_criteriatext" id="next_'.$last_link.'">'."\n";
- @Apache::scripttag::parser_env = @_;
- $result.=&Apache::scripttag::xmlparse($dimension{$dim}{'criteria.'.$id});
+ $result.=
+ &nested_parse(\$dimension{$dim}{'criteria.'.$id},[@_]);
+
$result.='</div>'."\n".
- #$dimension{$dim}{'criteria.'.$id}.
'<div class="LC_GRADING_grade">'."\n".
'<label class="LC_GRADING_ungraded"><input type="radio" name="HWVAL_'.$link.'" value="ungraded" '.($status eq 'ungraded' || !$status ? 'checked="checked"':'').' />'.&mt('Ungraded').'</label>'."\n".
'<label class="LC_GRADING_fail"><input type="radio" name="HWVAL_'.$link.'" value="fail" '.($status eq 'fail' ? 'checked="checked"':'').' />'.&mt('Fail').'</label>'."\n".
@@ -2161,8 +2225,9 @@
$result.=&grading_history($version,$dim,$id);
$last_link=$link;
}
- if (exists($dimension{$dim}{'nested'})) {
- $dimension{$dim}{'result'}=$result;
+ if (&delay_result()) {
+ &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'}) {
@@ -2171,12 +2236,11 @@
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'}}) {
@@ -2187,6 +2251,10 @@
# 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);
@@ -2232,6 +2300,7 @@
# any other targets no output
undef($result);
}
+ &disable_dimension_parsing();
pop(@Apache::bridgetask::dimension);
return $result;
}
--albertel1150450061--