Kdyby\Doctrine\QueryObject::count PHP Method

count() public method

public count ( Kdyby\Persistence\Queryable $repository, ResultSet $resultSet = NULL, Doctrine\ORM\Tools\Pagination\Paginator $paginatedQuery = NULL ) : integer
$repository Kdyby\Persistence\Queryable
$resultSet ResultSet
$paginatedQuery Doctrine\ORM\Tools\Pagination\Paginator
return integer
    public function count(Queryable $repository, ResultSet $resultSet = NULL, Paginator $paginatedQuery = NULL)
    {
        if ($query = $this->doCreateCountQuery($repository)) {
            return (int) $this->toQuery($query)->getSingleScalarResult();
        }
        if ($this->lastQuery && $this->lastQuery instanceof NativeQueryWrapper) {
            $class = get_called_class();
            throw new NotSupportedException("You must implement your own count query in {$class}::doCreateCountQuery(), Paginator from Doctrine doesn't support NativeQueries.");
        }
        if ($paginatedQuery !== NULL) {
            return $paginatedQuery->count();
        }
        $query = $this->getQuery($repository)->setFirstResult(NULL)->setMaxResults(NULL);
        $paginatedQuery = new Paginator($query, $resultSet ? $resultSet->getFetchJoinCollection() : TRUE);
        $paginatedQuery->setUseOutputWalkers($resultSet ? $resultSet->getUseOutputWalkers() : NULL);
        return $paginatedQuery->count();
    }

Usage Example

Esempio n. 1
0
 /**
  * @throws \Kdyby\Doctrine\QueryException
  * @return int
  */
 public function getTotalCount()
 {
     if ($this->totalCount === NULL) {
         try {
             $this->frozen = TRUE;
             $paginatedQuery = $this->createPaginatedQuery($this->query);
             if ($this->queryObject !== NULL && $this->repository !== NULL) {
                 $this->totalCount = $this->queryObject->count($this->repository, $this, $paginatedQuery);
             } else {
                 $this->totalCount = $paginatedQuery->count();
             }
         } catch (ORMException $e) {
             throw new QueryException($e, $this->query, $e->getMessage());
         }
     }
     return $this->totalCount;
 }