private function getTotalNumberOfEntities($entity, $startOffset)
    {
        $objectManager = $this->getObjectManager($entity);
        $repository = $objectManager->getRepository($entity);

        if ($repository instanceof DocumentRepository) {
            $totalSize = $repository->createQueryBuilder()
                ->getQuery()
                ->count();
        } else {
            $dataStoreMetadata = $objectManager->getClassMetadata($entity);

            $identifierFieldNames = $dataStoreMetadata->getIdentifierFieldNames();

            if (!count($identifierFieldNames)) {
                throw new \Exception(sprintf('No primary key found for entity %s', $entity));
            }

            $countableColumn = reset($identifierFieldNames);

            /** @var EntityRepository $repository */
            $totalSize = $repository->createQueryBuilder('size')
                ->select(sprintf('count(size.%s)', $countableColumn))
                ->getQuery()
                ->getSingleScalarResult();
        }

        return $totalSize - $startOffset;
    }
private function getTotalNumberOfEntities($entity, $startOffset)
    {
        $objectManager = $this->getObjectManager($entity);
        $repository = $objectManager->getRepository($entity);

        if ($repository instanceof DocumentRepository) {
            $totalSize = $repository->createQueryBuilder()
                ->getQuery()
                ->count();
        } else {
            $dataStoreMetadata = $objectManager->getClassMetadata($entity);

            $identifierFieldNames = $dataStoreMetadata->getIdentifierFieldNames();

            if (!count($identifierFieldNames)) {
                throw new \Exception(sprintf('No primary key found for entity %s', $entity));
            }

            $countableColumn = reset($identifierFieldNames);

            /** @var EntityRepository $repository */
            $totalSize = $repository->createQueryBuilder('size')
                ->select(sprintf('count(size.%s)', $countableColumn))
                ->getQuery()
                ->getSingleScalarResult();
        }

        return $totalSize - $startOffset;
    }
private function getTotalNumberOfEntities ( $ entity , $ startOffset ) { $ objectManager = $ this -> getObjectManager ( $ entity ) ; $ repository = $ objectManager -> getRepository ( $ entity ) ; if ( $ repository instanceof DocumentRepository ) { $ totalSize = $ repository -> createQueryBuilder ( ) -> getQuery ( ) -> count ( ) ; } else { $ dataStoreMetadata = $ objectManager -> getClassMetadata ( $ entity ) ; $ identifierFieldNames = $ dataStoreMetadata -> getIdentifierFieldNames ( ) ; if ( ! count ( $ identifierFieldNames ) ) { throw new \ Exception ( sprintf ( 'No primary key found for entity %s' , $ entity ) ) ; } $ countableColumn = reset ( $ identifierFieldNames ) ; /** @var EntityRepository $repository */ $ totalSize = $ repository -> createQueryBuilder ( 'size' ) -> select ( sprintf ( 'count(size.%s)' , $ countableColumn ) ) -> getQuery ( ) -> getSingleScalarResult ( ) ; } return $ totalSize - $ startOffset ; }
Get the total number of entities in a repository

@param string $entity
@param int    $startOffset

@return int

@throws \Exception if no primary key was found for the given entity
Get the total number of entities in a repository