--- loncom/interface/lonwhatsnew.pm 2005/12/06 16:37:28 1.36 +++ loncom/interface/lonwhatsnew.pm 2005/12/15 00:53:29 1.37 @@ -1,5 +1,5 @@ # -# $Id: lonwhatsnew.pm,v 1.36 2005/12/06 16:37:28 raeburn Exp $ +# $Id: lonwhatsnew.pm,v 1.37 2005/12/15 00:53:29 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -300,13 +300,14 @@ sub display_actions_box() { $timediff = time; } my $starttime = $now - $timediff; + my $countunread = 1; my %headings = &Apache::lonlocal::texthash( coursediscussion => 'Unread course discussion posts', handgrading => 'Problems requiring handgrading', haserrors => 'Problems with errors', versionchanges => 'Resources in course with version changes '.$interval, - coursenormalmail => 'New course message', + coursenormalmail => 'New course messages', coursecritmail => 'New critical messages in course', ); @@ -337,7 +338,7 @@ sub display_actions_box() { } if ($needitems) { - &getitems(\%unread,\%ungraded,\%bombed,\%triggered,\%changed,\@newdiscussions,\@tograde,\@bombs,\@warnings,$rowColor1,$rowColor2,\%threshold,$cdom,$crs,\%res_title,\%show,$starttime); + &getitems(\%unread,\%ungraded,\%bombed,\%triggered,\%changed,\@newdiscussions,\@tograde,\@bombs,\@warnings,$rowColor1,$rowColor2,\%threshold,$cdom,$crs,\%res_title,\%show,$starttime,$countunread); } if ($show{'coursenormalmail'}) { &getnormalmail(\@newmsgs); @@ -365,7 +366,7 @@ sub display_actions_box() { if ($displayed == $halfway) { $r->print(' '); } - &display_launcher($r,$actionitem,$checkallowed,$tabbg,$rowColor1,$rowColor2,\%show,\%headings,\%res_title,\@tograde,\%ungraded,\@bombs,\%bombed,\%changed,\@warnings,\%triggered,\@newdiscussions,\%unread,$msgcount,\@newmsgs,$critmsgcount,\@critmsgs,$interval); + &display_launcher($r,$actionitem,$checkallowed,$tabbg,$rowColor1,$rowColor2,\%show,\%headings,\%res_title,\@tograde,\%ungraded,\@bombs,\%bombed,\%changed,\@warnings,\%triggered,\@newdiscussions,\%unread,$msgcount,\@newmsgs,$critmsgcount,\@critmsgs,$interval,$countunread); $displayed ++; } } @@ -481,7 +482,7 @@ sub display_launcher { my ($r,$action,$checkallowed,$tabbg,$rowColor1,$rowColor2,$show, $headings,$res_title,$tograde,$ungraded,$bombs,$bombed,$changed, $warnings,$triggered,$newdiscussions,$unread,$msgcount,$newmsgs, - $critmsgcount,$critmsgs,$interval) = @_; + $critmsgcount,$critmsgs,$interval,$countunread) = @_; if ($$checkallowed{$action}) { &start_box($r,$tabbg,$show,$headings,$action); @@ -501,7 +502,7 @@ sub display_launcher { $rowColor1,$rowColor2); } elsif ($action eq 'coursediscussion') { # UNREAD COURSE DISCUSSION &display_coursediscussion($r,$newdiscussions,$unread, - $res_title,$rowColor1,$rowColor2); + $countunread,$res_title,$rowColor1,$rowColor2); } elsif ($action eq 'coursenormalmail') { # NORMAL MESSAGES &display_coursenormalmail($r,$msgcount,$newmsgs,$rowColor1, $rowColor2); @@ -518,19 +519,21 @@ sub display_launcher { sub getitems { my ($unread,$ungraded,$bombed,$triggered,$changed,$newdiscussions, $tograde,$bombs,$warnings,$rowColor1,$rowColor2,$threshold,$cdom,$crs, - $res_title,$show,$starttime) = @_; + $res_title,$show,$starttime,$countunread) = @_; my $navmap = Apache::lonnavmaps::navmap->new(); # 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 @allres=$navmap->retrieveResources(undef, + sub {if ($_[0]->is_problem) { $_[0]->parts();} return 1;}); my %lastreadtime; my %resourcetracker; + my $discussiontime; # Resource version changes if ($$show{'versionchanges'}) { &checkversions($cdom,$crs,$navmap,$changed,$starttime); } - if ($$show{'coursediscussions'}) { + if ($$show{'coursediscussion'}) { my %lastread = &Apache::lonnet::dump('nohist_'. $env{'request.course.id'}.'_discuss', $env{'user.domain'},$env{'user.name'},'lastread'); @@ -559,10 +562,10 @@ sub getitems { $$res_title{$symb} = $title; my $ressymb = $resource->wrap_symb(); -# Check for unread discussion postings +# Check if there are unread discussion postings if ($$show{'coursediscussion'}) { &check_discussions($cdom,$crs,$resource,$symb,$ressymb,$title, - $newdiscussions,$unread,\%lastreadtime); + $newdiscussions,$unread); } # Check for ungraded problems @@ -585,38 +588,82 @@ 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) { #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, - $lastreadtime) = @_; -# Check for unread discussion postings + my ($cdom,$crs,$resource,$symb,$ressymb,$title,$newdiscussions, + $unread) = @_; if ($resource->hasDiscussion()) { - my $prevread = 0; - my $unreadcount = 0; %{$$unread{$ressymb}} = (); $$unread{$ressymb}{'title'} = $title; $$unread{$ressymb}{'symb'} = $symb; - if (defined($$lastreadtime{$ressymb})) { - $prevread = $$lastreadtime{$ressymb}; + push(@{$newdiscussions}, $ressymb); + } +} + +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; + } + } + if (grep/^deleted$/,@keys) { + unless ($deletedflag) { + $deleted = $$discussiondata{$id.':'.$ressymb.':deleted'}; + $deletedflag = 1; + } + } + if ($deletedflag && $hiddenflag) { + last; + } } - my %contrib = &Apache::lonnet::restore($ressymb, - $env{'request.course.id'},$cdom,$crs); - if ($contrib{'version'}) { - for (my $id=1;$id<=$contrib{'version'};$id++) { - unless (($contrib{'hidden'}=~/\.$id\./) || - ($contrib{'deleted'}=~/\.$id\./)) { - if ($prevread <$contrib{$id.':timestamp'}) { - $$unread{$ressymb}{$unreadcount} = $id.': '.$contrib{$id.':subject'}; + for (my $id=$version; $id>0; $id--) { + unless (($hidden =~/\.$id\./) || ($deleted =~/\.$id\./)) { + if ($prevread <$$discussiondata{$id.':'.$ressymb.':timestamp'}) { + unless((exists($$discussiondata{$id.':'.$ressymb.':hidden'})) || + (exists($$discussiondata{$id.':'.$ressymb.':deleted'}))) { + $unreadcount ++; + $$unread{$ressymb}{$unreadcount} = $id.': '. + $$discussiondata{$id.':'.$ressymb.':subject'}; } } } } - if ($unreadcount) { push(@{$newdiscussions}, $ressymb); } + $$unread{$ressymb}{'unreadcount'} = $unreadcount; } } + sub check_handgraded { my ($resource,$symb,$title,$cdom,$cnum,$ungraded,$tograde) = @_; if ($resource->is_problem()) { @@ -1072,19 +1119,29 @@ sub display_versionchanges { } sub display_coursediscussion { - my ($r,$newdiscussions,$unread,$res_title,$rowColor1,$rowColor2) = @_; + my ($r,$newdiscussions,$unread,$countunread,$res_title,$rowColor1, + $rowColor2) = @_; my %lt = &Apache::lonlocal::texthash( 'loca' => 'Location', 'type' => 'Type', 'numn' => 'Number of new posts', 'noun' => 'No unread posts in course discussions', + 'tmlp' => 'Time of last post', ); my $rowColor; if (@{$newdiscussions} > 0) { $r->print(''.$lt{'loca'}. ''.$lt{'type'}. - ''.$lt{'numn'}. - ''); + ''); + if ($countunread) { + $r->print(''.$lt{'tmlp'}.''. + ''.$lt{'numn'}. + ''); + } else { + $r->print(''.$lt{'tmlp'}. + ''); + } + $r->print("\n"); @{$newdiscussions} = sort { &cmp_title($a,$b,$res_title) } @{$newdiscussions}; my $rowNum = 0; @@ -1095,17 +1152,23 @@ sub display_coursediscussion { if ($feedurl =~ /bulletinboard/) { $type = 'Bulletin Board'; } - my $unreadnum = keys(%{$$unread{$ressymb}}); - $unreadnum = $unreadnum - 2; - if ($unreadnum > 0) { - if ($rowNum %2 == 1) { - $rowColor = $rowColor1; - } else { - $rowColor = $rowColor2; - } - $r->print(''.$forum_title.' '.$type.''.$unreadnum.' '); - $rowNum ++; + if ($rowNum %2 == 1) { + $rowColor = $rowColor1; + } else { + $rowColor = $rowColor2; } + my $lastpost = &Apache::lonnavmaps::timeToHumanString( + $$unread{$ressymb}{'lastpost'}); + $r->print(''.$forum_title.' '.$type.' '); + if ($countunread) { + my $unreadnum = $$unread{$ressymb}{'unreadcount'}; + $r->print(''.$lastpost.''. + '',$unreadnum.' '); + } else { + $r->print(''.$lastpost.''); + } + $r->print("\n"); + $rowNum ++; } } else { $r->print('
 '.