wallabag/src/Wallabag/UserBundle/Repository/UserRepository.php

93 lines
2.4 KiB
PHP
Raw Normal View History

2015-03-28 13:27:45 +00:00
<?php
namespace Wallabag\UserBundle\Repository;
2015-03-28 13:27:45 +00:00
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
2017-07-29 20:51:50 +00:00
use Doctrine\ORM\QueryBuilder;
use Doctrine\Persistence\ManagerRegistry;
2017-07-29 20:51:50 +00:00
use Wallabag\UserBundle\Entity\User;
2015-03-28 13:27:45 +00:00
2022-11-23 14:51:33 +00:00
/**
* @method User|null findOneById(int $id)
*/
class UserRepository extends ServiceEntityRepository
2015-03-28 13:27:45 +00:00
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, User::class);
}
2015-03-28 13:27:45 +00:00
/**
* Find a user by its username and Feed token.
2015-03-28 13:27:45 +00:00
*
* @param string $username
* @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
*/
public function findOneByUsernameAndFeedtoken($username, $feedToken)
2015-03-28 13:27:45 +00:00
{
return $this->createQueryBuilder('u')
->leftJoin('u.config', 'c')
->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();
}
/**
* 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();
}
/**
* 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')
->getQuery()
->getSingleScalarResult();
}
/**
* Count how many users are existing.
*
* @return int
*/
public function getSumUsers()
{
return $this->createQueryBuilder('u')
->select('count(u)')
->getQuery()
->getSingleScalarResult();
}
/**
* Retrieves users filtered with a search term.
*
* @param string $term
*
* @return QueryBuilder
*/
public function getQueryBuilderForSearch($term)
{
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 . '%');
}
2015-03-28 13:27:45 +00:00
}