View Source

<ac:macro ac:name="unmigrated-inline-wiki-markup"><ac:plain-text-body><![CDATA[{zone-template-instance:ZFPROP:Proposal Zone Template}

{zone-data:component-name}
Zend_Paginator_Adapter_Doctrine - Jason Eisenmenger
{zone-data}

{zone-data:proposer-list}
[Jason Eisenmenger|mailto:jasoneisen@gmail.com]
{zone-data}

{zone-data:liaison}
[~ralph]
{zone-data}

{zone-data:revision}
1.0 - 5 September 2008: Initial Draft.
{zone-data}

{zone-data:overview}
Zend_Paginator_Adapter_Doctrine is an alternative to DbTable and allows the use of Doctrine

You may download the latest working class [here|http://framework.zend.com/wiki/download/attachments/7831683/Doctrine.php]
{zone-data}

{zone-data:references}
* [Zend_Paginator|http://framework.zend.com/wiki/pages/editpage.action?pageId=43560]
{zone-data}

{zone-data:requirements}
* This component *will* work as a drop-in replacement to DbTable.
{zone-data}

{zone-data:dependencies}
* Zend_Paginator
* Zend_Paginator_Exception
* Zend_Paginator_Adapter_Interface
{zone-data}

{zone-data:operation}
Exactly the same as DbTable
{zone-data}

{zone-data:milestones}
* Milestone 1: *\[DONE\]* Write proposal
* Milestone 2: *\[DONE\]* Post working prototype
* Milestone 3: *\[DONE\]* Review by community
* Milestone 4: Working prototype checked into the incubator supporting use cases #1, #2, ...
* Milestone 5: Working prototype checked into the incubator supporting use cases #3 and #4.
* Milestone 6: Unit tests exist, work, and are checked into SVN.
* Milestone 7: Initial documentation exists.
{zone-data}

{zone-data:class-list}
* Zend_Paginator_Adapter_Doctrine
{zone-data}

{zone-data:use-cases}
|| UC-01: Standard Usage ||
{code}

$query = Doctrine_Query::create()
->select('a.title, a.date, au.firstname, au.lastname')
->from('Article a')
->innerJoin('a.Author au')
->orderby('a.date DESC');

$paginator = new Zend_Paginator(
new Zend_Paginator_Adapter_Doctrine($query));

$paginator->setRouteName('article')
->setItemCountPerPage(15)
->setPageRange(5)
->setCurrentPageNumber($this->_getParam('page'));

$this->view->pages = $paginator;
{code}

|| UC-01: Supplying a count query ||
{code}

$query = Doctrine_Query::create()
->select('a.title, a.date, au.firstname, au.lastname')
->from('Article a')
->innerJoin('a.Author au')
->orderby('a.date DESC');

$paginator = new Zend_Paginator(
new Zend_Paginator_Adapter_Doctrine($query));

$countQuery = Doctrine_Query::create()
->select('COUNT(a.id) AS '. Zend_Paginator_Adapter_Doctrine::ROW_COUNT_COLUMN)
->from('Article a)
->innerJoin(a.Author au');

$paginator->setRowCount($countQuery)
->setRouteName('article')
->setItemCountPerPage(15)
->setPageRange(5)
->setCurrentPageNumber($this->_getParam('page'));

$this->view->pages = $paginator;
{code}
{zone-data}

{zone-data:skeletons}
{code}
class Zend_Paginator_Adapter_Doctrine implements Zend_Paginator_Adapter_Interface
{
/**
* Name of the row count column
*
* @var string
*/
const ROW_COUNT_COLUMN = 'zend_paginator_row_count';

/**
* Database query
*
* @var Doctrine_Query
*/
protected $_query = null;

/**
* Total item count
*
* @var integer
*/
protected $_rowCount = null;

/**
* Constructor.
*
* @param Doctrine_Query $query The select query
*/
public function __construct(Doctrine_Query $query)
{
}

/**
* Sets the total row count, either directly or through a supplied query.
*
* @param Doctrine_Query|integer $totalRowCount Total row count integer
* or query
* @return Zend_Paginator_Adapter_Doctrine_Query $this
* @throws Zend_Paginator_Exception
*/
public function setRowCount($rowCount)
{
}

/**
* Returns an array of items for a page.
*
* @param integer $offset Page offset
* @param integer $itemCountPerPage Number of items per page
* @return array
*/
public function getItems($offset, $itemCountPerPage)
{
}

/**
* Returns the total number of rows in the result set.
*
* @return integer
*/
public function count()
{
}
}

{code}
{zone-data}

{zone-template-instance}]]></ac:plain-text-body></ac:macro>