]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - src/Wallabag/CoreBundle/Repository/EntryRepository.php
Fix tests for all
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Repository / EntryRepository.php
index e764e8f707e6566e2fcdec8914ae286904a930f6..2286317c177097f53ff8cf389e1dd05a72dfc0a5 100644 (file)
@@ -134,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();
+    }
 }