--- loncom/lonnet/perl/lonnet.pm 2022/10/18 19:07:04 1.1495 +++ loncom/lonnet/perl/lonnet.pm 2022/10/19 00:03:11 1.1496 @@ -1,7 +1,7 @@ # The LearningOnline Network # TCP networking package # -# $Id: lonnet.pm,v 1.1495 2022/10/18 19:07:04 raeburn Exp $ +# $Id: lonnet.pm,v 1.1496 2022/10/19 00:03:11 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -12457,25 +12457,93 @@ sub domainlti_itemid { return $itemid; } -sub get_numsuppfiles { +sub count_supptools { + my ($cnum,$cdom,$ignorecache,$reload)=@_; + my $hashid=$cnum.':'.$cdom; + my ($numexttools,$cached); + unless ($ignorecache) { + ($numexttools,$cached) = &is_cached_new('supptools',$hashid); + } + unless (defined($cached)) { + my $chome=&homeserver($cnum,$cdom); + $numexttools = 0; + unless ($chome eq 'no_host') { + my ($supplemental) = &get_supplemental($cnum,$cdom,$reload); + if (ref($supplemental) eq 'HASH') { + if ((ref($supplemental->{'ids'}) eq 'HASH') && (ref($supplemental->{'hidden'}) eq 'HASH')) { + foreach my $key (keys(%{$supplemental->{'ids'}})) { + if ($key =~ m{^/adm/$cdom/$cnum/\d+/ext\.tool$}) { + $numexttools ++; + } + } + } + } + } + &do_cache_new('supptools',$hashid,$numexttools,600); + } + return $numexttools; +} + +sub has_unhidden_suppfiles { my ($cnum,$cdom,$ignorecache)=@_; my $hashid=$cnum.':'.$cdom; - my ($suppcount,$cached); + my ($showsupp,$cached); unless ($ignorecache) { - ($suppcount,$cached) = &is_cached_new('suppcount',$hashid); + ($showsupp,$cached) = &is_cached_new('showsupp',$hashid); } unless (defined($cached)) { my $chome=&homeserver($cnum,$cdom); unless ($chome eq 'no_host') { - ($suppcount,my $supptools,my $errors) = (0,0,0); - my $suppmap = 'supplemental.sequence'; - ($suppcount,$supptools,$errors) = - &Apache::loncommon::recurse_supplemental($cnum,$cdom,$suppmap,$suppcount, - $supptools,$errors); + my ($supplemental) = &get_supplemental($cnum,$cdom,$ignorecache); + if (ref($supplemental) eq 'HASH') { + if ((ref($supplemental->{'ids'}) eq 'HASH') && (ref($supplemental->{'hidden'}) eq 'HASH')) { + foreach my $key (keys(%{$supplemental->{'ids'}})) { + next if ($key =~ /\.sequence$/); + if (ref($supplemental->{'ids'}->{$key}) eq 'ARRAY') { + foreach my $id (@{$supplemental->{'ids'}->{$key}}) { + unless ($supplemental->{'hidden'}->{$id}) { + $showsupp = 1; + last; + } + } + } + last if ($showsupp); + } + } + } } - &do_cache_new('suppcount',$hashid,$suppcount,600); + &do_cache_new('showsupp',$hashid,$showsupp,600); } - return $suppcount; + return $showsupp; +} + +sub get_supplemental { + my ($cnum,$cdom,$ignorecache,$possdel)=@_; + my $hashid=$cnum.':'.$cdom; + my ($supplemental,$cached,$set_httprefs); + unless ($ignorecache) { + ($supplemental,$cached) = &is_cached_new('supplemental',$hashid); + } + unless (defined($cached)) { + my $chome=&homeserver($cnum,$cdom); + unless ($chome eq 'no_host') { + my ($errors,%ids,%hidden); + $errors = + &Apache::loncommon::recurse_supplemental($cnum,$cdom, + 'supplemental.sequence', + $errors,$possdel,\%ids,\%hidden); + $set_httprefs = 1; + if ($env{'request.course.id'} eq $cdom.'_'.$cnum) { + &Apache::lonnet::appenv({'request.course.suppupdated' => time}); + } + $supplemental = { + ids => \%ids, + hidden => \%hidden, + }; + &do_cache_new('supplemental',$hashid,$supplemental,600); + } + } + return ($supplemental,$set_httprefs); } # @@ -13603,11 +13671,45 @@ sub get_coursechange { } sub devalidate_coursechange_cache { - my ($cnum,$cdom)=@_; - my $hashid=$cnum.':'.$cdom; + my ($cdom,$cnum)=@_; + my $hashid=$cdom.'_'.$cnum; &devalidate_cache_new('crschange',$hashid); } +sub get_suppchange { + my ($cdom,$cnum) = @_; + if ($cdom eq '' || $cnum eq '') { + return unless ($env{'request.course.id'}); + $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; + $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; + } + my $hashid=$cdom.'_'.$cnum; + my ($change,$cached)=&is_cached_new('suppchange',$hashid); + if ((defined($cached)) && ($change ne '')) { + return $change; + } else { + my %crshash = &get('environment',['internal.supplementalchange'],$cdom,$cnum); + if ($crshash{'internal.supplementalchange'} eq '') { + $change = $env{'course.'.$cdom.'_'.$cnum.'.internal.created'}; + if ($change eq '') { + %crshash = &get('environment',['internal.created'],$cdom,$cnum); + $change = $crshash{'internal.created'}; + } + } else { + $change = $crshash{'internal.supplementalchange'}; + } + my $cachetime = 600; + &do_cache_new('suppchange',$hashid,$change,$cachetime); + } + return $change; +} + +sub devalidate_suppchange_cache { + my ($cdom,$cnum)=@_; + my $hashid=$cdom.'_'.$cnum; + &devalidate_cache_new('suppchange',$hashid); +} + # ------------------------------------------------- Update symbolic store links sub symblist { @@ -16464,10 +16566,6 @@ data base, returning a hash that is keye values that are the resource value. I believe that the timestamps and versions are also returned. -get_numsuppfiles($cnum,$cdom) : retrieve number of files in a course's -supplemental content area. This routine caches the number of files for -10 minutes. - =back =head2 Course Modification