Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 42 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
SolvResultRepository | |
0.00% |
0 / 42 |
|
0.00% |
0 / 5 |
56 | |
0.00% |
0 / 1 |
getUnassignedSolvResults | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
getAllAssignedSolvResultPersonData | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
getExactPersonId | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
6 | |||
mergePerson | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
2 | |||
solvPersonHasResults | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | |
3 | namespace Olz\Repository; |
4 | |
5 | use Olz\Entity\SolvResult; |
6 | use Olz\Repository\Common\OlzRepository; |
7 | |
8 | /** |
9 | * @extends OlzRepository<SolvResult> |
10 | */ |
11 | class SolvResultRepository extends OlzRepository { |
12 | protected string $solv_result_class = SolvResult::class; |
13 | |
14 | /** @return array<SolvResult> */ |
15 | public function getUnassignedSolvResults(): array { |
16 | $dql = "SELECT sr FROM {$this->solv_result_class} sr WHERE sr.person = '0'"; |
17 | $query = $this->getEntityManager()->createQuery($dql); |
18 | return $query->getResult(); |
19 | } |
20 | |
21 | /** @return array<array{person: int, name: string, birth_year: string, domicile: string}> */ |
22 | public function getAllAssignedSolvResultPersonData(): array { |
23 | $dql = " |
24 | SELECT DISTINCT |
25 | sr.person, |
26 | sr.name, |
27 | sr.birth_year, |
28 | sr.domicile |
29 | FROM {$this->solv_result_class} sr |
30 | WHERE sr.person != '0' |
31 | "; |
32 | $query = $this->getEntityManager()->createQuery($dql); |
33 | return $query->getResult(); |
34 | } |
35 | |
36 | public function getExactPersonId(SolvResult $solv_result): int { |
37 | $db = $this->dbUtils()->getDb(); |
38 | |
39 | $sane_name = $db->real_escape_string($solv_result->getName()); |
40 | $sane_birth_year = $db->real_escape_string($solv_result->getBirthYear()); |
41 | $sane_domicile = $db->real_escape_string($solv_result->getDomicile()); |
42 | $dql = " |
43 | SELECT sr.person |
44 | FROM {$this->solv_result_class} sr |
45 | WHERE |
46 | sr.name = '{$sane_name}' |
47 | AND sr.birth_year = '{$sane_birth_year}' |
48 | AND sr.domicile = '{$sane_domicile}' |
49 | AND sr.person != '0' |
50 | "; |
51 | $query = $this->getEntityManager()->createQuery($dql); |
52 | $query->setMaxResults(1); |
53 | try { |
54 | $person_id = $query->getSingleScalarResult(); |
55 | return intval($person_id); |
56 | } catch (\Exception $e) { |
57 | return 0; |
58 | } |
59 | } |
60 | |
61 | public function mergePerson(int $old_person_id, int $new_person_id): mixed { |
62 | $sane_old_id = intval($old_person_id); |
63 | $sane_new_id = intval($new_person_id); |
64 | $dql = " |
65 | UPDATE {$this->solv_result_class} sr |
66 | SET sr.person = '{$sane_new_id}' |
67 | WHERE sr.person = '{$sane_old_id}' |
68 | "; |
69 | $query = $this->getEntityManager()->createQuery($dql); |
70 | return $query->execute(); |
71 | } |
72 | |
73 | public function solvPersonHasResults(int $id): bool { |
74 | $sane_id = intval($id); |
75 | $dql = " |
76 | SELECT COUNT(sr.id) |
77 | FROM {$this->solv_result_class} sr |
78 | WHERE sr.person = '{$sane_id}'"; |
79 | $query = $this->getEntityManager()->createQuery($dql); |
80 | try { |
81 | $count = $query->getSingleScalarResult(); |
82 | return intval($count) > 0; |
83 | } catch (\Exception $e) { |
84 | return false; |
85 | } |
86 | } |
87 | } |