/** * Prepares a pager based on the finder * The pager is initialized (it knows how many pages it contains) * But it won't be populated until you call getResults() on it * * @param integer $page The current page (1 by default) * @param integer $maxPerPage The maximum number of results per page (10 by default) * * @return sfPropelFinderPager The initialized pager object */ public function paginate($page = 1, $maxPerPage = 10) { // Children of sfPropelPager don't have a $class property, so we need to guess it $pager = new sfPropelFinderPager($this->class, $maxPerPage); $pager->setFinder($this); $pager->setPage($page); $pager->init(); return $pager; }
$t->is(count($articles), 2, 'sfPropelFinder::paginate() returns a pager object from which items can be retrieved'); $t->isa_ok(@$articles[0], 'Article', 'sfPropelFinder::paginate() returns a pager object from which items can be retrieved'); $pager = sfPropelFinder::from('Article')-> where('Title', 'like', 'tt%')-> paginate(1, 2); $t->is($pager->getNbResults(), 4, 'sfPropelFinder::paginate() sfPropelFinder::paginate() uses the internal conditions'); $t->is($pager->getLastPage(), 2, 'sfPropelFinder::paginate() sfPropelFinder::paginate() uses the internal conditions'); $t->is($pager->getFirstIndice(), 1, 'sfPropelFinder::paginate() sfPropelFinder::paginate() uses the internal conditions'); $t->diag('sfPropelFinderPager issues with GroupBy'); $finder = sfPropelFinder::from('Article')->groupBy('Title'); $pager = new sfPropelFinderPager('Article', 2); $pager->setFinder($finder); $pager->init(); $t->is($con->getLastExecutedQuery(), propel_sql('SELECT COUNT([P13*][P12article.ID]) FROM article'), 'sfPropelFinderPager::init() removes groupBy clauses and issues a COUNT'); $pager->getResults(); $t->is($con->getLastExecutedQuery(), 'SELECT article.ID, article.TITLE, article.CATEGORY_ID FROM article GROUP BY article.TITLE LIMIT 2', 'sfPropelFinderPager::getResults() does not remove groupBy clauses and issues a SELECT'); $t->diag('sfPropelFinderPager issues with object finders classes'); class ArticleFinder extends sfPropelFinder { protected $class = 'Article'; } $finder = new ArticleFinder(); try { $pager = $finder->paginate(); $t->pass('Children of sfPropelFinder can use paginate()'); }