[Cpan-forum-commit] rev 142 - in branches/db_changes/lib/CPAN: . Forum

svn at pti.co.il svn at pti.co.il
Thu Mar 24 09:44:50 IST 2005


Author: gabor
Date: 2005-03-24 09:44:49 +0200 (Thu, 24 Mar 2005)
New Revision: 142

Added:
   branches/db_changes/lib/CPAN/Forum/Subscriptions_all.pm
Modified:
   branches/db_changes/lib/CPAN/Forum.pm
   branches/db_changes/lib/CPAN/Forum/INC.pm
Log:
enable user to subscribe to all discussions

Modified: branches/db_changes/lib/CPAN/Forum/INC.pm
===================================================================
--- branches/db_changes/lib/CPAN/Forum/INC.pm	2005-03-24 06:57:41 UTC (rev 141)
+++ branches/db_changes/lib/CPAN/Forum/INC.pm	2005-03-24 07:44:49 UTC (rev 142)
@@ -10,6 +10,9 @@
 use CPAN::Forum::Groups;
 use CPAN::Forum::Posts;
 
+use CPAN::Forum::Subscriptions;
+use CPAN::Forum::Subscriptions_all;
 
+
 1;
 

Added: branches/db_changes/lib/CPAN/Forum/Subscriptions_all.pm
===================================================================
--- branches/db_changes/lib/CPAN/Forum/Subscriptions_all.pm	2005-03-24 06:57:41 UTC (rev 141)
+++ branches/db_changes/lib/CPAN/Forum/Subscriptions_all.pm	2005-03-24 07:44:49 UTC (rev 142)
@@ -0,0 +1,10 @@
+package CPAN::Forum::Subscriptions_all;
+use strict;
+use warnings;
+use Carp;
+use base 'CPAN::Forum::DBI';
+__PACKAGE__->table('subscriptions_all');
+__PACKAGE__->columns(All => qw/id uid allposts starters followups announcements/);
+__PACKAGE__->has_a(uid => "CPAN::Forum::Users");
+
+1;

Modified: branches/db_changes/lib/CPAN/Forum.pm
===================================================================
--- branches/db_changes/lib/CPAN/Forum.pm	2005-03-24 06:57:41 UTC (rev 141)
+++ branches/db_changes/lib/CPAN/Forum.pm	2005-03-24 07:44:49 UTC (rev 142)
@@ -1815,6 +1815,17 @@
 			};
 		}
 	} else { # show all subscriptions
+		my ($s) = CPAN::Forum::Subscriptions_all->search(uid => $user->id);
+		$self->log->debug("all subscriptions " . ($s ? "found" : "not found"));
+		push @subscriptions, {
+			gid       => "_all",
+			group     => "All",
+			allposts  => $s ? $s->allposts  : '',
+			starters  => $s ? $s->starters  : '',
+			followups => $s ? $s->followups : '',
+		};
+		$gids = "_all";
+
 		my $it = CPAN::Forum::Subscriptions->search(uid => $user->id);
 		while (my $s = $it->next) {
 			#warn $s->allposts;
@@ -1825,7 +1836,7 @@
 				allposts  => $s->allposts,
 				starters  => $s->starters,
 				followups => $s->followups,
-			}
+			};
 		}
 	}
 	#warn Dumper \@subscriptions;
@@ -1852,30 +1863,47 @@
 
 	#warn Dumper $q->Vars;
 	foreach my $gid (@gids) {
-		my ($s) = CPAN::Forum::Subscriptions->search(gid => $gid, uid => $user->id);
-		if (not $s) {
-			$s = CPAN::Forum::Subscriptions->create({
-				uid       => $user->id,
-				gid       => $gid,
-			});
-		}
-		my $on=0;
-		foreach my $type (qw(allposts starters followups)) {
-			if (defined $q->param($type ."_$gid") and $q->param($type . "_$gid") eq "on") {
-				$s->set($type, 1);
-				$on++;
-			} else {
-				$s->set($type, 0);
+		if ($gid eq "_all") {
+			my ($s) = CPAN::Forum::Subscriptions_all->search(uid => $user->id);
+			if (not $s) {
+				$s = CPAN::Forum::Subscriptions_all->create({
+					uid       => $user->id,
+				});
 			}
+			$self->_update_subs($s, $gid);
+		} else {
+			my ($s) = CPAN::Forum::Subscriptions->search(gid => $gid, uid => $user->id);
+			if (not $s) {
+				$s = CPAN::Forum::Subscriptions->create({
+					uid       => $user->id,
+					gid       => $gid,
+				});
+			}
+			$self->_update_subs($s, $gid);
 		}
-		$s->update;
-		$s->delete if not $on;  # remove the whole line if there are no subscriptions at all.
 	}
+ 	$self->notes("mypanok");
+}
 
 
- 	$self->notes("mypanok");
+sub _update_subs {
+	my ($self, $s, $gid) = @_;
+	my $q = $self->query;
+
+	my $on=0;
+	foreach my $type (qw(allposts starters followups)) {
+		if (defined $q->param($type ."_$gid") and $q->param($type . "_$gid") eq "on") {
+			$s->set($type, 1);
+			$on++;
+		} else {
+			$s->set($type, 0);
+		}
+	}
+	$s->update;
+	$s->delete if not $on;  # remove the whole line if there are no subscriptions at all.
 }
 
+
 sub notes {
 	my ($self, $msg) = @_;
 	my $t = $self->load_tmpl("notes.tmpl");



More information about the Cpan-forum-commit mailing list