--- loncom/interface/statistics/lonstathelpers.pm 2005/02/01 15:15:28 1.36 +++ loncom/interface/statistics/lonstathelpers.pm 2009/05/06 16:19:42 1.59 @@ -1,6 +1,6 @@ # The LearningOnline Network with CAPA # -# $Id: lonstathelpers.pm,v 1.36 2005/02/01 15:15:28 matthew Exp $ +# $Id: lonstathelpers.pm,v 1.59 2009/05/06 16:19:42 bisitz 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(); @@ -60,6 +60,9 @@ use Time::Local(); use Spreadsheet::WriteExcel(); use GDBM_File; use Storable qw(freeze thaw); +use lib '/home/httpd/lib/perl/'; +use LONCAPA; + #################################################### #################################################### @@ -68,8 +71,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 +84,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'}.'?symb='.&Apache::lonnet::escape($resource->{'symb'})); + my ($base) = ($resource->src =~ m|^(.*/)[^/]*$|); + $base="http://".$ENV{'SERVER_NAME'}.$base; + my ($src,$symb)=($resource->link,&escape($resource->shown_symb)); + my $rendered_problem = &Apache::lonnet::ssi_body($src.'?symb='.$symb); $rendered_problem =~ s/<\s*form\s*/)|<\/nop>|g; return '
'. @@ -100,7 +101,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,45 +134,46 @@ Skips 'survey' problems. #################################################### #################################################### -sub ProblemSelector { - my ($AcceptedResponseTypes) = @_; +sub problem_selector { + my ($AcceptedResponseTypes,$sequence_addendum) = @_; my $Str; $Str = "\n\n"; my $rb_count =0; - foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess('all')) { - next if ($seq->{'num_assess'}<1); + 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) { - $checked = 'checked '; + if ($env{'form.problemchoice'} eq $value) { + $checked = ' 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{}. + qq{}. ''. '\n"; $rb_count++; } @@ -160,8 +181,15 @@ sub ProblemSelector { } } if ($seq_str ne '') { - $Str .= ''. + $Str .= ''. + ''. "\n".$seq_str; + if (defined($sequence_addendum)) { + $Str .= ''. + (''x2). + ''. + "\n"; + } } } $Str .= "
'; - if (scalar(@{$partdata->{'ResponseIds'}}) > 1) { + if (scalar(@response_ids) > 1) { $seq_str .= &mt('response').' '.$respid; } - my $link = $res->{'src'}.'?symb='. - &Apache::lonnet::escape($res->{'symb'}); + my $link = $res->link.'?symb='.&escape($res->shown_symb); $seq_str .= (' 'x2). - qq{view}; + ''.&mt('view').''; $seq_str .= "
 '.$seq->{'title'}.'
 '.$seq->compTitle.'
 '.$sequence_addendum.'
\n"; @@ -195,21 +223,22 @@ and their contents. A checkbox is provi #################################################### sub MultipleProblemSelector { my ($navmap,$inputname,$formname)=@_; - my $cid = $ENV{'request.course.id'}; + my $cid = $env{'request.course.id'}; my $Str; # Massage the input as needed. if (! defined($navmap)) { $navmap = Apache::lonnavmaps::navmap->new(); if (! defined($navmap)) { - $Str .= - '

'.&mt('Error: cannot process course structure').'

'; + $Str .= '
' + .&mt('Error: cannot process course structure') + .'
'; return $Str; } } 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 +} #################################################### ####################################################