|
10 | 10 |
|
11 | 11 | use DateTimeInterface; |
12 | 12 | use OCA\Libresign\AppInfo\Application; |
13 | | -use OCA\Libresign\Db\FileElement; |
14 | 13 | use OCA\Libresign\Db\FileMapper; |
15 | 14 | use OCA\Libresign\Db\IdentifyMethod; |
16 | 15 | use OCA\Libresign\Db\SignRequestMapper; |
| 16 | +use OCA\Libresign\ResponseDefinitions; |
| 17 | +use OCA\Libresign\Service\FileElementService; |
17 | 18 | use OCA\Libresign\Service\IdentifyMethodService; |
18 | 19 | use OCP\IAppConfig; |
19 | 20 | use OCP\IL10N; |
20 | 21 | use OCP\IURLGenerator; |
21 | 22 | use OCP\IUser; |
22 | 23 |
|
23 | 24 | /** |
24 | | - * Service for formatting file list responses with visible elements. |
| 25 | + * @psalm-import-type LibresignVisibleElement from ResponseDefinitions |
25 | 26 | */ |
26 | 27 | class FileListService { |
27 | 28 | public function __construct( |
28 | 29 | private SignRequestMapper $signRequestMapper, |
29 | 30 | private IdentifyMethodService $identifyMethodService, |
| 31 | + private FileElementService $fileElementService, |
30 | 32 | private FileMapper $fileMapper, |
31 | 33 | private IURLGenerator $urlGenerator, |
32 | 34 | private IAppConfig $appConfig, |
@@ -117,7 +119,10 @@ private function associateAllAndFormat(IUser $user, array $files, array $signers |
117 | 119 | }, false), |
118 | 120 | 'visibleElements' |
119 | 121 | => $visibleElements[$signer->getId()] |
120 | | - ? $this->formatVisibleElements($visibleElements[$signer->getId()]) |
| 122 | + ? $this->fileElementService->formatVisibleElements( |
| 123 | + $visibleElements[$signer->getId()], |
| 124 | + $file['metadata'], |
| 125 | + ) |
121 | 126 | : [], |
122 | 127 | 'identifyMethods' => array_map(fn (IdentifyMethod $identifyMethod): array => [ |
123 | 128 | 'method' => $identifyMethod->getIdentifierKey(), |
@@ -186,46 +191,4 @@ private function associateAllAndFormat(IUser $user, array $files, array $signers |
186 | 191 | } |
187 | 192 | return $files; |
188 | 193 | } |
189 | | - |
190 | | - /** |
191 | | - * Format visible elements for file list response. |
192 | | - * |
193 | | - * @param FileElement[] $visibleElements Array of FileElement objects |
194 | | - * @param array $metadata File metadata containing page dimensions |
195 | | - * @param string $uuid File UUID to include in response |
196 | | - * @return array Formatted visible elements |
197 | | - */ |
198 | | - public function formatVisibleElements(array $visibleElements): array { |
199 | | - return array_map(function ($visibleElement) { |
200 | | - $page = $visibleElement['page']; |
201 | | - $urx = (int)$visibleElement['urx']; |
202 | | - $ury = (int)$visibleElement['ury']; |
203 | | - $llx = (int)$visibleElement['llx']; |
204 | | - $lly = (int)$visibleElement['lly']; |
205 | | - |
206 | | - $dimension = $visibleElement['metadata']['d'][$page - 1]; |
207 | | - $height = abs($ury - $lly); |
208 | | - $width = $urx - $llx; |
209 | | - $top = (int)$dimension['h'] - $ury; |
210 | | - $left = $llx; |
211 | | - |
212 | | - return [ |
213 | | - 'elementId' => $visibleElement['id'], |
214 | | - 'signRequestId' => $visibleElement['sign_request_id'], |
215 | | - 'type' => $visibleElement['type'], |
216 | | - 'fileId' => $visibleElement['file_id'], |
217 | | - 'coordinates' => [ |
218 | | - 'page' => $page, |
219 | | - 'urx' => $urx, |
220 | | - 'ury' => $ury, |
221 | | - 'llx' => $llx, |
222 | | - 'lly' => $lly, |
223 | | - 'left' => $left, |
224 | | - 'top' => $top, |
225 | | - 'width' => $width, |
226 | | - 'height' => $height, |
227 | | - ], |
228 | | - ]; |
229 | | - }, $visibleElements); |
230 | | - } |
231 | 194 | } |
0 commit comments