]> git.immae.eu Git - github/wallabag/wallabag.git/blame - src/Wallabag/UserBundle/Repository/UserRepository.php
Merge remote-tracking branch 'origin/master' into 2.3
[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;
52b84c11
NH
6use Doctrine\ORM\QueryBuilder;
7use Wallabag\UserBundle\Entity\User;
0c83fd59
J
8
9class UserRepository extends EntityRepository
10{
11 /**
4346a860 12 * Find a user by its username and rss roken.
0c83fd59
J
13 *
14 * @param string $username
15 * @param string $rssToken
16 *
17 * @return User|null
18 */
19 public function findOneByUsernameAndRsstoken($username, $rssToken)
20 {
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)
25 ->getQuery()
26 ->getOneOrNullResult();
27 }
625acf33
KG
28
29 /**
30 * Find a user by its username.
31 *
32 * @param string $username
33 *
34 * @return User
35 */
36 public function findOneByUserName($username)
37 {
38 return $this->createQueryBuilder('u')
39 ->andWhere('u.username = :username')->setParameter('username', $username)
40 ->getQuery()
41 ->getSingleResult();
42 }
bb0c78f4
NL
43
44 /**
45 * Count how many users are enabled.
46 *
47 * @return int
48 */
49 public function getSumEnabledUsers()
50 {
51 return $this->createQueryBuilder('u')
52 ->select('count(u)')
5066c3e0 53 ->andWhere('u.enabled = true')
bb0c78f4
NL
54 ->getQuery()
55 ->getSingleScalarResult();
56 }
c37515f8 57
f7a4b441
NH
58 /**
59 * Count how many users are existing.
60 *
61 * @return int
62 */
63 public function getSumUsers()
64 {
65 return $this->createQueryBuilder('u')
66 ->select('count(u)')
67 ->getQuery()
68 ->getSingleScalarResult();
69 }
70
c37515f8
TC
71 /**
72 * Retrieves users filtered with a search term.
73 *
74 * @param string $term
75 *
76 * @return QueryBuilder
77 */
50cfd810 78 public function getQueryBuilderForSearch($term)
c37515f8
TC
79 {
80 return $this->createQueryBuilder('u')
f808b016 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 . '%');
c37515f8 82 }
0c83fd59 83}