|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of the login-cidadao project or it's bundles. |
|
4
|
|
|
* |
|
5
|
|
|
* (c) Guilherme Donato <guilhermednt on github> |
|
6
|
|
|
* |
|
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
8
|
|
|
* file that was distributed with this source code. |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace LoginCidadao\PhoneVerificationBundle\Entity; |
|
12
|
|
|
|
|
13
|
|
|
use Doctrine\ORM\EntityRepository; |
|
14
|
|
|
use Doctrine\ORM\NonUniqueResultException; |
|
15
|
|
|
use libphonenumber\PhoneNumber; |
|
16
|
|
|
use LoginCidadao\CoreBundle\Entity\Person; |
|
17
|
|
|
use Misd\PhoneNumberBundle\Doctrine\DBAL\Types\PhoneNumberType; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* PhoneVerificationRepository |
|
21
|
|
|
* |
|
22
|
|
|
* This class was generated by the Doctrine ORM. Add your own custom |
|
23
|
|
|
* repository methods below. |
|
24
|
|
|
* |
|
25
|
|
|
* @codeCoverageIgnore |
|
26
|
|
|
*/ |
|
27
|
|
|
class PhoneVerificationRepository extends EntityRepository |
|
28
|
|
|
{ |
|
29
|
|
|
public function countBadges() |
|
30
|
|
|
{ |
|
31
|
|
|
try { |
|
32
|
|
|
return $this->createQueryBuilder('ph') |
|
33
|
|
|
->select('COUNT(p)') |
|
34
|
|
|
->innerJoin(Person::class, 'p', 'WITH', 'ph.person = p') |
|
35
|
|
|
->andWhere('ph.verifiedAt IS NOT NULL') |
|
36
|
|
|
->getQuery()->getSingleScalarResult(); |
|
37
|
|
|
} catch (NonUniqueResultException $e) { |
|
38
|
|
|
throw new \RuntimeException('Could not count how many people has a verified phone number', 0, $e); |
|
39
|
|
|
} |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function countVerified(PhoneNumber $phoneNumber) |
|
43
|
|
|
{ |
|
44
|
|
|
try { |
|
45
|
|
|
return $this->createQueryBuilder('v') |
|
46
|
|
|
->select('COUNT(p)') |
|
47
|
|
|
->innerJoin(Person::class, 'p', 'WITH', 'v.person = p') |
|
48
|
|
|
->where('v.phone = :phone') |
|
49
|
|
|
->andWhere('v.phone = p.mobile') |
|
50
|
|
|
->andWhere('v.verifiedAt IS NOT NULL') |
|
51
|
|
|
->setParameter('phone', $phoneNumber, PhoneNumberType::NAME) |
|
52
|
|
|
->getQuery() |
|
53
|
|
|
->getSingleScalarResult(); |
|
54
|
|
|
} catch (NonUniqueResultException $e) { |
|
55
|
|
|
throw new \RuntimeException('Could not count how many people uses the same verified phone number', 0, $e); |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|