[Cpan-forum-commit] rev 90 - in trunk: lib/CPAN lib/CPAN/Forum
templates
svn at pti.co.il
svn at pti.co.il
Sun Feb 6 10:48:08 IST 2005
Author: gabor
Date: 2005-02-06 10:48:07 +0200 (Sun, 06 Feb 2005)
New Revision: 90
Modified:
trunk/lib/CPAN/Forum.pm
trunk/lib/CPAN/Forum/Posts.pm
trunk/templates/listing.tmpl
Log:
make paging work on the main page, probably breaking all other listsings
Modified: trunk/lib/CPAN/Forum/Posts.pm
===================================================================
--- trunk/lib/CPAN/Forum/Posts.pm 2005-02-06 07:16:01 UTC (rev 89)
+++ trunk/lib/CPAN/Forum/Posts.pm 2005-02-06 08:48:07 UTC (rev 90)
@@ -24,15 +24,22 @@
}
sub mysearch {
- my ($self, $params, $page, $per_page) = @_;
+ my ($self, $params, $page, $per_page, $order_by) = @_;
my %where;
+ if (not %where) {
+ $where{1} = 1;
+ }
+ $order_by ||= "id";
+
+ $order_by .= " desc";
+
my $pager = __PACKAGE__->pager(
where => \%where,
per_page => $per_page || 10,
page => $page || 1,
-# order_by => $order_by,
+ order_by => $order_by,
);
}
Modified: trunk/lib/CPAN/Forum.pm
===================================================================
--- trunk/lib/CPAN/Forum.pm 2005-02-06 07:16:01 UTC (rev 89)
+++ trunk/lib/CPAN/Forum.pm 2005-02-06 08:48:07 UTC (rev 90)
@@ -728,19 +728,38 @@
=cut
sub home {
my $self = shift;
+ my $q = $self->query;
my $t = $self->load_tmpl("home.tmpl",
loop_context_vars => 1,
);
- my $from = ${$self->param("path_parameters")}[1] || 0;
- my $cnt = ${$self->param("path_parameters")}[2] || $limit;
- $t->param(messages => $self->build_listing(
- scalar CPAN::Forum::Posts->retrieve_latest($from+$cnt),
- CPAN::Forum::Posts->count_all(),
- ));
- #CPAN::Forum::Posts->mysearch({},1 $limit);
+ #my $from = ${$self->param("path_parameters")}[1] || 0;
+ #my $cnt = ${$self->param("path_parameters")}[2] || $limit;
+ #my @results = CPAN::Forum::Posts->retrieve_latest($from+$cnt);
+ #$t->param(messages => $self->build_listing(
+ # \@results,
+ # CPAN::Forum::Posts->count_all(),
+ # ));
+ #
+ my $page = $q->param('page') || 1;
+ my $pager = CPAN::Forum::Posts->mysearch({}, $page, $limit);
+ my @results = $pager->search_where();
+ my $total = $pager->total_entries;
+ $self->log->debug("number of entries: total=$total");
+ #$self->session->param('per_page' => $per_page);
+ #$self->session->param('current_page' => $pager->current_page);
+ my $data = $self->new_build_listing(\@results);
+ $t->param(messages => $data);
+ $t->param(total => $total);
+ $t->param(previous_page => $pager->previous_page);
+ $t->param(next_page => $pager->next_page);
+ $t->param(first_entry => $pager->first);
+ $t->param(last_entry => $pager->last);
+ $t->param(first_page => 1) if $pager->current_page != 1;
+ $t->param(last_page => $pager->last_page) if $pager->current_page != $pager->last_page;
+
$t->output;
}
@@ -765,9 +784,9 @@
my $to = $from+$cnt-1;
my @resp;
- if ($to) {
- $it = $it->slice($from, $to);
- }
+ #if ($to) {
+ # $it = $it->slice($from, $to);
+ #}
#my $start = $from % $cnt;
@@ -778,7 +797,7 @@
my ($self, $it) = @_;
my @resp;
- while (my $post = $it->next) {
+ foreach my $post (@$it) {
my $thread_count = CPAN::Forum::Posts->sql_count_thread($post->thread)->select_val;
push @resp, {
subject => _subject_escape($post->subject),
@@ -825,6 +844,12 @@
$t->param(users_cnt => CPAN::Forum::Users->count_all());
$t->param(subscription_cnt => CPAN::Forum::Subscriptions->count_all());
$t->param(version => $VERSION);
+ # number of posts per group name, can create some xml feed from it that can
+ # be used by search.cpan.org and Kobes to add a number of posts next to the link
+ #select count(*),groups.name from posts, groups where groups.id=gid group by gid;
+ #
+ #count posts for a specific group:
+ #select count(*) from posts, groups where groups.id=gid and groups.name="CPAN-Forum";
$t->output;
}
@@ -2109,6 +2134,7 @@
$_[0]->load_tmpl("help.tmpl")->output;
}
+
1;
=head1 ACKNOWLEDGEMENTS
Modified: trunk/templates/listing.tmpl
===================================================================
--- trunk/templates/listing.tmpl 2005-02-06 07:16:01 UTC (rev 89)
+++ trunk/templates/listing.tmpl 2005-02-06 08:48:07 UTC (rev 90)
@@ -17,4 +17,10 @@
</tr>
</TMPL_LOOP>
</table>
+<TMPL_IF first_page> <a href="?page=<TMPL_VAR first_page>">first page</a> | </TMPL_IF>
+<TMPL_IF previous_page><a href="?page=<TMPL_VAR previous_page>">previous page</a> | </TMPL_IF>
+<TMPL_VAR first_entry> - <TMPL_VAR last_entry> messages in a total of <TMPL_VAR total>
+<TMPL_IF next_page> | <a href="?page=<TMPL_VAR next_page>">next page</a></TMPL_IF>
+<TMPL_IF last_page> | <a href="?page=<TMPL_VAR last_page>">last page</a></TMPL_IF>
+
</TMPL_IF>
More information about the Cpan-forum-commit
mailing list