Changeset 3836

Show
Ignore:
Timestamp:
02/19/08 02:37:09 (17 months ago)
Author:
guilhermeblanco
Message:

Second parameter support in Doctrine_Pager::setCountQuery and added new method: Doctrine_Pager::getResultsInPage(), which returns the numbers of itens in current page

Files:
3 modified

Legend:

Unmodified
Added
Removed
  • branches/0.10/lib/Doctrine/Pager.php

    r3540 r3836  
    384384 
    385385    /** 
     386     * getResultsInPage 
     387     * 
     388     * Returns the number of itens in current page 
     389     * 
     390     * @return int    Number of itens in current page 
     391     */ 
     392    public function getResultsInPage() 
     393    { 
     394        $page = $this->getPage(); 
     395 
     396        if ($page != $this->getLastPage()) { 
     397            return $page * $this->getMaxPerPage(); 
     398        } 
     399 
     400        $offset = ($this->getPage() - 1) * $this->getMaxPerPage(); 
     401 
     402        return abs($this->getNumResults() - $offset); 
     403    } 
     404 
     405 
     406    /** 
    386407     * getQuery 
    387408     * 
     
    433454     * Defines the counter query to be used by pager 
    434455     * 
    435      * @param Doctrine_Query     Accepts either a Doctrine_Query object or a string  
    436      *                           (which does the Doctrine_Query class creation). 
    437      * @return void 
    438      */ 
    439     public function setCountQuery($query) 
     456     * @param Doctrine_Query  Accepts either a Doctrine_Query object or a string  
     457     *                        (which does the Doctrine_Query class creation). 
     458     * @param array           Optional params to be used by counter Doctrine_Query.  
     459     *                        If not defined, the params passed to execute method will be used. 
     460     * @return void 
     461     */ 
     462    public function setCountQuery($query, $params = null) 
    440463    { 
    441464        if (is_string($query)) { 
     
    444467 
    445468        $this->_countQuery = $query; 
     469 
     470        $this->setCountQueryParams($params); 
    446471 
    447472        $this->_setExecuted(false); 
     
    477502            $this->_countQueryParams = array_merge($this->_countQueryParams, $params); 
    478503        } else { 
     504            if ($params !== null && !is_array($params)) { 
     505                $params = array($params); 
     506            } 
     507 
    479508            $this->_countQueryParams = $params; 
    480509        } 
  • branches/0.9/lib/Doctrine/Pager.php

    r3540 r3836  
    384384 
    385385    /** 
     386     * getResultsInPage 
     387     * 
     388     * Returns the number of itens in current page 
     389     * 
     390     * @return int    Number of itens in current page 
     391     */ 
     392    public function getResultsInPage() 
     393    { 
     394        $page = $this->getPage(); 
     395 
     396        if ($page != $this->getLastPage()) { 
     397            return $page * $this->getMaxPerPage(); 
     398        } 
     399 
     400        $offset = ($this->getPage() - 1) * $this->getMaxPerPage(); 
     401 
     402        return abs($this->getNumResults() - $offset); 
     403    } 
     404 
     405 
     406    /** 
    386407     * getQuery 
    387408     * 
     
    433454     * Defines the counter query to be used by pager 
    434455     * 
    435      * @param Doctrine_Query     Accepts either a Doctrine_Query object or a string  
    436      *                           (which does the Doctrine_Query class creation). 
    437      * @return void 
    438      */ 
    439     public function setCountQuery($query) 
     456     * @param Doctrine_Query  Accepts either a Doctrine_Query object or a string  
     457     *                        (which does the Doctrine_Query class creation). 
     458     * @param array           Optional params to be used by counter Doctrine_Query.  
     459     *                        If not defined, the params passed to execute method will be used. 
     460     * @return void 
     461     */ 
     462    public function setCountQuery($query, $params = null) 
    440463    { 
    441464        if (is_string($query)) { 
     
    444467 
    445468        $this->_countQuery = $query; 
     469 
     470        $this->setCountQueryParams($params); 
    446471 
    447472        $this->_setExecuted(false); 
     
    477502            $this->_countQueryParams = array_merge($this->_countQueryParams, $params); 
    478503        } else { 
     504            if ($params !== null && !is_array($params)) { 
     505                $params = array($params); 
     506            } 
     507 
    479508            $this->_countQueryParams = $params; 
    480509        } 
  • trunk/lib/Doctrine/Pager.php

    r3570 r3836  
    384384 
    385385    /** 
     386     * getResultsInPage 
     387     * 
     388     * Returns the number of itens in current page 
     389     * 
     390     * @return int    Number of itens in current page 
     391     */ 
     392    public function getResultsInPage() 
     393    { 
     394        $page = $this->getPage(); 
     395 
     396        if ($page != $this->getLastPage()) { 
     397            return $page * $this->getMaxPerPage(); 
     398        } 
     399 
     400        $offset = ($this->getPage() - 1) * $this->getMaxPerPage(); 
     401 
     402        return abs($this->getNumResults() - $offset); 
     403    } 
     404 
     405 
     406    /** 
    386407     * getQuery 
    387408     * 
     
    433454     * Defines the counter query to be used by pager 
    434455     * 
    435      * @param Doctrine_Query     Accepts either a Doctrine_Query object or a string  
    436      *                           (which does the Doctrine_Query class creation). 
    437      * @return void 
    438      */ 
    439     public function setCountQuery($query) 
     456     * @param Doctrine_Query  Accepts either a Doctrine_Query object or a string  
     457     *                        (which does the Doctrine_Query class creation). 
     458     * @param array           Optional params to be used by counter Doctrine_Query.  
     459     *                        If not defined, the params passed to execute method will be used. 
     460     * @return void 
     461     */ 
     462    public function setCountQuery($query, $params = null) 
    440463    { 
    441464        if (is_string($query)) { 
     
    444467 
    445468        $this->_countQuery = $query; 
     469 
     470        $this->setCountQueryParams($params); 
    446471 
    447472        $this->_setExecuted(false); 
     
    477502            $this->_countQueryParams = array_merge($this->_countQueryParams, $params); 
    478503        } else { 
     504            if ($params !== null && !is_array($params)) { 
     505                $params = array($params); 
     506            } 
     507 
    479508            $this->_countQueryParams = $params; 
    480509        }