+
$stateTitle
HEADER
+ $result .= "";
+
$result .= < |
@@ -688,6 +737,7 @@ sub render {
for my $element (@{$self->{ELEMENTS}}) {
push @results, $element->render();
}
+
return join("\n", @results);
}
@@ -700,23 +750,8 @@ package Apache::lonhelper::element;
=head2 Element Base Class
-The Apache::lonhelper::element base class provides support methods for
-the elements to use, such as a multiple value processer.
-
-B:
-
-=over 4
-
-=item * process_multiple_choices(formName, varName): Process the form
-element named "formName" and place the selected items into the helper
-variable named varName. This is for things like checkboxes or
-multiple-selection listboxes where the user can select more then
-one entry. The selected entries are delimited by triple pipes in
-the helper variables, like this:
-
- CHOICE_1|||CHOICE_2|||CHOICE_3
-
-=back
+The Apache::lonhelper::element base class provides support for elements
+and defines some generally useful tags for use in elements.
B
@@ -744,6 +779,12 @@ some setting accidentally.
Again, see the course initialization helper for examples.
+B
+
+If the element stores the name of the variable in a 'variable' member, which
+the provided ones all do, you can retreive the value of the variable by calling
+this method.
+
=cut
BEGIN {
@@ -830,26 +871,9 @@ sub overrideForm {
return 0;
}
-sub process_multiple_choices {
+sub getValue {
my $self = shift;
- my $formname = shift;
- my $var = shift;
-
- # Must extract values from data directly, as there
- # may be more then one.
- my @values;
- for my $formparam (split (/&/, $ENV{QUERY_STRING})) {
- my ($name, $value) = split(/=/, $formparam);
- if ($name ne $formname) {
- next;
- }
- $value =~ tr/+/ /;
- $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
- push @values, $value;
- }
- $helper->{VARS}->{$var} = join('|||', @values);
-
- return;
+ return $helper->{VARS}->{$self->{'variable'}};
}
1;
@@ -1204,9 +1228,8 @@ sub postprocess {
return 0;
}
- if ($self->{'multichoice'}) {
- $self->process_multiple_choices($self->{'variable'}.'.forminput',
- $self->{'variable'});
+ if (ref($chosenValue)) {
+ $helper->{VARS}->{$self->{'variable'}} = join('|||', @$chosenValue);
}
if (defined($self->{NEXTSTATE})) {
@@ -1452,7 +1475,10 @@ variable stores the results. It also tak
which controls whether the user can select more then one resource. The
"toponly" attribute controls whether the resource display shows just the
resources in that sequence, or recurses into all sub-sequences, defaulting
-to false.
+to false. The "suppressEmptySequences" attribute reflects the
+suppressEmptySequences argument to the render routine, which will cause
+folders that have all of their contained resources filtered out to also
+be filtered out.
B
@@ -1513,6 +1539,7 @@ sub start_resource {
$paramHash->{'variable'} = $token->[2]{'variable'};
$helper->declareVar($paramHash->{'variable'});
$paramHash->{'multichoice'} = $token->[2]{'multichoice'};
+ $paramHash->{'suppressEmptySequences'} = $token->[2]{'suppressEmptySequences'};
$paramHash->{'toponly'} = $token->[2]{'toponly'};
return '';
}
@@ -1681,6 +1708,7 @@ BUTTONS
'showParts' => 0,
'filterFunc' => $filterFunc,
'resource_no_folder_link' => 1,
+ 'suppressEmptySequences' => $self->{'suppressEmptySequences'},
'iterator_map' => $mapUrl }
);
@@ -1692,11 +1720,6 @@ BUTTONS
sub postprocess {
my $self = shift;
- if ($self->{'multichoice'}) {
- $self->process_multiple_choices($self->{'variable'}.'.forminput',
- $self->{'variable'});
- }
-
if ($self->{'multichoice'} && !$helper->{VARS}->{$self->{'variable'}}) {
$self->{ERROR_MSG} = 'You must choose at least one resource to continue.';
return 0;
@@ -1854,10 +1877,6 @@ sub postprocess {
return 0;
}
- if ($self->{'multichoice'}) {
- $self->process_multiple_choices($self->{'variable'}.'.forminput',
- $self->{'variable'});
- }
if (defined($self->{NEXTSTATE})) {
$helper->changeState($self->{NEXTSTATE});
}
@@ -2142,10 +2161,6 @@ sub postprocess {
return 0;
}
- if ($self->{'multichoice'}) {
- $self->process_multiple_choices($self->{'variable'}.'.forminput',
- $self->{'variable'});
- }
if (defined($self->{NEXTSTATE})) {
$helper->changeState($self->{NEXTSTATE});
}
@@ -2362,6 +2377,101 @@ sub end_eval {
1;
+package Apache::lonhelper::final;
+
+=pod
+
+=head2 Element: final
+
+ is a special element that works with helpers that use the
+tag. It goes through all the states and elements, executing the
+snippets and collecting the results. Finally, it takes the user out of the
+helper, going to a provided page.
+
+=cut
+
+no strict;
+@ISA = ("Apache::lonhelper::element");
+use strict;
+
+BEGIN {
+ &Apache::lonhelper::register('Apache::lonhelper::final',
+ ('final', 'exitpage'));
+}
+
+sub new {
+ my $ref = Apache::lonhelper::element->new();
+ bless($ref);
+}
+
+sub start_final { return ''; }
+
+sub end_final {
+ my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
+
+ if ($target ne 'helper') {
+ return '';
+ }
+
+ Apache::lonhelper::final->new();
+
+ return '';
+}
+
+sub start_exitpage {
+ my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
+
+ if ($target ne 'helper') {
+ return '';
+ }
+
+ $paramHash->{EXIT_PAGE} = &Apache::lonxml::get_all_text('/exitpage',
+ $parser);
+
+ return '';
+}
+
+sub end_exitpage { return ''; }
+
+sub render {
+ my $self = shift;
+
+ my @results;
+
+ # Collect all the results
+ for my $stateName (keys %{$helper->{STATES}}) {
+ my $state = $helper->{STATES}->{$stateName};
+
+ for my $element (@{$state->{ELEMENTS}}) {
+ if (defined($element->{FINAL_CODE})) {
+ # Compile the code.
+ my $code = 'sub { my $helper = shift; my $element = shift; '
+ . $element->{FINAL_CODE} . '}';
+ $code = eval($code);
+ die 'Error while executing final code for element with var ' .
+ $element->{'variable'} . ', Perl said: ' . $@ if $@;
+
+ my $result = &$code($helper, $element);
+ if ($result) {
+ push @results, $result;
+ }
+ }
+ }
+ }
+
+ if (scalar(@results) == 0) {
+ return '';
+ }
+
+ my $result = "\n";
+ for my $re (@results) {
+ $result .= ' - ' . $re . "
\n";
+ }
+ return $result . ' ';
+}
+
+1;
+
package Apache::lonhelper::parmwizfinal;
# This is the final state for the parmwizard. It is not generally useful,
@@ -2409,60 +2519,72 @@ sub render {
'due_date' => "0_duedate",
'answer_date' => "0_answerdate");
- my $result = "\n";
|