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

albertel lon-capa-cvs@mail.lon-capa.org
Sat, 04 Mar 2006 05:55:44 -0000


albertel		Sat Mar  4 00:55:44 2006 EDT

  Modified files:              
    /loncom/interface	lonnavmaps.pm 
  Log:
  - migrating some functinality from what'snew collectors into navmaps 
  
  
Index: loncom/interface/lonnavmaps.pm
diff -u loncom/interface/lonnavmaps.pm:1.365 loncom/interface/lonnavmaps.pm:1.366
--- loncom/interface/lonnavmaps.pm:1.365	Thu Mar  2 14:45:22 2006
+++ loncom/interface/lonnavmaps.pm	Sat Mar  4 00:55:43 2006
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Navigate Maps Handler
 #
-# $Id: lonnavmaps.pm,v 1.365 2006/03/02 19:45:22 albertel Exp $
+# $Id: lonnavmaps.pm,v 1.366 2006/03/04 05:55:43 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -2271,16 +2271,18 @@
 sub get_discussion_data {
     my $self = shift;
     if ($self->{RETRIEVED_DISCUSSION_DATA}) {
-         return  $self->{DISCUSSION_DATA};
+	return $self->{DISCUSSION_DATA};
     }
-                                                                                
+
+    $self->generate_email_discuss_status();    
+
     my $cid=$env{'request.course.id'};
     my $cdom=$env{'course.'.$cid.'.domain'};
     my $cnum=$env{'course.'.$cid.'.num'};
-                                                                                
     # Retrieve discussion data for resources in course
     my %discussion_data = &Apache::lonnet::dump($cid,$cdom,$cnum);
-                                                                                
+
+
     $self->{DISCUSSION_DATA} = \%discussion_data;
     $self->{RETRIEVED_DISCUSSION_DATA} = 1;
     return $self->{DISCUSSION_DATA};
@@ -2342,6 +2344,61 @@
     }
 }
 
+sub last_post_time {
+    my $self = shift;
+    my $symb = shift;
+    my $ressymb = $self->wrap_symb($symb);
+    return $self->{DISCUSSION_TIME}->{$ressymb};
+}
+
+sub unread_discussion {
+    my $self = shift;
+    my $symb = shift;
+
+    $self->get_discussion_data();
+    
+    my $ressymb = $self->wrap_symb($symb);
+
+    my $version = $self->{DISCUSSION_DATA}{'version:'.$ressymb};
+    if (!$version) { return; }
+
+    my $prevread = $self->{LAST_READ}{$ressymb};
+
+    my $unreadcount = 0;
+    my $hiddenflag = 0;
+    my $deletedflag = 0;
+    my ($hidden,$deleted);
+
+    my %subjects;
+
+    for (my $id=$version; $id>0; $id--) {
+	my $vkeys=$self->{DISCUSSION_DATA}{$id.':keys:'.$ressymb};
+	my @keys=split(/:/,$vkeys);
+	if (grep(/^hidden$/ ,@keys)) {
+	    if (!$hiddenflag) {
+		$hidden = $self->{DISCUSSION_DATA}{$id.':'.$ressymb.':hidden'};
+		$hiddenflag = 1;
+	    }
+	} elsif (grep(/^deleted$/,@keys)) {
+	    if (!$deletedflag) {
+		$deleted = $self->{DISCUSSION_DATA}{$id.':'.$ressymb.':deleted'};
+		$deletedflag = 1;
+	    }
+	} else {
+	    if (($hidden !~/\.$id\./) && ($deleted !~/\.$id\./)
+		&& $prevread < $self->{DISCUSSION_DATA}{$id.':'.$ressymb.':timestamp'}) {
+		    $unreadcount++;
+		    $subjects{$unreadcount}=
+			$id.': '.$self->{DISCUSSION_DATA}{$id.':'.$ressymb.':subject'};
+		}
+	}
+    }
+    if (wantarray) {
+	return ($unreadcount,\%subjects);
+    }
+    return $unreadcount
+}
+
 sub wrap_symb {
     my $self = shift;
     my $symb = shift;
@@ -4061,6 +4118,19 @@
 logged in, true if there has. Always returns false if the discussion
 data was not extracted when the nav map was constructed.
 
+=item * B<last_post_time>:
+
+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>:
+
+returns in scalar context the count of the number of unread discussion
+postings
+
+returns in list context both the count of postings and a hash ref
+containing the subjects of all unread postings
+
 =item * B<getFeedback>:
 
 Gets the feedback for the resource and returns the raw feedback string
@@ -4081,6 +4151,16 @@
     return $self->{NAV_MAP}->hasDiscussion($self->symb());
 }
 
+sub last_post_time {
+    my $self = shift;
+    return $self->{NAV_MAP}->last_post_time($self->symb());
+}
+
+sub unread_discussion {
+    my $self = shift;
+    return $self->{NAV_MAP}->unread_discussion($self->symb());
+}
+
 sub getFeedback {
     my $self = shift;
     my $source = $self->src();