Wallabag\CoreBundle\Twig\WallabagExtension::countEntries PHP Method

countEntries() public method

Return number of entries depending of the type (unread, archive, starred or all).
public countEntries ( string $type ) : integer
$type string Type of entries to count
return integer
    public function countEntries($type)
    {
        $user = $this->tokenStorage->getToken() ? $this->tokenStorage->getToken()->getUser() : null;
        if (null === $user || !is_object($user)) {
            return 0;
        }
        switch ($type) {
            case 'starred':
                $qb = $this->entryRepository->getBuilderForStarredByUser($user->getId());
                break;
            case 'archive':
                $qb = $this->entryRepository->getBuilderForArchiveByUser($user->getId());
                break;
            case 'unread':
                $qb = $this->entryRepository->getBuilderForUnreadByUser($user->getId());
                break;
            case 'all':
                $qb = $this->entryRepository->getBuilderForAllByUser($user->getId());
                break;
            default:
                throw new \InvalidArgumentException(sprintf('Type "%s" is not implemented.', $type));
        }
        // THANKS to PostgreSQL we CAN'T make a DEAD SIMPLE count(e.id)
        // ERROR: column "e0_.id" must appear in the GROUP BY clause or be used in an aggregate function
        $query = $qb->select('e.id')->groupBy('e.id')->getQuery();
        $query->useQueryCache(true);
        $query->useResultCache(true);
        $query->setResultCacheLifetime($this->lifeTime);
        return count($query->getArrayResult());
    }