Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
47 / 47 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
PluginDomainDao | |
100.00% |
47 / 47 |
|
100.00% |
2 / 2 |
2 | |
100.00% |
1 / 1 |
selectCacheItems | |
100.00% |
35 / 35 |
|
100.00% |
1 / 1 |
1 | |||
selectCacheCategories | |
100.00% |
12 / 12 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | declare(strict_types=1); |
4 | |
5 | namespace PeServer\App\Models\Dao\Domain; |
6 | |
7 | use PeServer\App\Models\Cache\PluginCache; |
8 | use PeServer\App\Models\Cache\PluginCacheCategory; |
9 | use PeServer\App\Models\Cache\PluginCacheItem; |
10 | use PeServer\App\Models\Domain\PluginUrlKey; |
11 | use PeServer\Core\Collection\Collections; |
12 | use PeServer\Core\Database\DaoBase; |
13 | use PeServer\Core\Database\DaoTrait; |
14 | use PeServer\Core\Database\IDatabaseContext; |
15 | |
16 | class PluginDomainDao extends DaoBase |
17 | { |
18 | use DaoTrait; |
19 | |
20 | #region function |
21 | |
22 | /** |
23 | * Undocumented function |
24 | * |
25 | * @return PluginCacheItem[] |
26 | */ |
27 | public function selectCacheItems(): array |
28 | { |
29 | $result = $this->context->query( |
30 | <<<SQL |
31 | |
32 | select |
33 | plugins.plugin_id, |
34 | plugins.user_id, |
35 | plugins.plugin_name, |
36 | plugins.display_name, |
37 | plugins.state, |
38 | plugins.description, |
39 | check_plugin_urls.url as check_plugin_url, |
40 | project_plugin_urls.url as project_plugin_url, |
41 | lp_plugin_urls.url as lp_plugin_url |
42 | from |
43 | plugins |
44 | left join |
45 | plugin_urls as check_plugin_urls |
46 | on |
47 | ( |
48 | check_plugin_urls.plugin_id = plugins.plugin_id |
49 | and |
50 | check_plugin_urls.key = :url_check |
51 | ) |
52 | left join |
53 | plugin_urls as project_plugin_urls |
54 | on |
55 | ( |
56 | project_plugin_urls.plugin_id = plugins.plugin_id |
57 | and |
58 | project_plugin_urls.key = :url_project |
59 | ) |
60 | left join |
61 | plugin_urls as lp_plugin_urls |
62 | on |
63 | ( |
64 | lp_plugin_urls.plugin_id = plugins.plugin_id |
65 | and |
66 | lp_plugin_urls.key = :url_lp |
67 | ) |
68 | order by |
69 | plugins.plugin_id |
70 | |
71 | SQL, |
72 | [ |
73 | 'url_check' => PluginUrlKey::CHECK, |
74 | 'url_project' => PluginUrlKey::PROJECT, |
75 | 'url_lp' => PluginUrlKey::LANDING, |
76 | ] |
77 | ); |
78 | |
79 | return array_map(function ($i) { |
80 | $categoryIds = $this->context->query( |
81 | <<<SQL |
82 | |
83 | select |
84 | plugin_categories.plugin_category_id |
85 | from |
86 | plugin_category_mappings |
87 | inner join |
88 | plugin_categories |
89 | on |
90 | ( |
91 | plugin_categories.plugin_category_id = plugin_category_mappings.plugin_category_id |
92 | ) |
93 | where |
94 | plugin_category_mappings.plugin_id = :plugin_id |
95 | |
96 | SQL, |
97 | [ |
98 | 'plugin_id' => $i['plugin_id'] |
99 | ] |
100 | ); |
101 | |
102 | |
103 | $cache = new PluginCacheItem( |
104 | $i['plugin_id'], |
105 | $i['user_id'], |
106 | $i['plugin_name'], |
107 | $i['display_name'], |
108 | $i['state'], |
109 | $i['description'], |
110 | [ |
111 | PluginUrlKey::CHECK => $i['check_plugin_url'], |
112 | PluginUrlKey::PROJECT => $i['project_plugin_url'], |
113 | PluginUrlKey::LANDING => $i['lp_plugin_url'], |
114 | ], |
115 | //@phpstan-ignore-next-line [TIME] |
116 | Collections::from($categoryIds->rows) |
117 | ->selectMany(fn($i) => $i) |
118 | ->toArray() |
119 | ); |
120 | |
121 | return $cache; |
122 | }, $result->rows); |
123 | } |
124 | |
125 | /** |
126 | * Undocumented function |
127 | * |
128 | * @return PluginCacheCategory[] |
129 | */ |
130 | public function selectCacheCategories(): array |
131 | { |
132 | $result = $this->context->query( |
133 | <<<SQL |
134 | |
135 | select |
136 | plugin_categories.plugin_category_id, |
137 | plugin_categories.display_name, |
138 | plugin_categories.description |
139 | from |
140 | plugin_categories |
141 | order by |
142 | plugin_categories.plugin_category_id |
143 | |
144 | SQL |
145 | ); |
146 | |
147 | return array_map(function ($i) { |
148 | $cache = new PluginCacheCategory( |
149 | $i['plugin_category_id'], |
150 | $i['display_name'], |
151 | $i['description'] |
152 | ); |
153 | |
154 | return $cache; |
155 | }, $result->rows); |
156 | } |
157 | |
158 | #endregion |
159 | } |