X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2FWallabag%2FCoreBundle%2FRepository%2FEntryRepository.php;h=57bf8024c150ae08537b6f7678d4b8c8160a3724;hb=cfb28c9da0ff648d34ae0602eaec55a8362504dd;hp=5538ae82b40081101d2482271a7b0b290039bfbf;hpb=109d67dbb16478f927c3d6a46ab61ea9994aafae;p=github%2Fwallabag%2Fwallabag.git diff --git a/src/Wallabag/CoreBundle/Repository/EntryRepository.php b/src/Wallabag/CoreBundle/Repository/EntryRepository.php index 5538ae82..57bf8024 100644 --- a/src/Wallabag/CoreBundle/Repository/EntryRepository.php +++ b/src/Wallabag/CoreBundle/Repository/EntryRepository.php @@ -24,6 +24,20 @@ class EntryRepository extends EntityRepository ; } + /** + * Retrieves all entries for a user. + * + * @param int $userId + * + * @return QueryBuilder + */ + public function getBuilderForAllByUser($userId) + { + return $this + ->getBuilderByUser($userId) + ; + } + /** * Retrieves unread entries for a user. * @@ -120,4 +134,49 @@ class EntryRepository extends EntityRepository return $qb->getQuery()->getResult(); } + + /** + * Find distinct language for a given user. + * Used to build the filter language list. + * + * @param int $userId User id + * + * @return array + */ + public function findDistinctLanguageByUser($userId) + { + $results = $this->createQueryBuilder('e') + ->select('e.language') + ->where('e.user = :userId')->setParameter('userId', $userId) + ->andWhere('e.language IS NOT NULL') + ->groupBy('e.language') + ->orderBy('e.language', ' ASC') + ->getQuery() + ->getResult(); + + $languages = array(); + foreach ($results as $result) { + $languages[$result['language']] = $result['language']; + } + + return $languages; + } + + /** + * Used only in test case to get the right entry associated to the right user. + * + * @param string $username + * + * @return Entry + */ + public function findOneByUsernameAndNotArchived($username) + { + return $this->createQueryBuilder('e') + ->leftJoin('e.user', 'u') + ->where('u.username = :username')->setParameter('username', $username) + ->andWhere('e.isArchived = false') + ->setMaxResults(1) + ->getQuery() + ->getSingleResult(); + } }