From raeburn at source.lon-capa.org Tue Mar 27 00:36:28 2018 From: raeburn at source.lon-capa.org (raeburn) Date: Tue, 27 Mar 2018 04:36:28 -0000 Subject: [LON-CAPA-cvs] cvs: loncom /homework structuretags.pm /lonnet/perl lonnet.pm Message-ID: raeburn Tue Mar 27 04:36:28 2018 EDT Modified files: /loncom/lonnet/perl lonnet.pm /loncom/homework structuretags.pm Log: - "Student Submission Reports" nneds to include submissions for imported responses. - Include in metadata for library file. - Rebuild responseorder metadata-field for problem with imported library file containing response items. -------------- next part -------------- Index: loncom/lonnet/perl/lonnet.pm diff -u loncom/lonnet/perl/lonnet.pm:1.1368 loncom/lonnet/perl/lonnet.pm:1.1369 --- loncom/lonnet/perl/lonnet.pm:1.1368 Fri Mar 23 01:02:04 2018 +++ loncom/lonnet/perl/lonnet.pm Tue Mar 27 04:36:11 2018 @@ -1,7 +1,7 @@ # The LearningOnline Network # TCP networking package # -# $Id: lonnet.pm,v 1.1368 2018/03/23 01:02:04 raeburn Exp $ +# $Id: lonnet.pm,v 1.1369 2018/03/27 04:36:11 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -11735,6 +11735,7 @@ my %metaentry; my %importedpartids; +my %importedrespids; sub metadata { my ($uri,$what,$toolsymb,$liburi,$prefix,$depthcount)=@_; $uri=&declutter($uri); @@ -11821,9 +11822,11 @@ { # Imported parts would go here - my %importedids=(); - my @origfileimportpartids=(); + my @origfiletagids=(); my $importedparts=0; + +# Imported responseids would go here + my $importedresponses=0; # # Is this a recursive call for a library? # @@ -11918,8 +11921,32 @@ my $dir=$filename; $dir=~s|[^/]*$||; $location=&filelocation($dir,$location); - + + my $importid=$token->[2]->{'id'}; my $importmode=$token->[2]->{'importmode'}; +# +# Check metadata for imported file to +# see if it contained response items +# + my $libresponseorder = &metadata($location,'responseorder'); + my $origfile; + if ($libresponseorder ne '') { + if ($#origfiletagids<0) { + undef(%importedrespids); + undef(%importedpartids); + } + @{$importedrespids{$importid}} = split(/\s*,\s*/,$libresponseorder); + if (@{$importedrespids{$importid}} > 0) { + $importedresponses = 1; +# We need to get the original file and the imported file to get the response order correct +# Load and inspect original file + if ($#origfiletagids<0) { + my $origfilelocation=$perlvar{'lonDocRoot'}.&clutter($uri); + $origfile=&getfile($origfilelocation); + @origfiletagids=($origfile=~/<((?:\w+)response|import|part)[^>]*id\s*=\s*[\"\']([^\"\']+)[\"\'][^>]*>/gs); + } + } + } if ($importmode eq 'problem') { # Import as problem/response $unikey=&add_prefix_and_part($prefix,$token->[2]->{'part'}); @@ -11928,12 +11955,15 @@ $importedparts=1; # We need to get the original file and the imported file to get the part order correct # Good news: we do not need to worry about nested libraries, since parts cannot be nested -# Load and inspect original file - if ($#origfileimportpartids<0) { - undef(%importedpartids); - my $origfilelocation=$perlvar{'lonDocRoot'}.&clutter($uri); - my $origfile=&getfile($origfilelocation); - @origfileimportpartids=($origfile=~/<(part|import)[^>]*id\s*=\s*[\"\']([^\"\']+)[\"\'][^>]*>/gs); +# Load and inspect original file if we didn't do that already + if ($#origfiletagids<0) { + undef(%importedrespids); + undef(%importedpartids); + if ($origfile eq '') { + my $origfilelocation=$perlvar{'lonDocRoot'}.&clutter($uri); + $origfile=&getfile($origfilelocation); + @origfiletagids=($origfile=~/<(part|import)[^>]*id\s*=\s*[\"\']([^\"\']+)[\"\'][^>]*>/gs); + } } # Load and inspect imported file @@ -11964,7 +11994,6 @@ $metaentry{':'.$meta}=$metaentry{':'.$meta}; $metathesekeys{$meta}=1; } - } } else { # @@ -12047,20 +12076,48 @@ grep { ! $seen{$_} ++ } (split(',',$metaentry{':packages'})); $metaentry{':packages'} = join(',', at uniq_packages); - if ($importedparts) { + if (($importedresponses) || ($importedparts)) { + if ($importedparts) { # We had imported parts and need to rebuild partorder - $metaentry{':partorder'}=''; - $metathesekeys{'partorder'}=1; - for (my $index=0;$index<$#origfileimportpartids;$index+=2) { - if ($origfileimportpartids[$index] eq 'part') { -# original part, part of the problem - $metaentry{':partorder'}.=','.$origfileimportpartids[$index+1]; - } else { -# we have imported parts at this position - $metaentry{':partorder'}.=','.$importedpartids{$origfileimportpartids[$index+1]}; - } - } - $metaentry{':partorder'}=~s/^\,//; + $metaentry{':partorder'}=''; + $metathesekeys{'partorder'}=1; + } + if ($importedresponses) { +# We had imported responses and need to rebuil responseorder + $metaentry{':responseorder'}=''; + $metathesekeys{'responseorder'}=1; + } + for (my $index=0;$index<$#origfiletagids;$index+=2) { + my $origid = $origfiletagids[$index+1]; + if ($origfiletagids[$index] eq 'part') { +# Original part, part of the problem + if ($importedparts) { + $metaentry{':partorder'}.=','.$origid; + } + } elsif ($origfiletagids[$index] eq 'import') { + if ($importedparts) { +# We have imported parts at this position + $metaentry{':partorder'}.=','.$importedpartids{$origid}; + } + if ($importedresponses) { +# We have imported responses at this position + if (ref($importedrespids{$origid}) eq 'ARRAY') { + $metaentry{':responseorder'}.=','.join(',',map { $origid.'_'.$_ } @{$importedrespids{$origid}}); + } + } + } else { +# Original response item, part of the problem + if ($importedresponses) { + $metaentry{':responseorder'}.=','.$origid; + } + } + } + if ($importedparts) { + $metaentry{':partorder'}=~s/^\,//; + } + if ($importedresponses) { + $metaentry{':responseorder'}=~s/^\,//; + } } $metaentry{':keys'} = join(',',keys(%metathesekeys)); Index: loncom/homework/structuretags.pm diff -u loncom/homework/structuretags.pm:1.557 loncom/homework/structuretags.pm:1.558 --- loncom/homework/structuretags.pm:1.557 Fri Dec 22 01:55:28 2017 +++ loncom/homework/structuretags.pm Tue Mar 27 04:36:28 2018 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # definition of tags that give a structure to a document # -# $Id: structuretags.pm,v 1.557 2017/12/22 01:55:28 raeburn Exp $ +# $Id: structuretags.pm,v 1.558 2018/03/27 04:36:28 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -2134,6 +2134,8 @@ && ($#$tagstack eq 0 && $$tagstack[0] eq 'library') && $env{'request.state'} eq "construct") { $result.=''.&Apache::loncommon::end_page({'discussion' => 1}); + } elsif ($target eq 'meta') { + $result.=&Apache::response::meta_response_order(); } if ( $#$tagstack eq 0 && $$tagstack[0] eq 'library') { &reset_problem_globals('library'); From raeburn at source.lon-capa.org Thu Mar 29 15:59:09 2018 From: raeburn at source.lon-capa.org (raeburn) Date: Thu, 29 Mar 2018 19:59:09 -0000 Subject: [LON-CAPA-cvs] cvs: rat / lonuserstate.pm Message-ID: raeburn Thu Mar 29 19:59:09 2018 EDT Modified files: /rat lonuserstate.pm Log: - Package globals should be initialized. Index: rat/lonuserstate.pm diff -u rat/lonuserstate.pm:1.154 rat/lonuserstate.pm:1.155 --- rat/lonuserstate.pm:1.154 Thu Nov 16 12:44:48 2017 +++ rat/lonuserstate.pm Thu Mar 29 19:59:08 2018 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Construct and maintain state and binary representation of course for user # -# $Id: lonuserstate.pm,v 1.154 2017/11/16 12:44:48 raeburn Exp $ +# $Id: lonuserstate.pm,v 1.155 2018/03/29 19:59:08 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -1227,6 +1227,8 @@ &unlink_tmpfiles($fn); } undef %randompick; + undef %randompickseed; + undef %randomorder; undef %hiddenurl; undef %encurl; $retfrid=''; @@ -1370,6 +1372,8 @@ $lock=1; } undef %randompick; + undef %randompickseed; + undef %randomorder; undef %hiddenurl; undef %encurl; $errtext=''; From raeburn at source.lon-capa.org Thu Mar 29 16:10:47 2018 From: raeburn at source.lon-capa.org (raeburn) Date: Thu, 29 Mar 2018 20:10:47 -0000 Subject: [LON-CAPA-cvs] cvs: rat(version_2_11_X) / lonuserstate.pm Message-ID: raeburn Thu Mar 29 20:10:47 2018 EDT Modified files: (Branch: version_2_11_X) /rat lonuserstate.pm Log: - For 2.11 Backport 1.155. Index: rat/lonuserstate.pm diff -u rat/lonuserstate.pm:1.149 rat/lonuserstate.pm:1.149.2.1 --- rat/lonuserstate.pm:1.149 Mon Dec 15 01:10:19 2014 +++ rat/lonuserstate.pm Thu Mar 29 20:10:47 2018 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Construct and maintain state and binary representation of course for user # -# $Id: lonuserstate.pm,v 1.149 2014/12/15 01:10:19 raeburn Exp $ +# $Id: lonuserstate.pm,v 1.149.2.1 2018/03/29 20:10:47 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -1174,6 +1174,8 @@ &unlink_tmpfiles($fn); } undef %randompick; + undef %randompickseed; + undef %randomorder; undef %hiddenurl; undef %encurl; $retfrid=''; @@ -1317,6 +1319,8 @@ $lock=1; } undef %randompick; + undef %randompickseed; + undef %randomorder; undef %hiddenurl; undef %encurl; $errtext=''; From raeburn at source.lon-capa.org Thu Mar 29 17:12:58 2018 From: raeburn at source.lon-capa.org (raeburn) Date: Thu, 29 Mar 2018 21:12:58 -0000 Subject: [LON-CAPA-cvs] cvs: rat / lonuserstate.pm Message-ID: raeburn Thu Mar 29 21:12:58 2018 EDT Modified files: /rat lonuserstate.pm Log: - Package globals should be initialized. Index: rat/lonuserstate.pm diff -u rat/lonuserstate.pm:1.155 rat/lonuserstate.pm:1.156 --- rat/lonuserstate.pm:1.155 Thu Mar 29 19:59:08 2018 +++ rat/lonuserstate.pm Thu Mar 29 21:12:57 2018 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Construct and maintain state and binary representation of course for user # -# $Id: lonuserstate.pm,v 1.155 2018/03/29 19:59:08 raeburn Exp $ +# $Id: lonuserstate.pm,v 1.156 2018/03/29 21:12:57 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -1229,8 +1229,11 @@ undef %randompick; undef %randompickseed; undef %randomorder; + undef %randomizationcode; undef %hiddenurl; undef %encurl; + undef %rescount; + undef %mapcount; $retfrid=''; $errtext=''; my ($untiedhash,$untiedparmhash,$tiedhash,$tiedparmhash); # More state flags. @@ -1374,8 +1377,11 @@ undef %randompick; undef %randompickseed; undef %randomorder; + undef %randomizationcode; undef %hiddenurl; undef %encurl; + undef %rescount; + undef %mapcount; $errtext=''; $retfrid=''; # From raeburn at source.lon-capa.org Fri Mar 30 14:07:47 2018 From: raeburn at source.lon-capa.org (raeburn) Date: Fri, 30 Mar 2018 18:07:47 -0000 Subject: [LON-CAPA-cvs] cvs: loncom /lonnet/perl lonnet.pm Message-ID: raeburn Fri Mar 30 18:07:47 2018 EDT Modified files: /loncom/lonnet/perl lonnet.pm Log: - Stop retrieval of metadata for library file(s) -- rev. 1.1369 -- overwriting %metaentry hash contents for resource containing them. Index: loncom/lonnet/perl/lonnet.pm diff -u loncom/lonnet/perl/lonnet.pm:1.1369 loncom/lonnet/perl/lonnet.pm:1.1370 --- loncom/lonnet/perl/lonnet.pm:1.1369 Tue Mar 27 04:36:11 2018 +++ loncom/lonnet/perl/lonnet.pm Fri Mar 30 18:07:47 2018 @@ -1,7 +1,7 @@ # The LearningOnline Network # TCP networking package # -# $Id: lonnet.pm,v 1.1369 2018/03/27 04:36:11 raeburn Exp $ +# $Id: lonnet.pm,v 1.1370 2018/03/30 18:07:47 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -11928,6 +11928,7 @@ # Check metadata for imported file to # see if it contained response items # + my %currmetaentry = %metaentry; my $libresponseorder = &metadata($location,'responseorder'); my $origfile; if ($libresponseorder ne '') { @@ -11947,6 +11948,10 @@ } } } +# Do not overwrite contents of %metaentry hash for resource itself with +# hash populated for imported library file + %metaentry = %currmetaentry; + undef(%currmetaentry); if ($importmode eq 'problem') { # Import as problem/response $unikey=&add_prefix_and_part($prefix,$token->[2]->{'part'}); From raeburn at source.lon-capa.org Fri Mar 30 17:30:00 2018 From: raeburn at source.lon-capa.org (raeburn) Date: Fri, 30 Mar 2018 21:30:00 -0000 Subject: [LON-CAPA-cvs] cvs: loncom /lonnet/perl lonnet.pm Message-ID: raeburn Fri Mar 30 21:30:00 2018 EDT Modified files: /loncom/lonnet/perl lonnet.pm Log: - No &do_cache_new() when &metadata was called with $liburi defined. Index: loncom/lonnet/perl/lonnet.pm diff -u loncom/lonnet/perl/lonnet.pm:1.1370 loncom/lonnet/perl/lonnet.pm:1.1371 --- loncom/lonnet/perl/lonnet.pm:1.1370 Fri Mar 30 18:07:47 2018 +++ loncom/lonnet/perl/lonnet.pm Fri Mar 30 21:30:00 2018 @@ -1,7 +1,7 @@ # The LearningOnline Network # TCP networking package # -# $Id: lonnet.pm,v 1.1370 2018/03/30 18:07:47 raeburn Exp $ +# $Id: lonnet.pm,v 1.1371 2018/03/30 21:30:00 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -12128,7 +12128,9 @@ $metaentry{':keys'} = join(',',keys(%metathesekeys)); &metadata_generate_part0(\%metathesekeys,\%metaentry,$uri); $metaentry{':allpossiblekeys'}=join(',',keys(%metathesekeys)); - &do_cache_new('meta',$uri,\%metaentry,$cachetime); + unless ($liburi) { + &do_cache_new('meta',$uri,\%metaentry,$cachetime); + } # this is the end of "was not already recently cached } return $metaentry{':'.$what}; @@ -14851,7 +14853,9 @@ the toolsymb is only used where the uri is for an external tool (for which the uri as well as the symb are guaranteed to be unique). -this function automatically caches all requests +this function automatically caches all requests except any made recursively +to retrieve a list of metadata keys for an imported library file ($liburi is +defined). =item * From raeburn at source.lon-capa.org Fri Mar 30 19:50:29 2018 From: raeburn at source.lon-capa.org (raeburn) Date: Fri, 30 Mar 2018 23:50:29 -0000 Subject: [LON-CAPA-cvs] cvs: loncom /homework response.pm structuretags.pm /lonnet/perl lonnet.pm Message-ID: raeburn Fri Mar 30 23:50:29 2018 EDT Modified files: /loncom/homework structuretags.pm response.pm /loncom/lonnet/perl lonnet.pm Log: - tag for a library file will include ids of any part tags. - library file is only loaded and inspected to check for parts if is absent. Index: loncom/homework/structuretags.pm diff -u loncom/homework/structuretags.pm:1.558 loncom/homework/structuretags.pm:1.559 --- loncom/homework/structuretags.pm:1.558 Tue Mar 27 04:36:28 2018 +++ loncom/homework/structuretags.pm Fri Mar 30 23:50:13 2018 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # definition of tags that give a structure to a document # -# $Id: structuretags.pm,v 1.558 2018/03/27 04:36:28 raeburn Exp $ +# $Id: structuretags.pm,v 1.559 2018/03/30 23:50:13 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -2057,7 +2057,7 @@ @Apache::inputtags::response=(); $result=&Apache::response::mandatory_part_meta; } - $result.=&Apache::response::meta_part_order(); + $result.=&Apache::response::meta_part_order('problem'); $result.=&Apache::response::meta_response_order(); } elsif ($target eq 'edit') { &Apache::lonxml::debug("in end_problem with $target, edit"); @@ -2135,6 +2135,7 @@ && $env{'request.state'} eq "construct") { $result.=''.&Apache::loncommon::end_page({'discussion' => 1}); } elsif ($target eq 'meta') { + $result.=&Apache::response::meta_part_order('library'); $result.=&Apache::response::meta_response_order(); } if ( $#$tagstack eq 0 && $$tagstack[0] eq 'library') { Index: loncom/homework/response.pm diff -u loncom/homework/response.pm:1.244 loncom/homework/response.pm:1.245 --- loncom/homework/response.pm:1.244 Fri Oct 30 03:49:47 2015 +++ loncom/homework/response.pm Fri Mar 30 23:50:13 2018 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # various response type definitons response definition # -# $Id: response.pm,v 1.244 2015/10/30 03:49:47 raeburn Exp $ +# $Id: response.pm,v 1.245 2018/03/30 23:50:13 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -265,10 +265,15 @@ } sub meta_part_order { + my ($type) = @_; if (@Apache::inputtags::partlist) { my @parts=@Apache::inputtags::partlist; - shift(@parts); + unless ($type eq 'library') { + shift(@parts); + } return ''.join(',', at parts).''."\n"; + } elsif ($type eq 'library') { + return ''."\n"; } else { return '0'."\n"; } Index: loncom/lonnet/perl/lonnet.pm diff -u loncom/lonnet/perl/lonnet.pm:1.1371 loncom/lonnet/perl/lonnet.pm:1.1372 --- loncom/lonnet/perl/lonnet.pm:1.1371 Fri Mar 30 21:30:00 2018 +++ loncom/lonnet/perl/lonnet.pm Fri Mar 30 23:50:29 2018 @@ -1,7 +1,7 @@ # The LearningOnline Network # TCP networking package # -# $Id: lonnet.pm,v 1.1371 2018/03/30 21:30:00 raeburn Exp $ +# $Id: lonnet.pm,v 1.1372 2018/03/30 23:50:29 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -11928,23 +11928,28 @@ # Check metadata for imported file to # see if it contained response items # + my ($origfile, at libfilekeys); my %currmetaentry = %metaentry; - my $libresponseorder = &metadata($location,'responseorder'); - my $origfile; - if ($libresponseorder ne '') { - if ($#origfiletagids<0) { - undef(%importedrespids); - undef(%importedpartids); - } - @{$importedrespids{$importid}} = split(/\s*,\s*/,$libresponseorder); - if (@{$importedrespids{$importid}} > 0) { - $importedresponses = 1; + @libfilekeys = split(/,/,&metadata($location,'keys',undef,undef,undef, + $depthcount+1)); + if (grep(/^responseorder$/, at libfilekeys)) { + my $libresponseorder = &metadata($location,'responseorder',undef,undef, + undef,$depthcount+1); + if ($libresponseorder ne '') { + if ($#origfiletagids<0) { + undef(%importedrespids); + undef(%importedpartids); + } + @{$importedrespids{$importid}} = split(/\s*,\s*/,$libresponseorder); + if (@{$importedrespids{$importid}} > 0) { + $importedresponses = 1; # We need to get the original file and the imported file to get the response order correct # Load and inspect original file - if ($#origfiletagids<0) { - my $origfilelocation=$perlvar{'lonDocRoot'}.&clutter($uri); - $origfile=&getfile($origfilelocation); - @origfiletagids=($origfile=~/<((?:\w+)response|import|part)[^>]*id\s*=\s*[\"\']([^\"\']+)[\"\'][^>]*>/gs); + if ($#origfiletagids<0) { + my $origfilelocation=$perlvar{'lonDocRoot'}.&clutter($uri); + $origfile=&getfile($origfilelocation); + @origfiletagids=($origfile=~/<((?:\w+)response|import|part)[^>]*id\s*=\s*[\"\']([^\"\']+)[\"\'][^>]*>/gs); + } } } } @@ -11970,10 +11975,23 @@ @origfiletagids=($origfile=~/<(part|import)[^>]*id\s*=\s*[\"\']([^\"\']+)[\"\'][^>]*>/gs); } } - -# Load and inspect imported file - my $impfile=&getfile($location); - my @impfilepartids=($impfile=~/]*id\s*=\s*[\"\']([^\"\']+)[\"\'][^>]*>/gs); + my @impfilepartids; +# If tag is included in metadata for the imported file +# get the parts in the imported file from that. + if (grep(/^partorder$/, at libfilekeys)) { + %currmetaentry = %metaentry; + my $libpartorder = &metadata($location,'partorder',undef,undef,undef, + $depthcount+1); + %metaentry = %currmetaentry; + undef(%currmetaentry); + if ($libpartorder ne '') { + @impfilepartids=split(/\s*,\s*/,$libpartorder); + } + } else { +# If no tag available, load and inspect imported file + my $impfile=&getfile($location); + @impfilepartids=($impfile=~/]*id\s*=\s*[\"\']([^\"\']+)[\"\'][^>]*>/gs); + } if ($#impfilepartids>=0) { # This problem had parts $importedpartids{$token->[2]->{'id'}}=join(',', at impfilepartids); @@ -12124,7 +12142,6 @@ $metaentry{':responseorder'}=~s/^\,//; } } - $metaentry{':keys'} = join(',',keys(%metathesekeys)); &metadata_generate_part0(\%metathesekeys,\%metaentry,$uri); $metaentry{':allpossiblekeys'}=join(',',keys(%metathesekeys));