]> git.immae.eu Git - github/wallabag/wallabag.git/blob - src/Wallabag/UserBundle/Repository/UserRepository.php
Better random function
[github/wallabag/wallabag.git] / src / Wallabag / UserBundle / Repository / UserRepository.php
1 <?php
2
3 namespace Wallabag\UserBundle\Repository;
4
5 use Doctrine\ORM\EntityRepository;
6 use Doctrine\ORM\QueryBuilder;
7 use Wallabag\UserBundle\Entity\User;
8
9 class UserRepository extends EntityRepository
10 {
11 /**
12 * Find a user by its username and rss roken.
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 }
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 }
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)')
53 ->andWhere('u.enabled = true')
54 ->getQuery()
55 ->getSingleScalarResult();
56 }
57
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
71 /**
72 * Retrieves users filtered with a search term.
73 *
74 * @param string $term
75 *
76 * @return QueryBuilder
77 */
78 public function getQueryBuilderForSearch($term)
79 {
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 . '%');
82 }
83 }