Skip to content

Commit

Permalink
Added Zend Framework paginator Doctrine implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
juokaz committed Nov 27, 2009
1 parent dd2ef93 commit 1e73f3a
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
49 changes: 49 additions & 0 deletions zf-doctrine-paginate/Adapter/DoctrineQuery.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

class App_Paginator_Adapter_DoctrineQuery implements Zend_Paginator_Adapter_Interface
{
/**
* @var Doctrine_Query
*/
protected $_query;

/**
* @var int
*/
protected $_rowCount;

public function __construct(Doctrine_Query $query)
{
$this->_query = $query;
}

/**
* Get items
*
* @param int $offset
* @param int $itemsPerPage
* @return Doctrine_Collection
*/
public function getItems($offset, $itemsPerPage)
{
return $this->_query
->limit($itemsPerPage)
->offset($offset)
->execute();
}

/**
* Count results
*
* @return int
*/
public function count()
{
if ($this->_rowCount === null)
{
$this->_rowCount = $this->_query->count();
}

return $this->_rowCount;
}
}
19 changes: 19 additions & 0 deletions zf-doctrine-paginate/Doctrine.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

class App_Paginator_Doctrine extends Zend_Paginator
{
/**
* Get new doctrine query paginator
*
* @param Doctrine_Query $query
* @param int $limit
* @param int $page
*/
public function __construct(Doctrine_Query $query, $page = 1, $limit = 10)
{
parent::__construct(new App_Paginator_Adapter_DoctrineQuery($query));

$this->setItemCountPerPage($limit);
$this->setCurrentPageNumber($page);
}
}

0 comments on commit 1e73f3a

Please sign in to comment.