[Cpan-forum-commit] rev 308 - 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:18 EEST 2007
Author: gabor
Date: 2007-07-25 17:48:18 +0300 (Wed, 25 Jul 2007)
New Revision: 308
Modified:
trunk/
trunk/lib/CPAN/Forum/DB/Subscriptions.pm
trunk/lib/CPAN/Forum/RM/Subscriptions.pm
Log:
add find method to DB::Subscription
move another db call in RM::Subscription to use plain SQL
Property changes on: trunk
___________________________________________________________________
Name: svk:merge
- 7bc34947-122d-0410-bc5a-f898d2bb5f81:/local/cpan-forum:4328
8c4c90e1-83eb-0310-96eb-e7cb62807872:/local/cpan-forum:12752
+ 7bc34947-122d-0410-bc5a-f898d2bb5f81:/local/cpan-forum:4329
8c4c90e1-83eb-0310-96eb-e7cb62807872:/local/cpan-forum:12752
Modified: trunk/lib/CPAN/Forum/DB/Subscriptions.pm
===================================================================
--- trunk/lib/CPAN/Forum/DB/Subscriptions.pm 2007-07-25 14:47:47 UTC (rev 307)
+++ trunk/lib/CPAN/Forum/DB/Subscriptions.pm 2007-07-25 14:48:18 UTC (rev 308)
@@ -9,18 +9,32 @@
__PACKAGE__->has_a(gid => "CPAN::Forum::DB::Groups");
+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 either uid or gid
my @fields = keys %args;
my $where = join " AND ", map {"$_=?"} @fields;
- my $sql = "SELECT id, gid, uid, allposts, starters, followups, announcements FROM subscriptions";
+ my $sql = "SELECT subscriptions.id, gid, uid, allposts, starters, followups, announcements,
+ groups.name group_name FROM subscriptions, groups WHERE groups.id=subscriptions.gid";
if ($where) {
- $sql .= " WHERE $where";
+ $sql .= " AND $where";
}
-
- $self->_fetch_single_hashref($sql, @args{@fields});
-
+ return ($sql, @args{@fields});
}
1;
Modified: trunk/lib/CPAN/Forum/RM/Subscriptions.pm
===================================================================
--- trunk/lib/CPAN/Forum/RM/Subscriptions.pm 2007-07-25 14:47:47 UTC (rev 307)
+++ trunk/lib/CPAN/Forum/RM/Subscriptions.pm 2007-07-25 14:48:18 UTC (rev 308)
@@ -93,15 +93,15 @@
};
}
- $it = CPAN::Forum::DB::Subscriptions->search(uid => $user->{id});
- while (my $s = $it->next) {
- $gids .= ($gids ? "," : "") . $s->gid->id;
+ $it = CPAN::Forum::DB::Subscriptions->find(uid => $user->{id});
+ foreach my $s (@$it) {
+ $gids .= ($gids ? "," : "") . $s->{gid};
push @subscriptions, {
- gid => $s->gid,
- group => $s->gid->name,
- allposts => $s->allposts,
- starters => $s->starters,
- followups => $s->followups,
+ gid => $s->{gid},
+ group => $s->{group_name},
+ allposts => $s->{allposts},
+ starters => $s->{starters},
+ followups => $s->{followups},
};
}
return ($gids, \@subscriptions);
More information about the Cpan-forum-commit
mailing list