Commit ebdb97b9 authored by guilhermeblanco's avatar guilhermeblanco

Second parameter support in Doctrine_Pager::setCountQuery and added new...

Second parameter support in Doctrine_Pager::setCountQuery and added new method: Doctrine_Pager::getResultsInPage(), which returns the numbers of itens in current page
parent 57df018c
...@@ -382,6 +382,27 @@ class Doctrine_Pager ...@@ -382,6 +382,27 @@ class Doctrine_Pager
} }
/**
* getResultsInPage
*
* Returns the number of itens in current page
*
* @return int Number of itens in current page
*/
public function getResultsInPage()
{
$page = $this->getPage();
if ($page != $this->getLastPage()) {
return $page * $this->getMaxPerPage();
}
$offset = ($this->getPage() - 1) * $this->getMaxPerPage();
return abs($this->getNumResults() - $offset);
}
/** /**
* getQuery * getQuery
* *
...@@ -434,9 +455,11 @@ class Doctrine_Pager ...@@ -434,9 +455,11 @@ class Doctrine_Pager
* *
* @param Doctrine_Query Accepts either a Doctrine_Query object or a string * @param Doctrine_Query Accepts either a Doctrine_Query object or a string
* (which does the Doctrine_Query class creation). * (which does the Doctrine_Query class creation).
* @param array Optional params to be used by counter Doctrine_Query.
* If not defined, the params passed to execute method will be used.
* @return void * @return void
*/ */
public function setCountQuery($query) public function setCountQuery($query, $params = null)
{ {
if (is_string($query)) { if (is_string($query)) {
$query = Doctrine_Query::create()->parseQuery($query); $query = Doctrine_Query::create()->parseQuery($query);
...@@ -444,6 +467,8 @@ class Doctrine_Pager ...@@ -444,6 +467,8 @@ class Doctrine_Pager
$this->_countQuery = $query; $this->_countQuery = $query;
$this->setCountQueryParams($params);
$this->_setExecuted(false); $this->_setExecuted(false);
} }
...@@ -476,6 +501,10 @@ class Doctrine_Pager ...@@ -476,6 +501,10 @@ class Doctrine_Pager
if ($append && is_array($this->_countQueryParams)) { if ($append && is_array($this->_countQueryParams)) {
$this->_countQueryParams = array_merge($this->_countQueryParams, $params); $this->_countQueryParams = array_merge($this->_countQueryParams, $params);
} else { } else {
if ($params !== null && !is_array($params)) {
$params = array($params);
}
$this->_countQueryParams = $params; $this->_countQueryParams = $params;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment