[Cpan-forum-commit] rev 309 - in trunk: . lib/CPAN/Forum/DB lib/CPAN/Forum/RM

svn at pti.co.il svn at pti.co.il
Wed Jul 25 17:48:47 EEST 2007


Author: gabor
Date: 2007-07-25 17:48:47 +0300 (Wed, 25 Jul 2007)
New Revision: 309

Modified:
   trunk/
   trunk/lib/CPAN/Forum/DB/Subscriptions_pauseid.pm
   trunk/lib/CPAN/Forum/RM/Subscriptions.pm
Log:
add find method to DB::Subscriptions_pauseid



Property changes on: trunk
___________________________________________________________________
Name: svk:merge
   - 7bc34947-122d-0410-bc5a-f898d2bb5f81:/local/cpan-forum:4329
8c4c90e1-83eb-0310-96eb-e7cb62807872:/local/cpan-forum:12752
   + 7bc34947-122d-0410-bc5a-f898d2bb5f81:/local/cpan-forum:4330
8c4c90e1-83eb-0310-96eb-e7cb62807872:/local/cpan-forum:12752

Modified: trunk/lib/CPAN/Forum/DB/Subscriptions_pauseid.pm
===================================================================
--- trunk/lib/CPAN/Forum/DB/Subscriptions_pauseid.pm	2007-07-25 14:48:18 UTC (rev 308)
+++ trunk/lib/CPAN/Forum/DB/Subscriptions_pauseid.pm	2007-07-25 14:48:47 UTC (rev 309)
@@ -8,4 +8,33 @@
 __PACKAGE__->has_a(uid     => "CPAN::Forum::DB::Users");
 __PACKAGE__->has_a(pauseid => "CPAN::Forum::DB::Authors");
 
+sub find {
+    my ($self, %args) = @_;
+    my ($sql, @args) = $self->_find(%args);
+    return $self->_fetch_arrayref_of_hashes($sql, @args);
+}
+
+sub find_one {
+    my ($self, %args) = @_;
+
+    my ($sql, @args) = $self->_find(%args);
+
+    return $self->_fetch_single_hashref($sql, @args); 
+}
+
+sub _find {
+    my ($self, %args) = @_;
+
+    # check if keys of args is uid 
+    my @fields = keys %args;
+    my $where = join " AND ", map {"$_=?"} @fields;
+    my $sql = "SELECT subscriptions_pauseid.id, uid, allposts, starters, followups, announcements,
+        authors.pauseid pauseid_name FROM subscriptions_pauseid, authors WHERE authors.id=subscriptions_pauseid.pauseid";
+    if ($where) {
+        $sql .= " AND $where";
+    }
+    return ($sql, @args{@fields}); 
+}
+
+
 1;

Modified: trunk/lib/CPAN/Forum/RM/Subscriptions.pm
===================================================================
--- trunk/lib/CPAN/Forum/RM/Subscriptions.pm	2007-07-25 14:48:18 UTC (rev 308)
+++ trunk/lib/CPAN/Forum/RM/Subscriptions.pm	2007-07-25 14:48:47 UTC (rev 309)
@@ -81,19 +81,19 @@
     };
     my $gids = "_all";
 
-    my $it = CPAN::Forum::DB::Subscriptions_pauseid->search(uid => $user->{id});
-    while (my $s = $it->next) {
-        $gids .= ($gids ? ",_" : "_") . $s->pauseid->id; 
+    my $it = CPAN::Forum::DB::Subscriptions_pauseid->find(uid => $user->{id}); # SQL
+    foreach my $s (@$it) {
+        $gids .= ($gids ? ",_" : "_") . $s->{pauseid}; 
         push @subscriptions, {
-            gid       => "_" . $s->pauseid->id,
-            group     => $s->pauseid->pauseid,
-            allposts  => $s->allposts,
-            starters  => $s->starters,
-            followups => $s->followups,
+            gid       => "_" . $s->{pauseid},
+            group     => $s->{pauseid_name},
+            allposts  => $s->{allposts},
+            starters  => $s->{starters},
+            followups => $s->{followups},
         };
     }
 
-    $it = CPAN::Forum::DB::Subscriptions->find(uid => $user->{id});
+    $it = CPAN::Forum::DB::Subscriptions->find(uid => $user->{id}); # SQL
     foreach my $s (@$it) {
         $gids .= ($gids ? "," : "") . $s->{gid};
         push @subscriptions, {



More information about the Cpan-forum-commit mailing list