]> git.immae.eu Git - github/wallabag/wallabag.git/blame - src/Wallabag/UserBundle/Repository/UserRepository.php
Add a real configuration for CS-Fixer
[github/wallabag/wallabag.git] / src / Wallabag / UserBundle / Repository / UserRepository.php
CommitLineData
0c83fd59
J
1<?php
2
1210dae1 3namespace Wallabag\UserBundle\Repository;
0c83fd59
J
4
5use Doctrine\ORM\EntityRepository;
6
7class UserRepository extends EntityRepository
8{
9 /**
4346a860 10 * Find a user by its username and rss roken.
0c83fd59
J
11 *
12 * @param string $username
13 * @param string $rssToken
14 *
15 * @return User|null
16 */
17 public function findOneByUsernameAndRsstoken($username, $rssToken)
18 {
19 return $this->createQueryBuilder('u')
20 ->leftJoin('u.config', 'c')
21 ->where('c.rssToken = :rss_token')->setParameter('rss_token', $rssToken)
22 ->andWhere('u.username = :username')->setParameter('username', $username)
23 ->getQuery()
24 ->getOneOrNullResult();
25 }
625acf33
KG
26
27 /**
28 * Find a user by its username.
29 *
30 * @param string $username
31 *
32 * @return User
33 */
34 public function findOneByUserName($username)
35 {
36 return $this->createQueryBuilder('u')
37 ->andWhere('u.username = :username')->setParameter('username', $username)
38 ->getQuery()
39 ->getSingleResult();
40 }
bb0c78f4
NL
41
42 /**
43 * Count how many users are enabled.
44 *
45 * @return int
46 */
47 public function getSumEnabledUsers()
48 {
49 return $this->createQueryBuilder('u')
50 ->select('count(u)')
5066c3e0 51 ->andWhere('u.enabled = true')
bb0c78f4
NL
52 ->getQuery()
53 ->getSingleScalarResult();
54 }
c37515f8
TC
55
56 /**
57 * Retrieves users filtered with a search term.
58 *
59 * @param string $term
60 *
61 * @return QueryBuilder
62 */
50cfd810 63 public function getQueryBuilderForSearch($term)
c37515f8
TC
64 {
65 return $this->createQueryBuilder('u')
f808b016 66 ->andWhere('lower(u.username) LIKE lower(:term) OR lower(u.email) LIKE lower(:term) OR lower(u.name) LIKE lower(:term)')->setParameter('term', '%' . $term . '%');
c37515f8 67 }
0c83fd59 68}