2015-03-28 13:27:45 +00:00
< ? php
2024-02-19 00:30:12 +00:00
namespace Wallabag\Repository ;
2015-03-28 13:27:45 +00:00
2022-08-27 21:01:09 +00:00
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository ;
2017-07-29 20:51:50 +00:00
use Doctrine\ORM\QueryBuilder ;
2022-08-27 21:01:09 +00:00
use Doctrine\Persistence\ManagerRegistry ;
2024-02-19 00:30:12 +00:00
use Wallabag\Entity\User ;
2015-03-28 13:27:45 +00:00
2022-11-23 14:51:33 +00:00
/**
* @ method User | null findOneById ( int $id )
*/
2022-08-27 21:01:09 +00:00
class UserRepository extends ServiceEntityRepository
2015-03-28 13:27:45 +00:00
{
2022-08-27 21:01:09 +00:00
public function __construct ( ManagerRegistry $registry )
{
parent :: __construct ( $registry , User :: class );
}
2015-03-28 13:27:45 +00:00
/**
2017-06-13 16:48:10 +00:00
* Find a user by its username and Feed token .
2015-03-28 13:27:45 +00:00
*
* @ param string $username
2017-06-13 16:48:10 +00:00
* @ param string $feedToken
2015-03-28 13:27:45 +00:00
*
2019-04-25 12:12:56 +00:00
* @ return User | null
2015-03-28 13:27:45 +00:00
*/
2017-06-13 16:48:10 +00:00
public function findOneByUsernameAndFeedtoken ( $username , $feedToken )
2015-03-28 13:27:45 +00:00
{
return $this -> createQueryBuilder ( 'u' )
-> leftJoin ( 'u.config' , 'c' )
2017-06-13 16:48:10 +00:00
-> where ( 'c.feedToken = :feed_token' ) -> setParameter ( 'feed_token' , $feedToken )
2015-03-28 13:27:45 +00:00
-> 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
2017-07-31 21:20:41 +00:00
/**
* Count how many users are existing .
*
* @ return int
*/
public function getSumUsers ()
{
return $this -> createQueryBuilder ( 'u' )
-> select ( 'count(u)' )
-> getQuery ()
-> getSingleScalarResult ();
}
2017-04-27 13:58:32 +00:00
/**
* Retrieves users filtered with a search term .
*
* @ param string $term
*
* @ return QueryBuilder
*/
2017-04-27 14:23:54 +00:00
public function getQueryBuilderForSearch ( $term )
2017-04-27 13:58:32 +00:00
{
return $this -> createQueryBuilder ( 'u' )
2017-07-01 07:52:38 +00:00
-> andWhere ( 'lower(u.username) LIKE lower(:term) OR lower(u.email) LIKE lower(:term) OR lower(u.name) LIKE lower(:term)' ) -> setParameter ( 'term' , '%' . $term . '%' );
2017-04-27 13:58:32 +00:00
}
2015-03-28 13:27:45 +00:00
}