Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 36 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
PluginUrlsEntityDao | |
0.00% |
0 / 36 |
|
0.00% |
0 / 4 |
30 | |
0.00% |
0 / 1 |
selectUrls | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
6 | |||
insertUrl | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
2 | |||
updatePluginUrl | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
2 | |||
deleteByPluginId | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | declare(strict_types=1); |
4 | |
5 | namespace PeServer\App\Models\Dao\Entities; |
6 | |
7 | use PeServer\Core\Database\DaoBase; |
8 | use PeServer\Core\Database\DaoTrait; |
9 | use PeServer\Core\Database\IDatabaseContext; |
10 | |
11 | class PluginUrlsEntityDao extends DaoBase |
12 | { |
13 | use DaoTrait; |
14 | |
15 | #region function |
16 | |
17 | /** |
18 | * Undocumented function |
19 | * |
20 | * @param string $pluginId |
21 | * @return array<string,string> |
22 | */ |
23 | public function selectUrls(string $pluginId): array |
24 | { |
25 | $results = $this->context->query( |
26 | <<<SQL |
27 | |
28 | select |
29 | plugin_urls.key, |
30 | plugin_urls.url |
31 | from |
32 | plugin_urls |
33 | where |
34 | plugin_urls.plugin_id = :plugin_id |
35 | |
36 | SQL, |
37 | [ |
38 | 'plugin_id' => $pluginId, |
39 | ] |
40 | ); |
41 | |
42 | /** @var array<string,string> */ |
43 | $map = []; |
44 | foreach ($results->rows as $result) { |
45 | $map[$result['key']] = $result['url']; |
46 | } |
47 | |
48 | /** @var array<string,string> */ |
49 | return $map; |
50 | } |
51 | |
52 | public function insertUrl(string $pluginId, string $key, string $url): void |
53 | { |
54 | $this->context->insertSingle( |
55 | <<<SQL |
56 | |
57 | insert into |
58 | plugin_urls |
59 | ( |
60 | plugin_id, |
61 | key, |
62 | url |
63 | ) |
64 | values |
65 | ( |
66 | :plugin_id, |
67 | :key, |
68 | :url |
69 | ) |
70 | |
71 | SQL, |
72 | [ |
73 | 'plugin_id' => $pluginId, |
74 | 'key' => $key, |
75 | 'url' => $url, |
76 | ] |
77 | ); |
78 | } |
79 | |
80 | public function updatePluginUrl(string $pluginId, string $key, string $url): bool |
81 | { |
82 | return $this->context->updateByKeyOrNothing( |
83 | <<<SQL |
84 | |
85 | update |
86 | plugin_urls |
87 | set |
88 | url = :url |
89 | where |
90 | plugin_id = :plugin_id |
91 | and |
92 | key = :key |
93 | |
94 | SQL, |
95 | [ |
96 | 'plugin_id' => $pluginId, |
97 | 'key' => $key, |
98 | 'url' => $url, |
99 | ] |
100 | ); |
101 | } |
102 | |
103 | public function deleteByPluginId(string $pluginId): int |
104 | { |
105 | return $this->context->delete( |
106 | <<<SQL |
107 | |
108 | delete |
109 | from |
110 | plugin_urls |
111 | where |
112 | plugin_urls.plugin_id = :plugin_id |
113 | |
114 | SQL, |
115 | [ |
116 | 'plugin_id' => $pluginId, |
117 | ] |
118 | ); |
119 | } |
120 | |
121 | #endregion |
122 | } |