[Rt-commit] r4055 - in Jifty-DBI/trunk: . lib/Jifty/DBI
jesse at bestpractical.com
jesse at bestpractical.com
Tue Nov 8 16:14:41 EST 2005
Author: jesse
Date: Tue Nov 8 16:14:41 2005
New Revision: 4055
Modified:
Jifty-DBI/trunk/ (props changed)
Jifty-DBI/trunk/Makefile.PL
Jifty-DBI/trunk/lib/Jifty/DBI/Collection.pm
Log:
r18574 at truegrounds: jesse | 2005-11-08 15:57:15 -0500
* moved new paging code from Jifty to Jifty::DBI
Modified: Jifty-DBI/trunk/Makefile.PL
==============================================================================
--- Jifty-DBI/trunk/Makefile.PL (original)
+++ Jifty-DBI/trunk/Makefile.PL Tue Nov 8 16:14:41 2005
@@ -8,7 +8,9 @@
requires('UNIVERSAL::require');
requires('Lingua::EN::Inflect');
requires('Class::ReturnValue', 0.40);
+requires('Class::Accessor' => 0);
requires('Cache::Simple::TimedExpiry' => '0.21');
+requires('Data::Page');
requires('DateTime');
requires('DateTime::Format::Strptime');
Modified: Jifty-DBI/trunk/lib/Jifty/DBI/Collection.pm
==============================================================================
--- Jifty-DBI/trunk/lib/Jifty/DBI/Collection.pm (original)
+++ Jifty-DBI/trunk/lib/Jifty/DBI/Collection.pm Tue Nov 8 16:14:41 2005
@@ -1,7 +1,8 @@
package Jifty::DBI::Collection;
+use warnings;
use strict;
-use vars qw($VERSION);
+
=head1 NAME
@@ -45,6 +46,16 @@
set the database handle (a L<Jifty::DBI::Handle> object) and table
name for the class -- see the L</SYNOPSIS> for an example.
+
+=cut
+
+use vars qw($VERSION);
+
+use Data::Page;
+use base qw/Class::Accessor/;
+__PACKAGE__->mk_accessors(qw/pager/);
+
+
=head1 METHODS
=head2 new
@@ -89,11 +100,21 @@
handle => undef,
@_
);
- $self->_handle( $args{'handle'} );
-
+ $self->_handle( $args{'handle'} ) if ($args{'handle'});
+ $self->_init_pager();
$self->clean_slate();
}
+
+sub _init_pager {
+ my $self = shift;
+ $self->pager(Data::Page->new);
+
+ $self->pager->total_entries(0);
+ $self->pager->entries_per_page(10);
+ $self->pager->current_page(1);
+}
+
=head2 clean_slate
This completely erases all the data in the object. It's useful if a
@@ -131,7 +152,8 @@
# Force ourselves to have no limit statements. do_search won't
# work.
$self->_is_limited(0);
-}
+}
+
=head2 _handle [DBH]
@@ -1144,6 +1166,35 @@
}
+=head2 set_page_info [per_page => NUMBER,] [current_page => NUMBER]
+
+Sets the current page (one-based) and number of items per page on the
+pager object, and pulls the number of elements from the collection.
+This both sets up the collection's L<Data::Page> object so that you
+can use its calculations, and sets the L<Jifty::DBI::Collection>
+C<first_row> and C<rows_per_page> so that queries return values from
+the selected page.
+
+=cut
+
+sub set_page_info {
+ my $self = shift;
+ my %args = (
+ per_page => undef,
+ current_page => undef, # 1-based
+ @_
+ );
+
+ $self->pager->total_entries($self->count_all)
+ ->entries_per_page($args{'per_page'})
+ ->current_page($args{'current_page'});
+
+ $self->rows_per_page($args{'per_page'});
+ $self->first_row($self->pager->first);
+
+}
+
+
=head2 rows_per_page
limits the number of rows returned by the database. Optionally, takes
More information about the Rt-commit
mailing list