--- loncom/interface/loncoursedata.pm 2002/08/31 18:31:15 1.27 +++ loncom/interface/loncoursedata.pm 2002/09/01 06:23:19 1.28 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # (Publication Handler # -# $Id: loncoursedata.pm,v 1.27 2002/08/31 18:31:15 stredwic Exp $ +# $Id: loncoursedata.pm,v 1.28 2002/09/01 06:23:19 stredwic Exp $ # # Copyright Michigan State University Board of Trustees # @@ -309,6 +309,15 @@ sub ProcessTopResourceMap { return 'Can not open Coursemap.'; } + my $oldkeys; + if(defined($cache->{'ResourceKeys'})) { + $oldkeys = $cache->{'ResourceKeys'}; + foreach (split(':::', $cache->{'ResourceKeys'})) { + delete $cache->{$_}; + } + delete $cache->{'ResourceKeys'}; + } + # Initialize state machine. Set information pointing to top level map. my (@sequences, @currentResource, @finishResource); my ($currentSequence, $currentResourceID, $lastResourceID); @@ -320,6 +329,7 @@ sub ProcessTopResourceMap { my $topLevelSequenceNumber = $currentSequence; my %sequenceRecord; + my %allkeys; while(1) { if($c->aborted()) { last; @@ -344,6 +354,7 @@ sub ProcessTopResourceMap { } else { $cache->{'orderedSequences'}.=':'.$currentSequence; } + $allkeys{'orderedSequences'}++; $lastResourceID=$hash{'map_finish_'. $hash{'src_'.$currentResourceID}}; @@ -378,20 +389,24 @@ sub ProcessTopResourceMap { $currentResourceID})); $cache->{$currentResourceID.':problem'}=$Problem; + $allkeys{$currentResourceID.':problem'}++; if(!defined($cache->{$currentSequence.':problems'})) { $cache->{$currentSequence.':problems'}=$currentResourceID; } else { $cache->{$currentSequence.':problems'}.= ':'.$currentResourceID; } + $allkeys{$currentSequence.':problems'}++; my $meta=$hash{'src_'.$currentResourceID}; # $cache->{$currentResourceID.':title'}= # &Apache::lonnet::metdata($meta,'title'); $cache->{$currentResourceID.':title'}= $hash{'title_'.$currentResourceID}; + $allkeys{$currentResourceID.':title'}++; $cache->{$currentResourceID.':source'}= $hash{'src_'.$currentResourceID}; + $allkeys{$currentResourceID.':source'}++; # Get Parts for problem my %beenHere; @@ -408,6 +423,8 @@ sub ProcessTopResourceMap { $cache->{$currentSequence.':'.$currentResourceID. ':parts'}.=':'.$partId; } + $allkeys{$currentSequence.':'.$currentResourceID. + ':parts'}++; } if($beenHere{'r:'.$partId.':'.$responseId} == 0) { $beenHere{'r:'.$partId.':'.$responseId}++; @@ -421,6 +438,8 @@ sub ProcessTopResourceMap { ':'.$partId.':responseIDs'}.=':'. $responseId; } + $allkeys{$currentSequence.':'.$currentResourceID.':'. + $partId.':responseIDs'}++; } if(/^optionresponse/ && $beenHere{'o:'.$partId.':'.$currentResourceID} == 0) { @@ -434,6 +453,7 @@ sub ProcessTopResourceMap { $currentResourceID.':'. $partId.':'.$responseId; } + $allkeys{'OptionResponses'}++; } } } @@ -449,8 +469,10 @@ sub ProcessTopResourceMap { # Capture sequence information here $cache->{$currentSequence.':title'}= $hash{'title_'.$currentResourceID}; + $allkeys{$currentSequence.':title'}++; $cache->{$currentSequence.':source'}= $hash{'src_'.$currentResourceID}; + $allkeys{$currentSequence.':source'}++; my $totalProblems=0; foreach my $currentProblem (split(/\:/, @@ -474,6 +496,7 @@ sub ProcessTopResourceMap { $cache->{$currentSequence.':columnWidth'}= (scalar @titleLength); } + $allkeys{$currentSequence.':columnWidth'}++; } else { # Remove sequence from list, if it contains no problems to # display. @@ -510,6 +533,15 @@ sub ProcessTopResourceMap { $currentResourceID=pop(@currentResource); } + my @theKeys = keys(%allkeys); + my $newkeys = join(':::', @theKeys); + $cache->{'ResourceKeys'} = join(':::', $newkeys); + if($newkeys ne $oldkeys) { + $cache->{'ResourceUpdated'} = 'true'; + } else { + $cache->{'ResourceUpdated'} = 'false'; + } + unless (untie(%hash)) { &Apache::lonnet::logthis("WARNING: ". "Could not untie coursemap $fn (browse)". @@ -693,10 +725,13 @@ sub ProcessStudentData { return; } + # This little delete thing, should not be here. Move some other + # time though. if(defined($cache->{$name.':keys'})) { foreach (split(':::', $cache->{$name.':keys'})) { delete $cache->{$name.':'.$_}; } + delete $cache->{$name.':keys'}; } my %courseKeys; @@ -764,11 +799,14 @@ sub ExtractStudentData { return; } + # This little delete thing, should not be here. Move some other + # time though. my %allkeys; if(defined($output->{$name.':keys'})) { foreach (split(':::', $output->{$name.':keys'})) { delete $output->{$name.':'.$_}; } + delete $output->{$name.':keys'}; } my ($username,$domain)=split(':',$name); @@ -1160,17 +1198,19 @@ sub DownloadStudentCourseData { } my $downloadTime='Not downloaded'; + my $needUpdate = 'false'; if($checkDate eq 'true' && tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) { $downloadTime = $cache{$_.':lastDownloadTime'}; + $needUpdate = $cache{'ResourceUpdated'}; untie(%cache); } if($c->aborted()) { return 'Aborted'; } - #if($downloadTime ne 'Not downloaded') { - # next; - #} + if($needUpdate eq 'true') { + $downloadTime = 'Not downloaded'; + } my $courseData = &DownloadCourseInformation($_, $courseID, $downloadTime, $WhatIWant); @@ -1230,9 +1270,11 @@ sub DownloadStudentCourseDataSeparate { my %cache; my $downloadTime='Not downloaded'; + my $needUpdate = 'false'; if($checkDate eq 'true' && tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) { $downloadTime = $cache{$_.':lastDownloadTime'}; + $needUpdate = $cache{'ResourceUpdated'}; untie(%cache); } @@ -1240,31 +1282,33 @@ sub DownloadStudentCourseDataSeparate { return 'Aborted'; } - #if($downloadTime eq 'Not downloaded') { - my $error = 0; - my $courseData = - &DownloadCourseInformation($_, $courseID, $downloadTime, - $WhatIWant); - my %downloadData; - unless(tie(%downloadData,'GDBM_File',$residualFile, - &GDBM_WRCREAT(),0640)) { - return 'Failed to tie temporary download hash.'; - } - foreach my $key (keys(%$courseData)) { - $downloadData{$key} = $courseData->{$key}; - if($key =~ /^(con_lost|error|no_such_host)/i) { - $error = 1; - last; - } + if($needUpdate eq 'true') { + $downloadTime = 'Not downloaded'; + } + + my $error = 0; + my $courseData = + &DownloadCourseInformation($_, $courseID, $downloadTime, + $WhatIWant); + my %downloadData; + unless(tie(%downloadData,'GDBM_File',$residualFile, + &GDBM_WRCREAT(),0640)) { + return 'Failed to tie temporary download hash.'; + } + foreach my $key (keys(%$courseData)) { + $downloadData{$key} = $courseData->{$key}; + if($key =~ /^(con_lost|error|no_such_host)/i) { + $error = 1; + last; } - if($error) { - foreach my $deleteKey (keys(%$courseData)) { - delete $downloadData{$deleteKey}; - } - $downloadData{$_.':error'} = 'No course data for '.$_; + } + if($error) { + foreach my $deleteKey (keys(%$courseData)) { + delete $downloadData{$deleteKey}; } - untie(%downloadData); - #} + $downloadData{$_.':error'} = 'No course data for '.$_; + } + untie(%downloadData); } if($status eq 'true') { &Apache::lonhtmlcommon::Close_PrgWin($r); }