]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - src/Wallabag/UserBundle/Repository/UserRepository.php
Add a real configuration for CS-Fixer
[github/wallabag/wallabag.git] / src / Wallabag / UserBundle / Repository / UserRepository.php
index c020f3ca9478a6418ec1e4bc6732610a5999fe7b..b1d753d2f42e97d2b1e016f45a87cc5ee546ec61 100644 (file)
@@ -23,4 +23,46 @@ class UserRepository extends EntityRepository
             ->getQuery()
             ->getOneOrNullResult();
     }
+
+    /**
+     * Find a user by its username.
+     *
+     * @param string $username
+     *
+     * @return User
+     */
+    public function findOneByUserName($username)
+    {
+        return $this->createQueryBuilder('u')
+            ->andWhere('u.username = :username')->setParameter('username', $username)
+            ->getQuery()
+            ->getSingleResult();
+    }
+
+    /**
+     * Count how many users are enabled.
+     *
+     * @return int
+     */
+    public function getSumEnabledUsers()
+    {
+        return $this->createQueryBuilder('u')
+            ->select('count(u)')
+            ->andWhere('u.enabled = true')
+            ->getQuery()
+            ->getSingleScalarResult();
+    }
+
+    /**
+     * Retrieves users filtered with a search term.
+     *
+     * @param string $term
+     *
+     * @return QueryBuilder
+     */
+    public function getQueryBuilderForSearch($term)
+    {
+        return $this->createQueryBuilder('u')
+            ->andWhere('lower(u.username) LIKE lower(:term) OR lower(u.email) LIKE lower(:term) OR lower(u.name) LIKE lower(:term)')->setParameter('term', '%' . $term . '%');
+    }
 }