|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Skobkin\Bundle\PointToolsBundle\Repository\Telegram; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\ORM\EntityRepository; |
|
6
|
|
|
|
|
7
|
|
|
class AccountRepository extends EntityRepository |
|
8
|
|
|
{ |
|
9
|
|
|
/** |
|
10
|
|
|
* @todo remove if not used |
|
11
|
|
|
* |
|
12
|
|
|
* @param array $criteria |
|
13
|
|
|
* @param array|null $orderBy |
|
14
|
|
|
* @param int|null $limit |
|
15
|
|
|
* @param int|null $offset |
|
16
|
|
|
* |
|
17
|
|
|
* @return array |
|
18
|
|
|
*/ |
|
19
|
|
|
public function findLinkedAccountsBy(array $criteria, array $orderBy = null, int $limit = null, int $offset = null): array |
|
20
|
|
|
{ |
|
21
|
|
|
$qb = $this->createQueryBuilder('a'); |
|
22
|
|
|
|
|
23
|
|
|
$i = 0; |
|
24
|
|
|
foreach ($criteria as $property => $value) { |
|
25
|
|
|
$qb |
|
26
|
|
|
->andWhere('a.'.$property.' = :criteria_'.$i) |
|
27
|
|
|
->setParameter('criteria_'.$i, $value) |
|
28
|
|
|
; |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
if (null !== $orderBy) { |
|
32
|
|
|
foreach ($orderBy as $property => $order) { |
|
33
|
|
|
$qb->addOrderBy($property, $order); |
|
34
|
|
|
} |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
if (null !== $limit) { |
|
38
|
|
|
$qb->setMaxResults($limit); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
if (null !== $offset) { |
|
42
|
|
|
$qb->setFirstResult($offset); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
return $qb->getQuery()->getResult(); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Returns total number of accounts |
|
50
|
|
|
* |
|
51
|
|
|
* @return int |
|
52
|
|
|
*/ |
|
53
|
|
|
public function getAccountsCount(): int |
|
54
|
|
|
{ |
|
55
|
|
|
return $this->createQueryBuilder('a') |
|
56
|
|
|
->select('COUNT(a)') |
|
57
|
|
|
->getQuery()->getSingleScalarResult() |
|
58
|
|
|
; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* Returns number of accounts with linked Point.im profile |
|
63
|
|
|
* |
|
64
|
|
|
* @return int |
|
65
|
|
|
*/ |
|
66
|
|
|
public function getLinkedAccountsCount(): int |
|
67
|
|
|
{ |
|
68
|
|
|
return $this->createQueryBuilder('a') |
|
69
|
|
|
->select('COUNT(a)') |
|
70
|
|
|
->where('a.user IS NOT NULL') |
|
71
|
|
|
->getQuery()->getSingleScalarResult() |
|
72
|
|
|
; |
|
73
|
|
|
} |
|
74
|
|
|
} |