3 namespace Wallabag\UserBundle\Repository
;
5 use Doctrine\ORM\EntityRepository
;
6 use Doctrine\ORM\QueryBuilder
;
7 use Wallabag\UserBundle\Entity\User
;
9 class UserRepository
extends EntityRepository
12 * Find a user by its username and rss roken.
14 * @param string $username
15 * @param string $rssToken
19 public function findOneByUsernameAndRsstoken($username, $rssToken)
21 return $this->createQueryBuilder('u')
22 ->leftJoin('u.config', 'c')
23 ->where('c.rssToken = :rss_token')->setParameter('rss_token', $rssToken)
24 ->andWhere('u.username = :username')->setParameter('username', $username)
26 ->getOneOrNullResult();
30 * Find a user by its username.
32 * @param string $username
36 public function findOneByUserName($username)
38 return $this->createQueryBuilder('u')
39 ->andWhere('u.username = :username')->setParameter('username', $username)
45 * Count how many users are enabled.
49 public function getSumEnabledUsers()
51 return $this->createQueryBuilder('u')
53 ->andWhere('u.enabled = true')
55 ->getSingleScalarResult();
59 * Count how many users are existing.
63 public function getSumUsers()
65 return $this->createQueryBuilder('u')
68 ->getSingleScalarResult();
72 * Retrieves users filtered with a search term.
76 * @return QueryBuilder
78 public function getQueryBuilderForSearch($term)
80 return $this->createQueryBuilder('u')
81 ->andWhere('lower(u.username) LIKE lower(:term) OR lower(u.email) LIKE lower(:term) OR lower(u.name) LIKE lower(:term)')->setParameter('term', '%' . $term . '%');