2015-03-28 13:27:45 +00:00
< ? php
2015-10-02 12:51:41 +00:00
namespace Wallabag\UserBundle\Repository ;
2015-03-28 13:27:45 +00:00
use Doctrine\ORM\EntityRepository ;
class UserRepository extends EntityRepository
{
/**
2015-05-30 11:52:26 +00:00
* Find a user by its username and rss roken .
2015-03-28 13:27:45 +00:00
*
* @ param string $username
* @ param string $rssToken
*
* @ return User | null
*/
public function findOneByUsernameAndRsstoken ( $username , $rssToken )
{
return $this -> createQueryBuilder ( 'u' )
-> leftJoin ( 'u.config' , 'c' )
-> where ( 'c.rssToken = :rss_token' ) -> setParameter ( 'rss_token' , $rssToken )
-> andWhere ( 'u.username = :username' ) -> setParameter ( 'username' , $username )
-> getQuery ()
-> getOneOrNullResult ();
}
2015-10-24 13:11:06 +00:00
/**
* 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 ();
}
2016-09-08 12:07:36 +00:00
/**
* Count how many users are enabled .
*
* @ return int
*/
public function getSumEnabledUsers ()
{
return $this -> createQueryBuilder ( 'u' )
-> select ( 'count(u)' )
2016-11-21 14:12:11 +00:00
-> andWhere ( 'u.enabled = true' )
2016-09-08 12:07:36 +00:00
-> getQuery ()
-> getSingleScalarResult ();
}
2017-04-27 13:58:32 +00:00
/**
* Retrieves users filtered with a search term .
*
* @ param string $term
*
* @ return QueryBuilder
*/
public function getUsersForSearch ( $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 . '%' )
-> getQuery ()
-> getResult ();
}
2015-03-28 13:27:45 +00:00
}