2007-11-25 21:33:49 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* This software consists of voluntary contributions made by many individuals
|
|
|
|
* and is licensed under the LGPL. For more information, see
|
|
|
|
* <http://www.phpdoctrine.com>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Doctrine_Pager
|
|
|
|
*
|
|
|
|
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
|
|
|
|
* @package Doctrine
|
|
|
|
* @subpackage Pager
|
|
|
|
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
|
|
|
* @version $Revision$
|
2008-01-16 23:51:36 +03:00
|
|
|
* @link www.phpdoctrine.org
|
|
|
|
* @since 0.9
|
2007-11-25 21:33:49 +03:00
|
|
|
*/
|
|
|
|
class Doctrine_Pager
|
|
|
|
{
|
2007-11-25 22:09:51 +03:00
|
|
|
/**
|
2007-11-26 03:07:09 +03:00
|
|
|
* @var Doctrine_Query $_query Doctrine_Query object related to the pager
|
2007-11-25 21:33:49 +03:00
|
|
|
*/
|
2007-11-26 03:07:09 +03:00
|
|
|
protected $_query;
|
2007-11-25 22:09:51 +03:00
|
|
|
|
2008-01-17 17:37:11 +03:00
|
|
|
/**
|
|
|
|
* @var Doctrine_Query $_countQuery Doctrine_Query object related to the counter of pager
|
|
|
|
*/
|
|
|
|
protected $_countQuery;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var array $_countQueryParams Hold the params to be used by Doctrine_Query counter object of pager
|
|
|
|
*/
|
|
|
|
protected $_countQueryParams;
|
|
|
|
|
2007-11-25 22:09:51 +03:00
|
|
|
/**
|
2007-11-26 03:07:09 +03:00
|
|
|
* @var integer $_numResults Number of results found
|
2007-11-25 21:33:49 +03:00
|
|
|
*/
|
2007-11-26 03:07:09 +03:00
|
|
|
protected $_numResults;
|
2007-11-25 22:09:51 +03:00
|
|
|
|
2007-11-25 21:33:49 +03:00
|
|
|
/**
|
2007-11-26 03:07:09 +03:00
|
|
|
* @var integer $_maxPerPage Maximum number of itens per page
|
2007-11-25 21:33:49 +03:00
|
|
|
*/
|
2007-11-26 03:07:09 +03:00
|
|
|
protected $_maxPerPage;
|
2007-11-25 22:09:51 +03:00
|
|
|
|
|
|
|
/**
|
2007-11-26 03:07:09 +03:00
|
|
|
* @var integer $page Current page
|
2007-11-25 21:33:49 +03:00
|
|
|
*/
|
2007-11-26 03:07:09 +03:00
|
|
|
protected $_page;
|
2007-11-25 22:09:51 +03:00
|
|
|
|
|
|
|
/**
|
2007-11-26 03:07:09 +03:00
|
|
|
* @var integer $_lastPage Last page (total of pages)
|
2007-11-25 21:33:49 +03:00
|
|
|
*/
|
2007-11-26 03:07:09 +03:00
|
|
|
protected $_lastPage;
|
2007-11-25 21:33:49 +03:00
|
|
|
|
2008-01-16 23:51:36 +03:00
|
|
|
/**
|
|
|
|
* @var boolean $_executed Pager was initialized (called "execute" at least once)
|
|
|
|
*/
|
|
|
|
protected $_executed;
|
|
|
|
|
2007-11-25 21:33:49 +03:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* __construct
|
|
|
|
*
|
2007-11-25 22:09:51 +03:00
|
|
|
* @param mixed $query Accepts either a Doctrine_Query object or a string
|
2008-01-16 23:51:36 +03:00
|
|
|
* (which does the Doctrine_Query class creation).
|
2007-11-25 21:33:49 +03:00
|
|
|
* @param int $page Current page
|
|
|
|
* @param int $maxPerPage Maximum itens per page
|
|
|
|
* @return void
|
|
|
|
*/
|
2007-11-26 03:07:09 +03:00
|
|
|
public function __construct($query, $page, $maxPerPage = 0)
|
2007-11-25 22:09:51 +03:00
|
|
|
{
|
2008-01-16 23:51:36 +03:00
|
|
|
$this->_setExecuted(false);
|
2007-11-25 22:09:51 +03:00
|
|
|
|
2008-01-16 23:51:36 +03:00
|
|
|
$this->_setQuery($query);
|
2007-11-25 22:09:51 +03:00
|
|
|
$this->_setPage($page);
|
|
|
|
|
2008-01-16 23:51:36 +03:00
|
|
|
$this->setMaxPerPage($maxPerPage);
|
2007-11-25 22:09:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2007-12-13 06:07:24 +03:00
|
|
|
* _initialize
|
2007-11-25 22:09:51 +03:00
|
|
|
*
|
|
|
|
* Initialize Pager object calculating number of results
|
|
|
|
*
|
2008-01-16 23:51:36 +03:00
|
|
|
* @param $params Optional parameters to Doctrine_Query::execute
|
2007-11-25 22:09:51 +03:00
|
|
|
* @return void
|
|
|
|
*/
|
2008-01-16 23:51:36 +03:00
|
|
|
protected function _initialize($params = array())
|
2007-11-25 22:09:51 +03:00
|
|
|
{
|
2007-11-26 02:57:10 +03:00
|
|
|
// retrieve the number of items found
|
2008-01-17 17:37:11 +03:00
|
|
|
$count = $this->getCountQuery()->count($this->getCountQueryParams($params));
|
2007-11-25 22:09:51 +03:00
|
|
|
|
2008-01-17 18:33:08 +03:00
|
|
|
$this->_setNumResults($count);
|
|
|
|
$this->_setExecuted(true); // _adjustOffset relies of _executed equals true = getNumResults()
|
2008-01-16 23:51:36 +03:00
|
|
|
|
2008-01-17 18:01:07 +03:00
|
|
|
$this->_adjustOffset();
|
2007-11-25 22:09:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2007-12-13 06:07:24 +03:00
|
|
|
* _adjustOffset
|
2007-11-25 22:09:51 +03:00
|
|
|
*
|
|
|
|
* Adjusts last page of Doctrine_Pager, offset and limit of Doctrine_Query associated
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2007-12-13 06:07:24 +03:00
|
|
|
protected function _adjustOffset()
|
2007-11-25 22:09:51 +03:00
|
|
|
{
|
2008-01-17 18:33:08 +03:00
|
|
|
// Define new total of pages
|
|
|
|
$this->_setLastPage(
|
|
|
|
max(1, ceil($this->getNumResults() / $this->getMaxPerPage()))
|
|
|
|
);
|
|
|
|
$offset = ($this->getPage() - 1) * $this->getMaxPerPage();
|
|
|
|
|
|
|
|
// Assign new offset and limit to Doctrine_Query object
|
|
|
|
$p = $this->getQuery();
|
|
|
|
$p->offset($offset);
|
|
|
|
$p->limit($this->getMaxPerPage());
|
2008-01-16 23:51:36 +03:00
|
|
|
}
|
2007-11-25 22:09:51 +03:00
|
|
|
|
2008-01-16 23:51:36 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* getExecuted
|
|
|
|
*
|
|
|
|
* Returns the check if Pager was already executed at least once
|
|
|
|
*
|
|
|
|
* @return boolen Pager was executed
|
|
|
|
*/
|
|
|
|
public function getExecuted()
|
|
|
|
{
|
|
|
|
return $this->_executed;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* _setExecuted
|
|
|
|
*
|
|
|
|
* Defines if Pager was already executed
|
|
|
|
*
|
|
|
|
* @param $executed Pager was executed
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
protected function _setExecuted($executed)
|
|
|
|
{
|
|
|
|
$this->_executed = $executed;
|
2007-11-25 22:09:51 +03:00
|
|
|
}
|
2007-11-25 21:33:49 +03:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
2007-11-26 03:07:09 +03:00
|
|
|
* getNumResults
|
2007-11-25 21:33:49 +03:00
|
|
|
*
|
|
|
|
* Returns the number of results found
|
|
|
|
*
|
|
|
|
* @return int the number of results found
|
|
|
|
*/
|
2007-11-26 03:07:09 +03:00
|
|
|
public function getNumResults()
|
2007-11-25 22:09:51 +03:00
|
|
|
{
|
2008-01-16 23:51:36 +03:00
|
|
|
if ($this->getExecuted()) {
|
|
|
|
return $this->_numResults;
|
|
|
|
}
|
|
|
|
|
|
|
|
throw new Doctrine_Pager_Exception(
|
|
|
|
'Cannot retrieve the number of results of a not yet executed Pager query'
|
|
|
|
);
|
2007-11-25 22:09:51 +03:00
|
|
|
}
|
2007-11-25 21:33:49 +03:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
2007-12-13 06:07:24 +03:00
|
|
|
* _setNumResults
|
2007-11-25 21:33:49 +03:00
|
|
|
*
|
|
|
|
* Defines the number of total results on initial query
|
|
|
|
*
|
|
|
|
* @param $nb Number of results found on initial query fetch
|
|
|
|
* @return void
|
|
|
|
*/
|
2007-12-13 06:07:24 +03:00
|
|
|
protected function _setNumResults($nb)
|
2007-11-25 22:09:51 +03:00
|
|
|
{
|
2007-11-26 03:07:09 +03:00
|
|
|
$this->_numResults = $nb;
|
2007-11-25 22:09:51 +03:00
|
|
|
}
|
2007-11-25 21:33:49 +03:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* getFirstPage
|
|
|
|
*
|
|
|
|
* Returns the first page
|
|
|
|
*
|
|
|
|
* @return int first page
|
|
|
|
*/
|
2007-11-25 22:09:51 +03:00
|
|
|
public function getFirstPage()
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
2007-11-25 21:33:49 +03:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* getLastPage
|
|
|
|
*
|
|
|
|
* Returns the last page (total of pages)
|
|
|
|
*
|
|
|
|
* @return int last page (total of pages)
|
|
|
|
*/
|
2007-11-25 22:09:51 +03:00
|
|
|
public function getLastPage()
|
|
|
|
{
|
2008-01-16 23:51:36 +03:00
|
|
|
if ($this->getExecuted()) {
|
|
|
|
return $this->_lastPage;
|
|
|
|
}
|
|
|
|
|
|
|
|
throw new Doctrine_Pager_Exception(
|
|
|
|
'Cannot retrieve the last page number of a not yet executed Pager query'
|
|
|
|
);
|
2007-11-25 22:09:51 +03:00
|
|
|
}
|
2007-11-25 21:33:49 +03:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
2007-12-13 06:07:24 +03:00
|
|
|
* _setLastPage
|
2007-11-25 21:33:49 +03:00
|
|
|
*
|
|
|
|
* Defines the last page (total of pages)
|
|
|
|
*
|
|
|
|
* @param $page last page (total of pages)
|
|
|
|
* @return void
|
|
|
|
*/
|
2007-12-13 06:07:24 +03:00
|
|
|
protected function _setLastPage($page)
|
2007-11-25 22:09:51 +03:00
|
|
|
{
|
2007-11-26 03:07:09 +03:00
|
|
|
$this->_lastPage = $page;
|
2007-11-25 21:33:49 +03:00
|
|
|
|
2007-11-26 02:59:54 +03:00
|
|
|
if ($this->getPage() > $page) {
|
2007-11-25 22:09:51 +03:00
|
|
|
$this->_setPage($page);
|
|
|
|
}
|
|
|
|
}
|
2007-11-25 21:33:49 +03:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* getLastPage
|
|
|
|
*
|
|
|
|
* Returns the current page
|
|
|
|
*
|
|
|
|
* @return int current page
|
|
|
|
*/
|
2007-11-25 22:09:51 +03:00
|
|
|
public function getPage()
|
|
|
|
{
|
2007-11-26 03:07:09 +03:00
|
|
|
return $this->_page;
|
2007-11-25 22:09:51 +03:00
|
|
|
}
|
2007-11-25 21:33:49 +03:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* getLastPage
|
|
|
|
*
|
|
|
|
* Returns the next page
|
|
|
|
*
|
|
|
|
* @return int next page
|
|
|
|
*/
|
2007-11-25 22:09:51 +03:00
|
|
|
public function getNextPage()
|
|
|
|
{
|
2008-01-16 23:51:36 +03:00
|
|
|
if ($this->getExecuted()) {
|
|
|
|
return $this->_lastPage;
|
|
|
|
}
|
|
|
|
|
|
|
|
throw new Doctrine_Pager_Exception(
|
|
|
|
'Cannot retrieve the last page number of a not yet executed Pager query'
|
|
|
|
);return min($this->getPage() + 1, $this->getLastPage());
|
2007-11-25 22:09:51 +03:00
|
|
|
}
|
2007-11-25 21:33:49 +03:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* getLastPage
|
|
|
|
*
|
|
|
|
* Returns the previous page
|
|
|
|
*
|
|
|
|
* @return int previous page
|
|
|
|
*/
|
2007-11-25 22:09:51 +03:00
|
|
|
public function getPreviousPage()
|
|
|
|
{
|
2008-01-16 23:51:36 +03:00
|
|
|
if ($this->getExecuted()) {
|
|
|
|
return max($this->getPage() - 1, $this->getFirstPage());
|
|
|
|
}
|
|
|
|
|
|
|
|
throw new Doctrine_Pager_Exception(
|
|
|
|
'Cannot retrieve the previous page number of a not yet executed Pager query'
|
|
|
|
);
|
2007-11-25 22:09:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* haveToPaginate
|
|
|
|
*
|
|
|
|
* Return true if it's necessary to paginate or false if not
|
|
|
|
*
|
|
|
|
* @return bool true if it is necessary to paginate, false otherwise
|
|
|
|
*/
|
|
|
|
public function haveToPaginate()
|
|
|
|
{
|
2008-01-16 23:51:36 +03:00
|
|
|
if ($this->getExecuted()) {
|
|
|
|
return $this->getNumResults() > $this->getMaxPerPage();
|
|
|
|
}
|
|
|
|
|
|
|
|
throw new Doctrine_Pager_Exception(
|
|
|
|
'Cannot know if it is necessary to paginate a not yet executed Pager query'
|
|
|
|
);
|
2007-11-25 22:09:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2007-11-25 21:33:49 +03:00
|
|
|
* setPage
|
|
|
|
*
|
|
|
|
* Defines the current page and automatically adjust offset and limits
|
|
|
|
*
|
|
|
|
* @param $page current page
|
|
|
|
* @return void
|
|
|
|
*/
|
2007-11-25 22:09:51 +03:00
|
|
|
public function setPage($page)
|
|
|
|
{
|
|
|
|
$this->_setPage($page);
|
2008-01-16 23:51:36 +03:00
|
|
|
$this->_setExecuted(false);
|
2007-11-25 22:09:51 +03:00
|
|
|
}
|
2007-11-25 21:33:49 +03:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* _setPage
|
|
|
|
*
|
|
|
|
* Defines the current page
|
|
|
|
*
|
|
|
|
* @param $page current page
|
|
|
|
* @return void
|
|
|
|
*/
|
2007-11-25 22:09:51 +03:00
|
|
|
private function _setPage($page)
|
|
|
|
{
|
|
|
|
$page = intval($page);
|
2007-11-26 03:07:09 +03:00
|
|
|
$this->_page = ($page <= 0) ? 1 : $page;
|
2007-11-25 22:09:51 +03:00
|
|
|
}
|
2007-11-25 21:33:49 +03:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* getLastPage
|
|
|
|
*
|
|
|
|
* Returns the maximum number of itens per page
|
|
|
|
*
|
|
|
|
* @return int maximum number of itens per page
|
|
|
|
*/
|
2007-11-25 22:09:51 +03:00
|
|
|
public function getMaxPerPage()
|
|
|
|
{
|
2007-11-26 03:07:09 +03:00
|
|
|
return $this->_maxPerPage;
|
2007-11-25 22:09:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2007-11-25 21:33:49 +03:00
|
|
|
* setMaxPerPage
|
|
|
|
*
|
|
|
|
* Defines the maximum number of itens per page and automatically adjust offset and limits
|
|
|
|
*
|
|
|
|
* @param $max maximum number of itens per page
|
|
|
|
* @return void
|
|
|
|
*/
|
2007-11-25 22:09:51 +03:00
|
|
|
public function setMaxPerPage($max)
|
|
|
|
{
|
|
|
|
if ($max > 0) {
|
2007-11-26 03:07:09 +03:00
|
|
|
$this->_maxPerPage = $max;
|
2007-11-25 22:09:51 +03:00
|
|
|
} else if ($max == 0) {
|
2007-11-26 03:07:09 +03:00
|
|
|
$this->_maxPerPage = 25;
|
2007-11-25 22:09:51 +03:00
|
|
|
} else {
|
2007-11-26 03:07:09 +03:00
|
|
|
$this->_maxPerPage = abs($max);
|
2007-11-25 22:09:51 +03:00
|
|
|
}
|
2008-01-16 23:51:36 +03:00
|
|
|
|
|
|
|
$this->_setExecuted(false);
|
2007-11-25 22:09:51 +03:00
|
|
|
}
|
2007-11-25 21:33:49 +03:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* getQuery
|
|
|
|
*
|
2008-01-17 17:37:11 +03:00
|
|
|
* Returns the Doctrine_Query collector object related to the pager
|
2007-11-25 21:33:49 +03:00
|
|
|
*
|
2008-01-17 17:37:11 +03:00
|
|
|
* @return Doctrine_Query Doctrine_Query object related to the pager
|
2007-11-25 21:33:49 +03:00
|
|
|
*/
|
2007-11-25 22:09:51 +03:00
|
|
|
public function getQuery()
|
|
|
|
{
|
2007-11-26 03:07:09 +03:00
|
|
|
return $this->_query;
|
2007-11-25 22:09:51 +03:00
|
|
|
}
|
2007-11-25 21:33:49 +03:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
2007-12-13 06:07:24 +03:00
|
|
|
* _setQuery
|
2007-11-25 21:33:49 +03:00
|
|
|
*
|
2008-01-17 17:37:11 +03:00
|
|
|
* Defines the collector query to be used by pager
|
2007-11-25 21:33:49 +03:00
|
|
|
*
|
2008-01-17 17:37:11 +03:00
|
|
|
* @param Doctrine_Query Accepts either a Doctrine_Query object or a string
|
|
|
|
* (which does the Doctrine_Query class creation).
|
2007-11-25 21:33:49 +03:00
|
|
|
* @return void
|
|
|
|
*/
|
2007-12-13 06:07:24 +03:00
|
|
|
protected function _setQuery($query)
|
2007-11-25 22:09:51 +03:00
|
|
|
{
|
|
|
|
if (is_string($query)) {
|
2007-11-26 02:59:54 +03:00
|
|
|
$query = Doctrine_Query::create()->parseQuery($query);
|
2007-11-25 22:09:51 +03:00
|
|
|
}
|
2007-11-25 21:33:49 +03:00
|
|
|
|
2007-11-26 03:07:09 +03:00
|
|
|
$this->_query = $query;
|
2007-11-25 22:09:51 +03:00
|
|
|
}
|
2007-11-25 21:33:49 +03:00
|
|
|
|
|
|
|
|
2008-01-17 17:37:11 +03:00
|
|
|
/**
|
|
|
|
* getCountQuery
|
|
|
|
*
|
|
|
|
* Returns the Doctrine_Query object that is used to make the count results to pager
|
|
|
|
*
|
|
|
|
* @return Doctrine_Query Doctrine_Query object related to the pager
|
|
|
|
*/
|
|
|
|
public function getCountQuery()
|
|
|
|
{
|
|
|
|
return ($this->_countQuery !== null) ? $this->_countQuery : $this->_query;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* setCountQuery
|
|
|
|
*
|
|
|
|
* Defines the counter query to be used by pager
|
|
|
|
*
|
|
|
|
* @param Doctrine_Query Accepts either a Doctrine_Query object or a string
|
|
|
|
* (which does the Doctrine_Query class creation).
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function setCountQuery($query)
|
|
|
|
{
|
|
|
|
if (is_string($query)) {
|
|
|
|
$query = Doctrine_Query::create()->parseQuery($query);
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->_countQuery = $query;
|
|
|
|
|
|
|
|
$this->_setExecuted(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* getCountQueryParams
|
|
|
|
*
|
|
|
|
* Returns the params to be used by counter Doctrine_Query
|
|
|
|
*
|
|
|
|
* @return array Doctrine_Query counter params
|
|
|
|
*/
|
|
|
|
public function getCountQueryParams($defaultParams = array())
|
|
|
|
{
|
|
|
|
return ($this->_countQueryParams !== null) ? $this->_countQueryParams : $defaultParams;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* setCountQueryParams
|
|
|
|
*
|
|
|
|
* Defines the params to be used by counter Doctrine_Query
|
|
|
|
*
|
|
|
|
* @param array Optional params to be used by counter Doctrine_Query.
|
|
|
|
* If not defined, the params passed to execute method will be used.
|
|
|
|
* @param boolean Optional argument that append the query param instead of overriding the existent ones.
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function setCountQueryParams($params = array(), $append = false)
|
|
|
|
{
|
|
|
|
if ($append && is_array($this->_countQueryParams)) {
|
|
|
|
$this->_countQueryParams = array_merge($this->_countQueryParams, $params);
|
|
|
|
} else {
|
|
|
|
$this->_countQueryParams = $params;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->_setExecuted(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-25 21:33:49 +03:00
|
|
|
/**
|
|
|
|
* execute
|
|
|
|
*
|
2008-01-16 23:51:36 +03:00
|
|
|
* Executes the query, populates the collection and then return it
|
|
|
|
*
|
|
|
|
* @param $params Optional parameters to Doctrine_Query::execute
|
|
|
|
* @param $hydrationMode Hydration Mode of Doctrine_Query::execute
|
|
|
|
* returned ResultSet. Doctrine::Default is FETCH_RECORD
|
|
|
|
* @return Doctrine_Collection The root collection
|
2007-11-25 21:33:49 +03:00
|
|
|
*/
|
2007-11-25 22:09:51 +03:00
|
|
|
public function execute($params = array(), $hydrationMode = Doctrine::FETCH_RECORD)
|
|
|
|
{
|
2008-01-17 17:37:11 +03:00
|
|
|
if (!$this->getExecuted()) {
|
|
|
|
$this->_initialize($params);
|
|
|
|
}
|
2008-01-16 23:51:36 +03:00
|
|
|
|
2007-11-25 22:09:51 +03:00
|
|
|
return $this->getQuery()->execute($params, $hydrationMode);
|
|
|
|
}
|
2007-11-25 21:33:49 +03:00
|
|
|
}
|