--- loncom/interface/lonnavmaps.pm 2006/10/23 22:48:27 1.392 +++ loncom/interface/lonnavmaps.pm 2006/12/20 23:02:33 1.393 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Navigate Maps Handler # -# $Id: lonnavmaps.pm,v 1.392 2006/10/23 22:48:27 albertel Exp $ +# $Id: lonnavmaps.pm,v 1.393 2006/12/20 23:02:33 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -2034,9 +2034,10 @@ sub last_post_time { return $self->{DISCUSSION_TIME}->{$ressymb}; } -sub unread_discussion { +sub discussion_info { my $self = shift; my $symb = shift; + my $filter = shift; $self->get_discussion_data(); @@ -2048,12 +2049,10 @@ sub unread_discussion { my $prevread = $self->{LAST_READ}{$ressymb}; - my $unreadcount = 0; + my $count = 0; my $hiddenflag = 0; my $deletedflag = 0; - my ($hidden,$deleted); - - my %subjects; + my ($hidden,$deleted,%info); for (my $id=$version; $id>0; $id--) { my $vkeys=$self->{DISCUSSION_DATA}{$id.':keys:'.$discsymb}; @@ -2069,18 +2068,24 @@ sub unread_discussion { $deletedflag = 1; } } else { - if (($hidden !~/\.$id\./) && ($deleted !~/\.$id\./) - && $prevread < $self->{DISCUSSION_DATA}{$id.':'.$discsymb.':timestamp'}) { - $unreadcount++; - $subjects{$unreadcount}= - $id.': '.$self->{DISCUSSION_DATA}{$id.':'.$discsymb.':subject'}; - } + if (($hidden !~/\.$id\./) && ($deleted !~/\.$id\./)) { + if ($filter eq 'unread') { + if ($prevread >= $self->{DISCUSSION_DATA}{$id.':'.$discsymb.':timestamp'}) { + next; + } + } + $count++; + $info{$count}{'subject'} = + $self->{DISCUSSION_DATA}{$id.':'.$discsymb.':subject'}; + $info{$count}{'id'} = $id; + $info{$count}{'timestamp'} = $self->{DISCUSSION_DATA}{$id.':'.$discsymb.':timestamp'}; + } } } if (wantarray) { - return ($unreadcount,\%subjects); + return ($count,%info); } - return $unreadcount + return $count; } sub wrap_symb { @@ -3835,13 +3840,15 @@ data was not extracted when the nav map Returns a false value if there hasn't been discussion otherwise returns unix timestamp of last time a discussion posting (or edit) was made. -=item * B: +=item * B: -returns in scalar context the count of the number of unread discussion -postings +optional argument is a filter (currently can be 'unread'); +returns in scalar context the count of the number of discussion postings. returns in list context both the count of postings and a hash ref -containing the subjects of all unread postings +containing information about the postings (subject, id, timestamp) in a hash. + +Default is to return counts for all postings. However if called with a second argument set to 'unread', will return information about only unread postings. =item * B: @@ -3868,9 +3875,9 @@ sub last_post_time { return $self->{NAV_MAP}->last_post_time($self->symb()); } -sub unread_discussion { - my $self = shift; - return $self->{NAV_MAP}->unread_discussion($self->symb()); +sub discussion_info { + my ($self,$filter) = @_; + return $self->{NAV_MAP}->discussion_info($self->symb(),$filter); } sub getFeedback {