/** * Returns query for count of items. * * @return Doctrine_Query */ protected function getCountQuery() { if ($this->_countQuery == null) { $this->_countQuery = clone $this->_query; $partsToBeRemoved = array('offset', 'limit', 'orderby'); foreach ($partsToBeRemoved as $part) { $this->_countQuery->removeDqlQueryPart($part); $this->_countQuery->removeSqlQueryPart($part); } } return $this->_countQuery; }