--- loncom/interface/lonwhatsnew.pm 2006/01/13 01:18:44 1.50 +++ loncom/interface/lonwhatsnew.pm 2006/03/04 05:59:01 1.51 @@ -1,5 +1,5 @@ # -# $Id: lonwhatsnew.pm,v 1.50 2006/01/13 01:18:44 raeburn Exp $ +# $Id: lonwhatsnew.pm,v 1.51 2006/03/04 05:59:01 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -712,7 +712,6 @@ sub getitems { # force retrieve Resource to seed the part id cache we'll need it later my @allres=$navmap->retrieveResources(undef, sub {if ($_[0]->is_problem) { $_[0]->parts();} return 1;}); - my %lastreadtime; my %resourcetracker; my $discussiontime; @@ -721,17 +720,6 @@ sub getitems { &checkversions($cdom,$crs,$navmap,$changed,$starttime); } - if ($$show{'coursediscussion'}) { - my %lastread = &Apache::lonnet::dump('nohist_'. - $env{'request.course.id'}.'_discuss', - $env{'user.domain'},$env{'user.name'},'lastread'); - foreach my $key (keys(%lastread)) { - my $newkey = $key; - $newkey =~ s/_lastread$//; - $lastreadtime{$newkey} = $lastread{$key}; - } - } - if ($$show{'abovethreshold'}) { %resourcetracker = &Apache::lonnet::dump('nohist_resourcetracker', $cdom,$crs); @@ -752,8 +740,8 @@ sub getitems { # Check if there are unread discussion postings if ($$show{'coursediscussion'}) { - &check_discussions($cdom,$crs,$resource,$symb,$ressymb,$title, - $newdiscussions,$unread); + &check_discussions($resource,$symb,$ressymb,$title, + $newdiscussions,$unread,$countunread); } # Check for ungraded problems @@ -776,73 +764,26 @@ sub getitems { } } - my $hasdiscussion = @{$newdiscussions}; - if ($$show{'coursediscussion'} && $hasdiscussion) { # Get time of last post; - $discussiontime = $navmap->{DISCUSSION_TIME}; - foreach my $ressymb (@{$newdiscussions}) { - $$unread{$ressymb}{'lastpost'} = $$discussiontime{$ressymb}; - } - if ($countunread eq 'on') { #Get count of unread postings for each resource - my $discussiondata = $navmap->get_discussion_data(); - foreach my $ressymb (@{$newdiscussions}) { - &get_discussions($cdom,$crs,$discussiondata,$ressymb, - $unread,\%lastreadtime); - } - } - } } sub check_discussions { - my ($cdom,$crs,$resource,$symb,$ressymb,$title,$newdiscussions, - $unread) = @_; - if ($resource->hasDiscussion()) { - %{$$unread{$ressymb}} = (); - $$unread{$ressymb}{'title'} = $title; - $$unread{$ressymb}{'symb'} = $symb; - push(@{$newdiscussions}, $ressymb); - } -} + my ($resource,$symb,$ressymb,$title,$newdiscussions,$unread, + $countunread) = @_; -sub get_discussions { - my ($cdom,$crs,$discussiondata,$ressymb,$unread,$lastreadtime) = @_; - my $prevread = 0; - my $unreadcount = 0; - if (defined($$lastreadtime{$ressymb})) { - $prevread = $$lastreadtime{$ressymb}; - } - my $version = $$discussiondata{'version:'.$ressymb}; - if ($version) { - my $hiddenflag = 0; - my $deletedflag = 0; - my ($hidden,$deleted); - for (my $id=$version; $id>0; $id--) { - my $vkeys=$$discussiondata{$id.':keys:'.$ressymb}; - my @keys=split(/:/,$vkeys); - if (grep/^hidden$/,@keys) { - unless ($hiddenflag) { - $hidden = $$discussiondata{$id.':'.$ressymb.':hidden'}; - $hiddenflag = 1; - } - } elsif (grep/^deleted$/,@keys) { - unless ($deletedflag) { - $deleted = $$discussiondata{$id.':'.$ressymb.':deleted'}; - $deletedflag = 1; - } - } else { - unless (($hidden =~/\.$id\./) || ($deleted =~/\.$id\./)) { - if ($prevread <$$discussiondata{$id.':'.$ressymb.':timestamp'}) { - $unreadcount ++; - $$unread{$ressymb}{$unreadcount} = $id.': '. - $$discussiondata{$id.':'.$ressymb.':subject'}; - } - } - } - } - $$unread{$ressymb}{'unreadcount'} = $unreadcount; + if (!$resource->hasDiscussion()) { return; } + + %{$$unread{$ressymb}} = (); + $$unread{$ressymb}{'title'} = $title; + $$unread{$ressymb}{'symb'} = $symb; + push(@{$newdiscussions}, $ressymb); + + $$unread{$ressymb}{'lastpost'} = $resource->last_post_time(); + + if ($countunread eq 'on') { + $$unread{$ressymb}{'unreadcount'} = $resource->unread_discussion(); } } - sub check_handgraded { my ($resource,$symb,$title,$cdom,$cnum,$ungraded,$tograde) = @_; if ($resource->is_problem()) {