--- loncom/interface/statistics/lonstathelpers.pm 2004/09/15 21:07:34 1.21 +++ loncom/interface/statistics/lonstathelpers.pm 2005/11/12 03:58:55 1.51 @@ -1,6 +1,6 @@ # The LearningOnline Network with CAPA # -# $Id: lonstathelpers.pm,v 1.21 2004/09/15 21:07:34 matthew Exp $ +# $Id: lonstathelpers.pm,v 1.51 2005/11/12 03:58:55 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -49,7 +49,7 @@ routines that are needed across multiple package Apache::lonstathelpers; use strict; -use Apache::lonnet(); +use Apache::lonnet; use Apache::loncommon(); use Apache::lonhtmlcommon(); use Apache::loncoursedata(); @@ -68,8 +68,7 @@ use Storable qw(freeze thaw); =item &render_resource($resource) -Input: a resource generated from -&Apache::loncoursedata::get_sequence_assessment_data(). +Input: a navmaps resource Retunrs: a scalar containing html for a rendering of the problem within a table. @@ -82,11 +81,10 @@ sub render_resource { my ($resource) = @_; ## ## Render the problem - my $base; - ($base,undef) = ($resource->{'src'} =~ m|(.*/)[^/]*$|); - $base = "http://".$ENV{'SERVER_NAME'}.$base; - my $rendered_problem = - &Apache::lonnet::ssi_body($resource->{'src'}); + my ($base) = ($resource->src =~ m|^(.*/)[^/]*$|); + $base="http://".$ENV{'SERVER_NAME'}.$base; + my ($src,$symb)=($resource->src,&Apache::lonnet::escape($resource->symb)); + my $rendered_problem = &Apache::lonnet::ssi_body($src.'?symb='.$symb); $rendered_problem =~ s/<\s*form\s*/)|<\/nop>|g; return '
'. @@ -100,7 +98,26 @@ sub render_resource { =pod -=item &ProblemSelector($AcceptedResponseTypes) +=item &get_resources + +=cut + +#################################################### +#################################################### +sub get_resources { + my ($navmap,$sequence) = @_; + my @resources = $navmap->retrieveResources($sequence, + sub { shift->is_problem(); }, + 0,0,0); + return @resources; +} + +#################################################### +#################################################### + +=pod + +=item &problem_selector($AcceptedResponseTypes) Input: scalar containing regular expression which matches response types to show. '.' will yield all, '(option|radiobutton)' will match @@ -114,50 +131,63 @@ Skips 'survey' problems. #################################################### #################################################### -sub ProblemSelector { - my ($AcceptedResponseTypes) = @_; +sub problem_selector { + my ($AcceptedResponseTypes,$sequence_addendum) = @_; my $Str; $Str = "\n\n"; - foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess('all')) { - next if ($seq->{'num_assess'}<1); + my $rb_count =0; + my ($navmap,@sequences) = + &Apache::lonstatistics::selected_sequences_with_assessments('all'); + return $navmap if (! ref($navmap)); # error + foreach my $seq (@sequences) { my $seq_str = ''; - foreach my $res (@{$seq->{'contents'}}) { - next if ($res->{'type'} ne 'assessment'); - foreach my $part (@{$res->{'parts'}}) { - my $partdata = $res->{'partdata'}->{$part}; - for (my $i=0;$i{'ResponseTypes'}});$i++){ - my $respid = $partdata->{'ResponseIds'}->[$i]; - my $resptype = $partdata->{'ResponseTypes'}->[$i]; + foreach my $res (&get_resources($navmap,$seq)) { + foreach my $part (@{$res->parts}) { + my @response_ids = $res->responseIds($part); + my @response_types = $res->responseType($part); + for (my $i=0;$i$res->{'symb'}, + my $value = &make_target_id({symb=>$res->symb, part=>$part, respid=>$respid, resptype=>$resptype}); my $checked = ''; - if ($ENV{'form.problemchoice'} eq $value) { + if ($env{'form.problemchoice'} eq $value) { $checked = 'checked '; } - my $title = $res->{'title'}; + my $title = $res->compTitle; if (! defined($title) || $title eq '') { - ($title) = ($res->{'src'} =~ m:/([^/]*)$:); + ($title) = ($res->src =~ m:/([^/]*)$:); } - $seq_str .= ''. + qq{}. + ''. + '\n"; + $rb_count++; } } } } if ($seq_str ne '') { - $Str .= ''. + $Str .= ''. + ''. "\n".$seq_str; + if (defined($sequence_addendum)) { + $Str .= ''. + (''x2). + ''. + "\n"; + } } } $Str .= "
'. - ''. - ''. - $resptype.''. - ''.$title.' '; -# ''.$resptype.' '.$res->{'title'}.' '; - if (scalar(@{$partdata->{'ResponseIds'}}) > 1) { + $seq_str .= '
'; + if (scalar(@response_ids) > 1) { $seq_str .= &mt('response').' '.$respid; } + my $link = $res->src.'?symb='. + &Apache::lonnet::escape($res->symb); + $seq_str .= (' 'x2). + qq{view}; $seq_str .= "
 '.$seq->{'title'}.'
 '.$seq->compTitle.'
 '.$sequence_addendum.'
\n"; @@ -169,7 +199,7 @@ sub ProblemSelector { =pod -=item &MultpleProblemSelector($navmap,$ResponseTypes,$selected,$inputname) +=item &MultipleProblemSelector($navmap,$selected,$inputname) Generate HTML with checkboxes for problem selection. @@ -178,10 +208,6 @@ Input: $navmap: a navmap object. If undef, navmaps will be called to create a new object. -$ResponseTypes: scalar containing regular expression which matches response -types. Only those problems which contain the given response type will be -shown. - $selected: Scalar, Array, or hash reference of currently selected items. $inputname: The name of the form elements to use for the checkboxs. @@ -194,8 +220,8 @@ and their contents. A checkbox is provi #################################################### #################################################### sub MultipleProblemSelector { - my ($navmap,$ReponseTypes,$inputname,$formname)=@_; - my $cid = $ENV{'request.course.id'}; + my ($navmap,$inputname,$formname)=@_; + my $cid = $env{'request.course.id'}; my $Str; # Massage the input as needed. if (! defined($navmap)) { @@ -209,12 +235,20 @@ sub MultipleProblemSelector { my $selected = {map { ($_,1) } (&get_selected_symbs($inputname))}; # Header $Str .= <<"END"; -'. + ''. + ''. + ''; + my $output_selector = $/.''.$/; + my $link = ''; + $html.= &mt('View data as [_1] [_2]go[_3]',$output_selector, + $link,'').$/; + return $html +} #################################################### ####################################################