Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 30 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
RoleRepository | |
0.00% |
0 / 30 |
|
0.00% |
0 / 5 |
56 | |
0.00% |
0 / 1 |
getPredefinedRole | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
findRoleFuzzilyByUsername | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
findRoleFuzzilyByOldUsername | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
getRolesWithParent | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
6 | |||
getAllActive | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace Olz\Repository\Roles; |
4 | |
5 | use Doctrine\Common\Collections\Collection; |
6 | use Doctrine\Common\Collections\Criteria; |
7 | use Olz\Entity\Roles\Role; |
8 | use Olz\Repository\Common\OlzRepository; |
9 | |
10 | /** |
11 | * @extends OlzRepository<Role> |
12 | */ |
13 | class RoleRepository extends OlzRepository { |
14 | protected string $role_class = Role::class; |
15 | |
16 | public function getPredefinedRole(PredefinedRole $predefined_role): ?Role { |
17 | $role = $this->findOneBy(['username' => $predefined_role->value]); |
18 | if (!$role) { |
19 | $this->log()->warning("Predefined role does not exist: {$predefined_role->value}"); |
20 | } |
21 | return $role; |
22 | } |
23 | |
24 | public function findRoleFuzzilyByUsername(string $username): ?Role { |
25 | $dql = "SELECT r FROM {$this->role_class} r WHERE r.username LIKE ?1"; |
26 | $query = $this->getEntityManager()->createQuery($dql)->setParameter(1, $username); |
27 | return $query->getOneOrNullResult(); |
28 | } |
29 | |
30 | public function findRoleFuzzilyByOldUsername(string $old_username): ?Role { |
31 | $dql = "SELECT r FROM {$this->role_class} r WHERE r.old_username LIKE ?1"; |
32 | $query = $this->getEntityManager()->createQuery($dql)->setParameter(1, $old_username); |
33 | return $query->getOneOrNullResult(); |
34 | } |
35 | |
36 | /** @return array<Role> */ |
37 | public function getRolesWithParent(?int $roleId, int $limit = 100): array { |
38 | if ($roleId === null) { |
39 | $dql = " |
40 | SELECT r |
41 | FROM {$this->role_class} r |
42 | WHERE |
43 | r.parent_role IS NULL |
44 | AND r.index_within_parent IS NOT NULL |
45 | AND r.index_within_parent >= 0 |
46 | AND r.on_off = 1 |
47 | ORDER BY r.index_within_parent ASC"; |
48 | $query = $this->getEntityManager()->createQuery($dql); |
49 | } else { |
50 | $dql = " |
51 | SELECT r |
52 | FROM {$this->role_class} r |
53 | WHERE |
54 | r.parent_role = ?1 |
55 | AND r.index_within_parent IS NOT NULL |
56 | AND r.index_within_parent >= 0 |
57 | AND r.on_off = 1 |
58 | ORDER BY r.index_within_parent ASC"; |
59 | $query = $this->getEntityManager()->createQuery($dql)->setParameter(1, $roleId); |
60 | } |
61 | $query->setMaxResults($limit); |
62 | return $query->getResult(); |
63 | } |
64 | |
65 | /** @return Collection<int, Role>&iterable<Role> */ |
66 | public function getAllActive(): Collection { |
67 | // TODO: Remove guide != '' condition again, after all ressort |
68 | // descriptions have been updated. This is just temporary logic! |
69 | $criteria = Criteria::create() |
70 | ->where(Criteria::expr()->andX( |
71 | Criteria::expr()->gte('index_within_parent', 0), // Negative = hidden |
72 | Criteria::expr()->neq('guide', ''), |
73 | )) |
74 | ->setFirstResult(0) |
75 | ->setMaxResults(1000000) |
76 | ; |
77 | return $this->matching($criteria); |
78 | } |
79 | } |