1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Repository; |
4
|
|
|
|
5
|
|
|
use App\Entity\User; |
6
|
|
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; |
7
|
|
|
use Doctrine\ORM\NonUniqueResultException; |
8
|
|
|
use Symfony\Bridge\Doctrine\RegistryInterface; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* @method User|null find($id, $lockMode = null, $lockVersion = null) |
12
|
|
|
* @method User|null findOneBy(array $criteria, array $orderBy = null) |
13
|
|
|
* @method User[] findAll() |
14
|
|
|
* @method User[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) |
15
|
|
|
*/ |
16
|
|
|
class UserRepository extends ServiceEntityRepository |
17
|
|
|
{ |
18
|
|
|
public function __construct(RegistryInterface $registry) |
19
|
|
|
{ |
20
|
|
|
parent::__construct($registry, User::class); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
// /** |
24
|
|
|
// * @return User[] Returns an array of User objects |
25
|
|
|
// */ |
26
|
|
|
/* |
27
|
|
|
public function findByExampleField($value) |
28
|
|
|
{ |
29
|
|
|
return $this->createQueryBuilder('u') |
30
|
|
|
->andWhere('u.exampleField = :val') |
31
|
|
|
->setParameter('val', $value) |
32
|
|
|
->orderBy('u.id', 'ASC') |
33
|
|
|
->setMaxResults(10) |
34
|
|
|
->getQuery() |
35
|
|
|
->getResult() |
36
|
|
|
; |
37
|
|
|
} |
38
|
|
|
*/ |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Get the unique user from it's hash |
42
|
|
|
* @param $hash |
43
|
|
|
* @return User|null |
44
|
|
|
* @throws NonUniqueResultException |
45
|
|
|
*/ |
46
|
|
|
public function findUserByHash($hash): ?User |
47
|
|
|
{ |
48
|
|
|
return $this->createQueryBuilder('u') |
49
|
|
|
->andWhere('u.verifiedHash = :hash') |
50
|
|
|
->setParameter('hash', $hash) |
51
|
|
|
->getQuery() |
52
|
|
|
->getOneOrNullResult(); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @param string $userMailName |
57
|
|
|
* @return User|null |
58
|
|
|
* @throws NonUniqueResultException |
59
|
|
|
*/ |
60
|
|
|
public function findUserByMailOrUsername(string $userMailName): ?User |
61
|
|
|
{ |
62
|
|
|
return $this->createQueryBuilder('u') |
63
|
|
|
->andWhere('u.email = :userMailName OR u.userName = :userMailName') |
64
|
|
|
->setParameter('userMailName', $userMailName) |
65
|
|
|
->getQuery() |
66
|
|
|
->getOneOrNullResult(); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
|
70
|
|
|
} |
71
|
|
|
|