Commit 139720fb authored by guilhermeblanco's avatar guilhermeblanco

CHG: Updated Doctrine_Pager to become coding standards compliant

parent 05147fbe
...@@ -63,7 +63,8 @@ class Doctrine_Pager ...@@ -63,7 +63,8 @@ class Doctrine_Pager
/** /**
* __construct * __construct
* *
* @param mixed $query Accepts either a Doctrine_Query object or a string (which does the Doctrine_Query class creation). * @param mixed $query Accepts either a Doctrine_Query object or a string
* (which does the Doctrine_Query class creation).
* @param int $page Current page * @param int $page Current page
* @param int $maxPerPage Maximum itens per page * @param int $maxPerPage Maximum itens per page
* @return void * @return void
...@@ -88,6 +89,7 @@ class Doctrine_Pager ...@@ -88,6 +89,7 @@ class Doctrine_Pager
*/ */
protected function initialize() protected function initialize()
{ {
// etrieve the number of itens found
$count = $this->getQuery()->offset(0)->limit(0)->count(); $count = $this->getQuery()->offset(0)->limit(0)->count();
$this->setNbResults($count); $this->setNbResults($count);
...@@ -104,9 +106,13 @@ class Doctrine_Pager ...@@ -104,9 +106,13 @@ class Doctrine_Pager
*/ */
protected function adjustOffset() protected function adjustOffset()
{ {
$this->setLastPage(max(1, ceil($this->getNbResults() / $this->getMaxPerPage()))); // Define new total of pages
$this->setLastPage(
max(1, ceil($this->getNbResults() / $this->getMaxPerPage()))
);
$offset = ($this->getPage() - 1) * $this->getMaxPerPage(); $offset = ($this->getPage() - 1) * $this->getMaxPerPage();
// Assign new offset and limit to Doctrine_Query object
$p = $this->getQuery(); $p = $this->getQuery();
$p->offset($offset); $p->offset($offset);
$p->limit($this->getMaxPerPage()); $p->limit($this->getMaxPerPage());
...@@ -333,7 +339,8 @@ class Doctrine_Pager ...@@ -333,7 +339,8 @@ class Doctrine_Pager
* *
* Defines the maximum number of itens per page * Defines the maximum number of itens per page
* *
* @param $query Accepts either a Doctrine_Query object or a string (which does the Doctrine_Query class creation). * @param $query Accepts either a Doctrine_Query object or a string
* (which does the Doctrine_Query class creation).
* @return void * @return void
*/ */
protected function setQuery($query) protected function setQuery($query)
...@@ -351,7 +358,8 @@ class Doctrine_Pager ...@@ -351,7 +358,8 @@ class Doctrine_Pager
* executes the query and populates the data set * executes the query and populates the data set
* *
* @param $params Optional parameters to Doctrine_Query::execute * @param $params Optional parameters to Doctrine_Query::execute
* @param $hydrationMode Hyddration Mode of Doctrine_Query::execute returned ResultSet. Doctrine::Default is FETCH_RECORD * @param $hydrationMode Hyddration Mode of Doctrine_Query::execute
* returned ResultSet. Doctrine::Default is FETCH_RECORD
* @return Doctrine_Collection the root collection * @return Doctrine_Collection the root collection
*/ */
public function execute($params = array(), $hydrationMode = Doctrine::FETCH_RECORD) public function execute($params = array(), $hydrationMode = Doctrine::FETCH_RECORD)
...@@ -359,5 +367,3 @@ class Doctrine_Pager ...@@ -359,5 +367,3 @@ class Doctrine_Pager
return $this->getQuery()->execute($params, $hydrationMode); return $this->getQuery()->execute($params, $hydrationMode);
} }
} }
?>
\ No newline at end of file
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