-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Zend Framework paginator Doctrine implementation
- Loading branch information
Showing
2 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |