|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Repository; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Import classes |
|
7
|
|
|
*/ |
|
8
|
|
|
use App\Entity\Entry; |
|
9
|
|
|
use Doctrine\ORM\EntityRepository; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Import functions |
|
13
|
|
|
*/ |
|
14
|
|
|
use function current; |
|
15
|
|
|
use function sprintf; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* EntryRepository |
|
19
|
|
|
*/ |
|
20
|
|
|
final class EntryRepository extends EntityRepository |
|
21
|
|
|
{ |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Gets the numbers of entries |
|
25
|
|
|
* |
|
26
|
|
|
* @return int |
|
27
|
|
|
*/ |
|
28
|
14 |
|
public function countAll() : int |
|
29
|
|
|
{ |
|
30
|
14 |
|
$dql = sprintf('select count(t.id) from %s t', Entry::class); |
|
31
|
|
|
|
|
32
|
14 |
|
$query = $this->getEntityManager() |
|
33
|
14 |
|
->createQuery($dql); |
|
34
|
|
|
|
|
35
|
14 |
|
return (int) $query->getSingleScalarResult(); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Gets all entries |
|
40
|
|
|
* |
|
41
|
|
|
* @return Entry[] |
|
42
|
|
|
*/ |
|
43
|
2 |
|
public function getAll() : array |
|
44
|
|
|
{ |
|
45
|
2 |
|
$dql = sprintf('select t from %s t', Entry::class); |
|
46
|
|
|
|
|
47
|
2 |
|
$query = $this->getEntityManager() |
|
48
|
2 |
|
->createQuery($dql); |
|
49
|
|
|
|
|
50
|
2 |
|
return $query->getResult(); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Finds entries by the given ID(s) |
|
55
|
|
|
* |
|
56
|
|
|
* @param int ...$ids |
|
57
|
|
|
* |
|
58
|
|
|
* @return Entry[] |
|
59
|
|
|
*/ |
|
60
|
1 |
|
public function findByIds(int ...$ids) : array |
|
61
|
|
|
{ |
|
62
|
1 |
|
$dql = sprintf('select t from %s t where t.id in (:ids)', Entry::class); |
|
63
|
|
|
|
|
64
|
1 |
|
$query = $this->getEntityManager() |
|
65
|
1 |
|
->createQuery($dql) |
|
66
|
1 |
|
->setParameter('ids', $ids); |
|
67
|
|
|
|
|
68
|
1 |
|
return $query->getResult(); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* Finds an entry by the given ID |
|
73
|
|
|
* |
|
74
|
|
|
* @param int $id |
|
75
|
|
|
* |
|
76
|
|
|
* @return null|Entry |
|
77
|
|
|
*/ |
|
78
|
6 |
|
public function findById(int $id) : ?Entry |
|
79
|
|
|
{ |
|
80
|
6 |
|
$dql = sprintf('select t from %s t where t.id = :id', Entry::class); |
|
81
|
|
|
|
|
82
|
6 |
|
$query = $this->getEntityManager() |
|
83
|
6 |
|
->createQuery($dql) |
|
84
|
6 |
|
->setParameter('id', $id) |
|
85
|
6 |
|
->setMaxResults(1); |
|
86
|
|
|
|
|
87
|
6 |
|
$result = $query->getResult(); |
|
88
|
|
|
|
|
89
|
6 |
|
if (empty($result)) { |
|
90
|
3 |
|
return null; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
3 |
|
return current($result); |
|
94
|
|
|
} |
|
95
|
|
|
} |
|
96
|
|
|
|