[LON-CAPA-cvs] cvs: loncom /interface lonnavmaps.pm lonwhatsnew.pm

raeburn lon-capa-cvs@mail.lon-capa.org
Wed, 20 Dec 2006 23:02:36 -0000


raeburn		Wed Dec 20 18:02:36 2006 EDT

  Modified files:              
    /loncom/interface	lonnavmaps.pm lonwhatsnew.pm 
  Log:
  Renaming unread_discussion() as discussion_info() and making the funtion more universally useful.  Can now be used to retrieve counts for all postings, or just unread postings (if 'unread') is included as an argumnet in the call (e.g., $resource->discussion_info('unread');).  Also if
  called in array context, returns ($count,%info), where %info is a hash of a hash.  Outer hash keys are count number, inner hash keys are: subject, id, timestamp.
  
  
Index: loncom/interface/lonnavmaps.pm
diff -u loncom/interface/lonnavmaps.pm:1.392 loncom/interface/lonnavmaps.pm:1.393
--- loncom/interface/lonnavmaps.pm:1.392	Mon Oct 23 18:48:27 2006
+++ loncom/interface/lonnavmaps.pm	Wed Dec 20 18:02:33 2006
@@ -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 @@
     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 @@
 
     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 @@
 		$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 @@
 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<unread_discussion>:
+=item * B<discussion_info>:
 
-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<getFeedback>:
 
@@ -3868,9 +3875,9 @@
     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 {
Index: loncom/interface/lonwhatsnew.pm
diff -u loncom/interface/lonwhatsnew.pm:1.66 loncom/interface/lonwhatsnew.pm:1.67
--- loncom/interface/lonwhatsnew.pm:1.66	Sun Dec  3 00:45:13 2006
+++ loncom/interface/lonwhatsnew.pm	Wed Dec 20 18:02:33 2006
@@ -1,5 +1,5 @@
 #
-# $Id: lonwhatsnew.pm,v 1.66 2006/12/03 05:45:13 raeburn Exp $
+# $Id: lonwhatsnew.pm,v 1.67 2006/12/20 23:02:33 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -794,7 +794,8 @@
     $$unread{$ressymb}{'lastpost'} = $resource->last_post_time();
     
     if ($countunread eq 'on') {
-	$$unread{$ressymb}{'unreadcount'} = $resource->unread_discussion();
+	$$unread{$ressymb}{'unreadcount'} = 
+                            $resource->discussion_info('unread');
     }
 }